filename
stringlengths
5
42
content
stringlengths
15
319k
Lean.lean
/- Copyright (c) 2025 Jon Eugster. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jon Eugster, Arthur Paulino -/ import Lean.Data.Json import Lean.Util.Path /-! # Helper Functions This file contains helper functions that could potentially be upstreamed to Lean or replaced by an appropriate function from Lean. Some functions here are duplicates from the folder `Mathlib/Lean/`. -/ /-- Format as hex digit string. Used by `Cache` to format hashes. -/ def Nat.toHexDigits (n : Nat) : Nat → (res : String := "") → String | 0, s => s | len + 1, s => let b := UInt8.ofNat (n >>> (len * 8)) Nat.toHexDigits n len <| s.push (Nat.digitChar (b >>> 4).toNat) |>.push (Nat.digitChar (b &&& 15).toNat) /-- Format hash as hex digit with extension `.ltar` -/ def UInt64.asLTar (n : UInt64) : String := s!"{Nat.toHexDigits n.toNat 8}.ltar" -- copied from Mathlib /-- Create a `Name` from a list of components. -/ def Lean.Name.fromComponents : List Name → Name := go .anonymous where go : Name → List Name → Name | n, [] => n | n, s :: rest => go (s.updatePrefix n) rest namespace Lean.SearchPath open System in /-- Find the source directory for a module. This could be `.` (or in fact also something uncleaned like `./././.`) if the module is part of the current package, or something like `.lake/packages/mathlib` if the module is from a dependency. This is an exact copy of the first part of `Lean.SearchPath.findWithExt` which, in turn, is used by `Lean.findLean sp mod`. In the future, `findWithExt` could be refactored to expose this base path. -/ def findWithExtBase (sp : SearchPath) (ext : String) (mod : Name) : IO (Option FilePath) := do let pkg := mod.getRoot.toString (escape := false) sp.findM? fun p => (p / pkg).isDir <||> ((p / pkg).addExtension ext).pathExists end Lean.SearchPath namespace System.FilePath /-- Removes a parent path from the beginning of a path -/ def withoutParent (path parent : FilePath) : FilePath := mkFilePath <| go path.components parent.components where go : List String → List String → List String | path@(x :: xs), y :: ys => if x == y then go xs ys else path | [], _ => [] | path, [] => path end System.FilePath
Defs.lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Algebra.CharZero.Defs import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Int.Defs import Mathlib.Data.Int.Cast.Basic import Mathlib.Algebra.Ring.GrindInstances /-! # The integers are a ring This file contains the commutative ring instance on `ℤ`. See note [foundational algebra order theory]. -/ assert_not_exists DenselyOrdered Set.Subsingleton namespace Int instance instCommRing : CommRing ℤ where __ := instAddCommGroup __ := instCommSemigroup zero_mul := Int.zero_mul mul_zero := Int.mul_zero left_distrib := Int.mul_add right_distrib := Int.add_mul mul_one := Int.mul_one one_mul := Int.one_mul npow n x := x ^ n npow_zero _ := rfl npow_succ _ _ := rfl natCast := (·) natCast_zero := rfl natCast_succ _ := rfl intCast := (·) intCast_ofNat _ := rfl intCast_negSucc _ := rfl instance instCancelCommMonoidWithZero : CancelCommMonoidWithZero ℤ where mul_left_cancel_of_ne_zero ha _ _ := (mul_eq_mul_left_iff ha).1 instance instCharZero : CharZero ℤ where cast_injective _ _ := ofNat.inj instance instMulDivCancelClass : MulDivCancelClass ℤ where mul_div_cancel _ _ := mul_ediv_cancel _ @[simp, norm_cast] lemma cast_mul {α : Type*} [NonAssocRing α] : ∀ m n, ((m * n : ℤ) : α) = m * n := fun m => by obtain ⟨m, rfl | rfl⟩ := Int.eq_nat_or_neg m · induction m with | zero => simp | succ m ih => simp_all [add_mul] · induction m with | zero => simp | succ m ih => simp_all [add_mul] /-- Note this holds in marginally more generality than `Int.cast_mul` -/ lemma cast_mul_eq_zsmul_cast {α : Type*} [AddGroupWithOne α] : ∀ m n : ℤ, ↑(m * n) = m • (n : α) := fun m ↦ Int.induction_on m (by simp) (fun _ ih ↦ by simp [add_mul, add_zsmul, ih]) fun _ ih ↦ by simp only [sub_mul, one_mul, cast_sub, ih, sub_zsmul, one_zsmul, ← sub_eq_add_neg, forall_const] @[simp, norm_cast] lemma cast_pow {R : Type*} [Ring R] (n : ℤ) (m : ℕ) : ↑(n ^ m) = (n ^ m : R) := by induction m <;> simp [_root_.pow_succ, *] /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances like `Int.normedCommRing` being used to construct these instances non-computably. -/ set_option linter.style.commandStart false instance instCommSemiring : CommSemiring ℤ := inferInstance instance instSemiring : Semiring ℤ := inferInstance instance instRing : Ring ℤ := inferInstance instance instDistrib : Distrib ℤ := inferInstance set_option linter.style.commandStart true end Int
Basic.lean
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Michael Stoll -/ import Mathlib.Analysis.PSeries import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.Data.Complex.FiniteDimensional /-! # L-series Given a sequence `f: ℕ → ℂ`, we define the corresponding L-series. ## Main Definitions * `LSeries.term f s n` is the `n`th term of the L-series of the sequence `f` at `s : ℂ`. We define it to be zero when `n = 0`. * `LSeries f` is the L-series with a given sequence `f` as its coefficients. This is not the analytic continuation (which does not necessarily exist), just the sum of the infinite series if it exists and zero otherwise. * `LSeriesSummable f s` indicates that the L-series of `f` converges at `s : ℂ`. * `LSeriesHasSum f s a` expresses that the L-series of `f` converges (absolutely) at `s : ℂ` to `a : ℂ`. ## Main Results * `LSeriesSummable_of_isBigO_rpow`: the `LSeries` of a sequence `f` such that `f = O(n^(x-1))` converges at `s` when `x < s.re`. * `LSeriesSummable.isBigO_rpow`: if the `LSeries` of `f` is summable at `s`, then `f = O(n^(re s))`. ## Notation We introduce `L` as notation for `LSeries` and `↗f` as notation for `fun n : ℕ ↦ (f n : ℂ)`, both scoped to `LSeries.notation`. The latter makes it convenient to use arithmetic functions or Dirichlet characters (or anything that coerces to a function `N → R`, where `ℕ` coerces to `N` and `R` coerces to `ℂ`) as arguments to `LSeries` etc. ## Reference For some background on the design decisions made when implementing L-series in Mathlib (and applications motivating the development), see the paper [Formalizing zeta and L-functions in Lean](https://arxiv.org/abs/2503.00959) by David Loeffler and Michael Stoll. ## Tags L-series -/ open Complex /-! ### The terms of an L-series We define the `n`th term evaluated at a complex number `s` of the L-series associated to a sequence `f : ℕ → ℂ`, `LSeries.term f s n`, and provide some basic API. We set `LSeries.term f s 0 = 0`, and for positive `n`, `LSeries.term f s n = f n / n ^ s`. -/ namespace LSeries /-- The `n`th term of the L-series of `f` evaluated at `s`. We set it to zero when `n = 0`. -/ noncomputable def term (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : ℂ := if n = 0 then 0 else f n / n ^ s lemma term_def (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : term f s n = if n = 0 then 0 else f n / n ^ s := rfl /-- An alternate spelling of `term_def` for the case `f 0 = 0`. -/ lemma term_def₀ {f : ℕ → ℂ} (hf : f 0 = 0) (s : ℂ) (n : ℕ) : LSeries.term f s n = f n * (n : ℂ) ^ (-s) := by rw [LSeries.term] split_ifs with h <;> simp [h, hf, cpow_neg, div_eq_inv_mul, mul_comm] @[simp] lemma term_zero (f : ℕ → ℂ) (s : ℂ) : term f s 0 = 0 := rfl -- We put `hn` first for convnience, so that we can write `rw [LSeries.term_of_ne_zero hn]` etc. @[simp] lemma term_of_ne_zero {n : ℕ} (hn : n ≠ 0) (f : ℕ → ℂ) (s : ℂ) : term f s n = f n / n ^ s := if_neg hn /-- If `s ≠ 0`, then the `if .. then .. else` construction in `LSeries.term` isn't needed, since `0 ^ s = 0`. -/ lemma term_of_ne_zero' {s : ℂ} (hs : s ≠ 0) (f : ℕ → ℂ) (n : ℕ) : term f s n = f n / n ^ s := by rcases eq_or_ne n 0 with rfl | hn · rw [term_zero, Nat.cast_zero, zero_cpow hs, div_zero] · rw [term_of_ne_zero hn] lemma term_congr {f g : ℕ → ℂ} (h : ∀ {n}, n ≠ 0 → f n = g n) (s : ℂ) (n : ℕ) : term f s n = term g s n := by rcases eq_or_ne n 0 with hn | hn <;> simp [hn, h] lemma pow_mul_term_eq (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : (n + 1) ^ s * term f s (n + 1) = f (n + 1) := by simp [term, natCast_add_one_cpow_ne_zero n _, mul_div_assoc'] lemma norm_term_eq (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : ‖term f s n‖ = if n = 0 then 0 else ‖f n‖ / n ^ s.re := by rcases eq_or_ne n 0 with rfl | hn · simp · simp [hn, norm_natCast_cpow_of_pos <| Nat.pos_of_ne_zero hn] lemma norm_term_le {f g : ℕ → ℂ} (s : ℂ) {n : ℕ} (h : ‖f n‖ ≤ ‖g n‖) : ‖term f s n‖ ≤ ‖term g s n‖ := by simp only [norm_term_eq] split · rfl · gcongr lemma norm_term_le_of_re_le_re (f : ℕ → ℂ) {s s' : ℂ} (h : s.re ≤ s'.re) (n : ℕ) : ‖term f s' n‖ ≤ ‖term f s n‖ := by simp only [norm_term_eq] split · next => rfl · next hn => gcongr; exact Nat.one_le_cast.mpr <| Nat.one_le_iff_ne_zero.mpr hn section positivity open scoped ComplexOrder lemma term_nonneg {a : ℕ → ℂ} {n : ℕ} (h : 0 ≤ a n) (x : ℝ) : 0 ≤ term a x n := by rw [term_def] split_ifs with hn exacts [le_rfl, mul_nonneg h (inv_natCast_cpow_ofReal_pos hn x).le] lemma term_pos {a : ℕ → ℂ} {n : ℕ} (hn : n ≠ 0) (h : 0 < a n) (x : ℝ) : 0 < term a x n := by simpa only [term_of_ne_zero hn] using mul_pos h <| inv_natCast_cpow_ofReal_pos hn x end positivity end LSeries /-! ### Definition of the L-series and related statements We define `LSeries f s` of `f : ℕ → ℂ` as the sum over `LSeries.term f s`. We also provide predicates `LSeriesSummable f s` stating that `LSeries f s` is summable and `LSeriesHasSum f s a` stating that the L-series of `f` is summable at `s` and converges to `a : ℂ`. -/ open LSeries /-- The value of the L-series of the sequence `f` at the point `s` if it converges absolutely there, and `0` otherwise. -/ noncomputable def LSeries (f : ℕ → ℂ) (s : ℂ) : ℂ := ∑' n, term f s n -- TODO: change argument order in `LSeries_congr` to have `s` last. lemma LSeries_congr {f g : ℕ → ℂ} (s : ℂ) (h : ∀ {n}, n ≠ 0 → f n = g n) : LSeries f s = LSeries g s := tsum_congr <| term_congr h s /-- `LSeriesSummable f s` indicates that the L-series of `f` converges absolutely at `s`. -/ def LSeriesSummable (f : ℕ → ℂ) (s : ℂ) : Prop := Summable (term f s) lemma LSeriesSummable_congr {f g : ℕ → ℂ} (s : ℂ) (h : ∀ {n}, n ≠ 0 → f n = g n) : LSeriesSummable f s ↔ LSeriesSummable g s := summable_congr <| term_congr h s open Filter in /-- If `f` and `g` agree on large `n : ℕ` and the `LSeries` of `f` converges at `s`, then so does that of `g`. -/ lemma LSeriesSummable.congr' {f g : ℕ → ℂ} (s : ℂ) (h : f =ᶠ[atTop] g) (hf : LSeriesSummable f s) : LSeriesSummable g s := by rw [← Nat.cofinite_eq_atTop] at h refine (summable_norm_iff.mpr hf).of_norm_bounded_eventually ?_ have : term f s =ᶠ[cofinite] term g s := by rw [eventuallyEq_iff_exists_mem] at h ⊢ obtain ⟨S, hS, hS'⟩ := h refine ⟨S \ {0}, diff_mem hS <| (Set.finite_singleton 0).compl_mem_cofinite, fun n hn ↦ ?_⟩ rw [Set.mem_diff, Set.mem_singleton_iff] at hn simp [hn.2, hS' hn.1] exact this.symm.mono fun n hn ↦ by simp [hn] open Filter in /-- If `f` and `g` agree on large `n : ℕ`, then the `LSeries` of `f` converges at `s` if and only if that of `g` does. -/ lemma LSeriesSummable_congr' {f g : ℕ → ℂ} (s : ℂ) (h : f =ᶠ[atTop] g) : LSeriesSummable f s ↔ LSeriesSummable g s := ⟨fun H ↦ H.congr' s h, fun H ↦ H.congr' s h.symm⟩ theorem LSeries.eq_zero_of_not_LSeriesSummable (f : ℕ → ℂ) (s : ℂ) : ¬ LSeriesSummable f s → LSeries f s = 0 := tsum_eq_zero_of_not_summable @[simp] theorem LSeriesSummable_zero {s : ℂ} : LSeriesSummable 0 s := by simp [LSeriesSummable, funext (term_def 0 s), summable_zero] /-- This states that the L-series of the sequence `f` converges absolutely at `s` and that the value there is `a`. -/ def LSeriesHasSum (f : ℕ → ℂ) (s a : ℂ) : Prop := HasSum (term f s) a lemma LSeriesHasSum.LSeriesSummable {f : ℕ → ℂ} {s a : ℂ} (h : LSeriesHasSum f s a) : LSeriesSummable f s := h.summable lemma LSeriesHasSum.LSeries_eq {f : ℕ → ℂ} {s a : ℂ} (h : LSeriesHasSum f s a) : LSeries f s = a := h.tsum_eq lemma LSeriesSummable.LSeriesHasSum {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) : LSeriesHasSum f s (LSeries f s) := h.hasSum lemma LSeriesHasSum_iff {f : ℕ → ℂ} {s a : ℂ} : LSeriesHasSum f s a ↔ LSeriesSummable f s ∧ LSeries f s = a := ⟨fun H ↦ ⟨H.LSeriesSummable, H.LSeries_eq⟩, fun ⟨H₁, H₂⟩ ↦ H₂ ▸ H₁.LSeriesHasSum⟩ lemma LSeriesHasSum_congr {f g : ℕ → ℂ} (s a : ℂ) (h : ∀ {n}, n ≠ 0 → f n = g n) : LSeriesHasSum f s a ↔ LSeriesHasSum g s a := by simp [LSeriesHasSum_iff, LSeriesSummable_congr s h, LSeries_congr s h] lemma LSeriesSummable.of_re_le_re {f : ℕ → ℂ} {s s' : ℂ} (h : s.re ≤ s'.re) (hf : LSeriesSummable f s) : LSeriesSummable f s' := by rw [LSeriesSummable, ← summable_norm_iff] at hf ⊢ exact hf.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (norm_term_le_of_re_le_re f h) theorem LSeriesSummable_iff_of_re_eq_re {f : ℕ → ℂ} {s s' : ℂ} (h : s.re = s'.re) : LSeriesSummable f s ↔ LSeriesSummable f s' := ⟨fun H ↦ H.of_re_le_re h.le, fun H ↦ H.of_re_le_re h.symm.le⟩ /-- The indicator function of `{1} ⊆ ℕ` with values in `ℂ`. -/ def LSeries.delta (n : ℕ) : ℂ := if n = 1 then 1 else 0 /-! ### Notation -/ @[inherit_doc] scoped[LSeries.notation] notation "L" => LSeries /-- We introduce notation `↗f` for `f` interpreted as a function `ℕ → ℂ`. Let `R` be a ring with a coercion to `ℂ`. Then we can write `↗χ` when `χ : DirichletCharacter R` or `↗f` when `f : ArithmeticFunction R` or simply `f : N → R` with a coercion from `ℕ` to `N` as an argument to `LSeries`, `LSeriesHasSum`, `LSeriesSummable` etc. -/ scoped[LSeries.notation] notation:max "↗" f:max => fun n : ℕ ↦ (f n : ℂ) @[inherit_doc] scoped[LSeries.notation] notation "δ" => delta /-! ### LSeries of 0 and δ -/ @[simp] lemma LSeries_zero : LSeries 0 = 0 := by ext simp [LSeries, LSeries.term] section delta open scoped LSeries.notation namespace LSeries open Nat Complex lemma term_delta (s : ℂ) (n : ℕ) : term δ s n = if n = 1 then 1 else 0 := by rcases eq_or_ne n 0 with rfl | hn · simp · rcases eq_or_ne n 1 with hn' | hn' <;> simp [hn, hn', delta] lemma mul_delta_eq_smul_delta {f : ℕ → ℂ} : f * δ = f 1 • δ := by ext n by_cases hn : n = 1 <;> simp [hn, delta] lemma mul_delta {f : ℕ → ℂ} (h : f 1 = 1) : f * δ = δ := by rw [mul_delta_eq_smul_delta, h, one_smul] lemma delta_mul_eq_smul_delta {f : ℕ → ℂ} : δ * f = f 1 • δ := mul_comm δ f ▸ mul_delta_eq_smul_delta lemma delta_mul {f : ℕ → ℂ} (h : f 1 = 1) : δ * f = δ := mul_comm δ f ▸ mul_delta h end LSeries /-- The L-series of `δ` is the constant function `1`. -/ lemma LSeries_delta : LSeries δ = 1 := by ext simp [LSeries, LSeries.term_delta] end delta /-! ### Criteria for and consequences of summability of L-series We relate summability of L-series with bounds on the coefficients in terms of powers of `n`. -/ /-- If the `LSeries` of `f` is summable at `s`, then `f n` is bounded in absolute value by a constant times `n^(re s)`. -/ lemma LSeriesSummable.le_const_mul_rpow {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) : ∃ C, ∀ n ≠ 0, ‖f n‖ ≤ C * n ^ s.re := by replace h := h.norm by_contra! H obtain ⟨n, hn₀, hn⟩ := H (tsum fun n ↦ ‖term f s n‖) have := h.le_tsum n fun _ _ ↦ norm_nonneg _ rw [norm_term_eq, if_neg hn₀, div_le_iff₀ <| Real.rpow_pos_of_pos (Nat.cast_pos.mpr <| Nat.pos_of_ne_zero hn₀) _] at this exact (this.trans_lt hn).false.elim open Filter in /-- If the `LSeries` of `f` is summable at `s`, then `f = O(n^(re s))`. -/ lemma LSeriesSummable.isBigO_rpow {f : ℕ → ℂ} {s : ℂ} (h : LSeriesSummable f s) : f =O[atTop] fun n ↦ (n : ℝ) ^ s.re := by obtain ⟨C, hC⟩ := h.le_const_mul_rpow refine Asymptotics.IsBigO.of_bound C <| eventually_atTop.mpr ⟨1, fun n hn ↦ ?_⟩ convert hC n (Nat.pos_iff_ne_zero.mp hn) using 2 rw [Real.norm_eq_abs, Real.abs_rpow_of_nonneg n.cast_nonneg, abs_of_nonneg n.cast_nonneg] /-- If `f n` is bounded in absolute value by a constant times `n^(x-1)` and `re s > x`, then the `LSeries` of `f` is summable at `s`. -/ lemma LSeriesSummable_of_le_const_mul_rpow {f : ℕ → ℂ} {x : ℝ} {s : ℂ} (hs : x < s.re) (h : ∃ C, ∀ n ≠ 0, ‖f n‖ ≤ C * n ^ (x - 1)) : LSeriesSummable f s := by obtain ⟨C, hC⟩ := h have hC₀ : 0 ≤ C := (norm_nonneg <| f 1).trans <| by simpa using hC 1 one_ne_zero have hsum : Summable fun n : ℕ ↦ ‖(C : ℂ) / n ^ (s + (1 - x))‖ := by simp_rw [div_eq_mul_inv, norm_mul, ← cpow_neg] have hsx : -s.re + x - 1 < -1 := by linarith only [hs] refine Summable.mul_left _ <| Summable.of_norm_bounded_eventually_nat (g := fun n ↦ (n : ℝ) ^ (-s.re + x - 1)) ?_ ?_ · simpa · simp only [norm_norm, Filter.eventually_atTop] refine ⟨1, fun n hn ↦ le_of_eq ?_⟩ simp only [norm_natCast_cpow_of_pos hn, add_re, sub_re, neg_re, ofReal_re, one_re] ring_nf refine Summable.of_norm <| hsum.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ ?_) rcases n.eq_zero_or_pos with rfl | hn · simpa only [term_zero, norm_zero] using norm_nonneg _ have hn' : 0 < (n : ℝ) ^ s.re := Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ simp_rw [term_of_ne_zero hn.ne', norm_div, norm_natCast_cpow_of_pos hn, div_le_iff₀ hn', norm_real, Real.norm_of_nonneg hC₀, div_eq_mul_inv, mul_assoc, ← Real.rpow_neg <| Nat.cast_nonneg _, ← Real.rpow_add <| Nat.cast_pos.mpr hn] simpa using hC n <| Nat.pos_iff_ne_zero.mp hn open Filter Finset Real Nat in /-- If `f = O(n^(x-1))` and `re s > x`, then the `LSeries` of `f` is summable at `s`. -/ lemma LSeriesSummable_of_isBigO_rpow {f : ℕ → ℂ} {x : ℝ} {s : ℂ} (hs : x < s.re) (h : f =O[atTop] fun n ↦ (n : ℝ) ^ (x - 1)) : LSeriesSummable f s := by obtain ⟨C, hC⟩ := Asymptotics.isBigO_iff.mp h obtain ⟨m, hm⟩ := eventually_atTop.mp hC let C' := max C (max' (insert 0 (image (fun n : ℕ ↦ ‖f n‖ / (n : ℝ) ^ (x - 1)) (range m))) (insert_nonempty 0 _)) have hC'₀ : 0 ≤ C' := (le_max' _ _ (mem_insert.mpr (Or.inl rfl))).trans <| le_max_right .. have hCC' : C ≤ C' := le_max_left .. refine LSeriesSummable_of_le_const_mul_rpow hs ⟨C', fun n hn₀ ↦ ?_⟩ rcases le_or_gt m n with hn | hn · refine (hm n hn).trans ?_ have hn₀ : (0 : ℝ) ≤ n := cast_nonneg _ gcongr rw [Real.norm_eq_abs, abs_rpow_of_nonneg hn₀, abs_of_nonneg hn₀] · have hn' : 0 < n := Nat.pos_of_ne_zero hn₀ refine (div_le_iff₀ <| rpow_pos_of_pos (cast_pos.mpr hn') _).mp ?_ refine (le_max' _ _ <| mem_insert_of_mem ?_).trans <| le_max_right .. exact mem_image.mpr ⟨n, mem_range.mpr hn, rfl⟩ /-- If `f` is bounded, then its `LSeries` is summable at `s` when `re s > 1`. -/ theorem LSeriesSummable_of_bounded_of_one_lt_re {f : ℕ → ℂ} {m : ℝ} (h : ∀ n ≠ 0, ‖f n‖ ≤ m) {s : ℂ} (hs : 1 < s.re) : LSeriesSummable f s := LSeriesSummable_of_le_const_mul_rpow hs ⟨m, fun n hn ↦ by simp [h n hn]⟩ /-- If `f` is bounded, then its `LSeries` is summable at `s : ℝ` when `s > 1`. -/ theorem LSeriesSummable_of_bounded_of_one_lt_real {f : ℕ → ℂ} {m : ℝ} (h : ∀ n ≠ 0, ‖f n‖ ≤ m) {s : ℝ} (hs : 1 < s) : LSeriesSummable f s := LSeriesSummable_of_bounded_of_one_lt_re h <| by simp [hs]
preorder.v
(* (c) Copyright 2006-2019 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice seq. From mathcomp Require Import path fintype tuple bigop finset div prime finfun. From mathcomp Require Import finset. (******************************************************************************) (* Types equipped with order relations *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file and order.v define types equipped with order relations. *) (* *) (* * How to use preorders in MathComp? *) (* Use the module PreorderTheory implementing the theories (located in the *) (* module Order):$ *) (* To access the definitions, notations, and the theory from, say, *) (* "Order.Xyz", insert "Import Order.Xyz." at the top of your scripts. You can*) (* also "Import Order.Def." to enjoy shorter notations (e.g., min instead of *) (* Order.min, nondecreasing instead of Order.nondecreasing, etc.). *) (* *) (* In order to reason about abstract orders, notations are accessible by *) (* opening the scope "order_scope" bound to the delimiting key "O"; however, *) (* when dealing with another notation scope providing order notations for *) (* a concrete instance (e.g., "ring_scope"), it is not recommended to open *) (* "order_scope" at the same time. *) (* *) (* * Control of inference (parsing) and printing *) (* One characteristic of ordered types is that one carrier type may have *) (* several orders. For example, natural numbers can be totally or partially *) (* ordered by the less than or equal relation, the divisibility relation, and *) (* their dual relations. Therefore, we need a way to control inference of *) (* ordered type instances and printing of generic relations and operations on *) (* ordered types. As a rule of thumb, we use the carrier type or its "alias" *) (* (named copy) to control inference (using canonical structures), and use a *) (* "display" to control the printing of notations. *) (* *) (* Each generic interface and operation for ordered types has, as its first *) (* argument, a "display" of type Order.disp_t. For example, the less than or *) (* equal relation has type: *) (* Order.le : forall {d : Order.disp_t} {T : porderType d}, rel T, *) (* where porderType d is the structure of partially ordered types with *) (* display d. (@Order.le dvd_display _ m n) is printed as m %| n because *) (* ordered type instances associated to the display dvd_display is intended *) (* to represent natural numbers partially ordered by the divisibility *) (* relation. *) (* *) (* We stress that order structure inference can be triggered only from the *) (* carrier type (or its alias), but not the display. For example, writing *) (* m %| n for m and n of type nat does not trigger an inference of the *) (* divisibility relation on natural numbers, which is associated to an alias *) (* natdvd for nat; such an inference should be triggered through the use of *) (* the corresponding alias, i.e., (m : natdvd) %| n. In other words, displays *) (* are merely used to inform the user and the notation mechanism of what the *) (* inference did; they are not additional input for the inference. *) (* *) (* See below for various aliases and their associated displays. *) (* *) (* NB: algebra/ssrnum.v provides the display ring_display to change the *) (* scope of the usual notations to ring_scope. *) (* *) (* Instantiating d with Disp tt tt or an unknown display will lead to a *) (* default display for notations. *) (* *) (* Alternative notation displays can be defined by : *) (* 1. declaring a new opaque definition of type unit. Using the idiom *) (* `Fact my_display : Order.disp_t. Proof. exact: Disp tt tt. Qed.` *) (* 2. using this symbol to tag canonical porderType structures using *) (* `HB.instance Definition _ := isPOrder.Build my_display my_type ...`, *) (* 3. declaring notations for the main operations of this library, by *) (* setting the first argument of the definition to the display, e.g. *) (* `Notation my_syndef_le x y := @Order.le my_display _ x y.` or *) (* `Notation "x <=< y" := @Order.lt my_display _ x y (at level ...).` *) (* Non overloaded notations will default to the default display. *) (* We suggest the user to refer to the example of natdvd below as a guideline *) (* example to add their own displays. *) (* *) (* * Interfaces *) (* We provide the following interfaces for types equipped with an order: *) (* *) (* preorderType d == the type of preordered types *) (* The HB class is called Preorder. *) (* bPreorderType d == preorderType with a bottom element (\bot) *) (* The HB class is called BPreorder. *) (* tPreorderType d == preorderType with a top element (\top) *) (* The HB class is called TPreorder. *) (* tbPreorderType d == preorderType with both a top and a bottom *) (* The HB class is called TBPreorder. *) (* finPreorderType d == the type of partially preordered finite types *) (* The HB class is called FinPreorder. *) (* finBPreorderType d == finPreorderType with a bottom element *) (* The HB class is called FinBPreorder. *) (* finTPreorderType d == finPreorderType with a top element *) (* The HB class is called FinTPreorder. *) (* finTBPreorderType d == finPreorderType with both a top and a bottom *) (* The HB class is called FinTBPreorder. *) (* *) (* and their joins with subType: *) (* *) (* subPreorder d T P d' == join of preorderType d' and subType *) (* (P : pred T) such that val is monotonic *) (* The HB class is called SubPreorder. *) (* *) (* Morphisms between the above structures: *) (* *) (* OrderMorphism.type d T d' T' == nondecreasing function between the two *) (* preorder *) (* := {omorphism T -> T'} *) (* *) (* TODO: Check this section * Useful lemmas: *) (* On orderType, leP, ltP, and ltgtP are the three main lemmas for case *) (* analysis. *) (* On porderType, one may use comparableP, comparable_leP, comparable_ltP, *) (* and comparable_ltgtP, which are the four main lemmas for case analysis. *) (* *) (* * Order relations and operations: *) (* In general, an overloaded relation or operation on ordered types takes the *) (* following arguments: *) (* 1. a display d of type Order.disp_t, *) (* 2. an instance T of the minimal structure it operates on, and *) (* 3. operands. *) (* Here is the exhaustive list of all such operations together with their *) (* default notation (defined in order_scope unless specified otherwise). *) (* *) (* For T of type preorderType d, x and y of type T, and C of type bool: *) (* x <= y := @Order.le d T x y *) (* <-> x is less than or equal to y. *) (* x < y := @Order.lt d T x y *) (* <-> x is less than y, i.e., (y != x) && (x <= y). *) (* x >= y := y <= x *) (* <-> x is greater than or equal to y. *) (* x > y := y < x *) (* <-> x is greater than y. *) (* x >=< y := @Order.comparable d T x y (:= (x <= y) || (y <= x)) *) (* <-> x and y are comparable. *) (* x >< y := ~~ x >=< y *) (* <-> x and y are incomparable. *) (* x <= y ?= iff C := @Order.leif d T x y C (:= (x <= y) * ((x == y) = C)) *) (* <-> x is less than y, or equal iff C is true. *) (* x < y ?<= if C := @Order.lteif d T x y C (:= if C then x <= y else x < y)*) (* <-> x is smaller than y, and strictly if C is false. *) (* Order.min x y := if x < y then x else y *) (* Order.max x y := if x < y then y else x *) (* f \min g == the function x |-> Order.min (f x) (g x); *) (* f \min g simplifies on application. *) (* f \max g == the function x |-> Order.max (f x) (g x); *) (* f \max g simplifies on application. *) (* nondecreasing f <-> the function f : T -> T' is nondecreasing, *) (* where T and T' are porderType *) (* := {homo f : x y / x <= y} *) (* Unary (partially applied) versions of order notations: *) (* >= y := @Order.le d T y *) (* == a predicate characterizing elements greater than or *) (* equal to y *) (* > y := @Order.lt d T y *) (* <= y := @Order.ge d T y *) (* < y := @Order.gt d T y *) (* >=< y := [pred x | @Order.comparable d T x y] *) (* >< y := [pred x | ~~ @Order.comparable d T x y] *) (* 0-ary versions of order notations (in function_scope): *) (* <=%O := @Order.le d T *) (* <%O := @Order.lt d T *) (* >=%O := @Order.ge d T *) (* >%O := @Order.gt d T *) (* >=<%O := @Order.comparable d T *) (* <?=%O := @Order.leif d T *) (* <?<=%O := @Order.lteif d T *) (* -> These conventions are compatible with Haskell's, *) (* where ((< y) x) = (x < y) = ((<) x y), *) (* except that we write <%O instead of (<). *) (* *) (* For T of type bPreorderType d: *) (* \bot := @Order.bottom d T *) (* == the bottom element of type T *) (* For T of type tPreorderType d: *) (* \top := @Order.top d T *) (* == the top element of type T *) (* *) (* For preorderType we provide the following operations: *) (* [arg min_(i < i0 | P) M] == a value i : T minimizing M : R, subject to *) (* the condition P (i may appear in P and M), and *) (* provided P holds for i0. *) (* [arg max_(i > i0 | P) M] == a value i maximizing M subject to P and *) (* provided P holds for i0. *) (* [arg min_(i < i0 in A) M] == an i \in A minimizing M if i0 \in A. *) (* [arg max_(i > i0 in A) M] == an i \in A maximizing M if i0 \in A. *) (* [arg min_(i < i0) M] == an i : T minimizing M, given i0 : T. *) (* [arg max_(i > i0) M] == an i : T maximizing M, given i0 : T. *) (* with head symbols Order.arg_min and Order.arg_max *) (* The user may use extremumP or extremum_inP to eliminate them. *) (* *) (* -> patterns for contextual rewriting: *) (* leLHS := (X in (X <= _)%O)%pattern *) (* leRHS := (X in (_ <= X)%O)%pattern *) (* ltLHS := (X in (X < _)%O)%pattern *) (* ltRHS := (X in (_ < X)%O)%pattern *) (* *) (* We provide aliases for various types and their displays: *) (* natdvd := nat (associated with display dvd_display) *) (* == an alias for nat which is canonically ordered using *) (* divisibility predicate dvdn *) (* Notation %|, %<|, gcd, lcm are used instead of *) (* <=, <, meet and join. *) (* T^d := dual T, *) (* where dual is a new definition for (fun T => T) *) (* (associated with dual_display d where d is a display) *) (* == an alias for T, such that if T is canonically *) (* ordered, then T^d is canonically ordered with the *) (* dual order, and displayed with an extra ^d in the *) (* notation, i.e., <=^d, <^d, >=<^d, ><^d, `&`^d, `|`^d *) (* are used and displayed instead of *) (* <=, <, >=<, ><, `&`, `|` *) (* T *prod[d] T' := T * T' *) (* == an alias for the cartesian product such that, *) (* if T and T' are canonically ordered, *) (* then T *prod[d] T' is canonically ordered in product *) (* order, i.e., *) (* (x1, x2) <= (y1, y2) = (x1 <= y1) && (x2 <= y2), *) (* and displayed in display d *) (* T *p T' := T *prod[prod_display d d'] T' *) (* where d and d' are the displays of T and T', *) (* respectively, and prod_display adds an extra ^p to *) (* all notations *) (* T *lexi[d] T' := T * T' *) (* == an alias for the cartesian product such that, *) (* if T and T' are canonically ordered, *) (* then T *lexi[d] T' is canonically ordered in *) (* lexicographic order, *) (* i.e., (x1, x2) <= (y1, y2) = *) (* (x1 <= y1) && ((x1 >= y1) ==> (x2 <= y2)) *) (* and (x1, x2) < (y1, y2) = *) (* (x1 <= y1) && ((x1 >= y1) ==> (x2 < y2)) *) (* and displayed in display d *) (* T *l T' := T *lexi[lexi_display d d'] T' *) (* where d and d' are the displays of T and T', *) (* respectively, and lexi_display adds an extra ^l to *) (* all notations *) (* seqprod_with d T := seq T *) (* == an alias for seq, such that if T is canonically *) (* ordered, then seqprod_with d T is canonically ordered *) (* in product order, i.e., *) (* [:: x1, .., xn] <= [y1, .., yn] = *) (* (x1 <= y1) && ... && (xn <= yn) *) (* and displayed in display d *) (* n.-tupleprod[d] T == same with n.tuple T *) (* seqprod T := seqprod_with (seqprod_display d) T *) (* where d is the display of T, and seqprod_display adds *) (* an extra ^sp to all notations *) (* n.-tupleprod T := n.-tuple[seqprod_display d] T *) (* where d is the display of T *) (* seqlexi_with d T := seq T *) (* == an alias for seq, such that if T is canonically *) (* ordered, then seqprod_with d T is canonically ordered *) (* in lexicographic order, i.e., *) (* [:: x1, .., xn] <= [y1, .., yn] = *) (* (x1 <= x2) && ((x1 >= y1) ==> ((x2 <= y2) && ...)) *) (* and displayed in display d *) (* n.-tuplelexi[d] T == same with n.tuple T *) (* seqlexi T := lexiprod_with (seqlexi_display d) T *) (* where d is the display of T, and seqlexi_display adds *) (* an extra ^sl to all notations *) (* n.-tuplelexi T := n.-tuple[seqlexi_display d] T *) (* where d is the display of T *) (* {subset[d] T} := {set T} *) (* == an alias for set which is canonically ordered by the *) (* subset order and displayed in display d *) (* {subset T} := {subset[subset_display] T} *) (* *) (* The following notations are provided to build substructures: *) (* [SubChoice_isSubPreorder of U by <: with disp] == *) (* [SubChoice_isSubPreorder of U by <:] == preorderType mixin for a subType *) (* whose base type is a preorderType *) (* *) (* We provide expected instances of ordered types for bool, nat (for leq and *) (* and dvdn), 'I_n, 'I_n.+1 (with a top and bottom), nat for dvdn, *) (* T *prod[disp] T', T *lexi[disp] T', {t : T & T' x} (with lexicographic *) (* ordering), seqprod_with d T (using product order), seqlexi_with d T *) (* (with lexicographic ordering), n.-tupleprod[disp] (using product order), *) (* n.-tuplelexi[d] T (with lexicographic ordering), on {subset[disp] T} *) (* (using subset order) and all possible finite type instances. *) (* (Use `HB.about type` to discover the instances on type.) *) (* *) (* In order to get a canonical order on prod, seq, tuple or set, one may *) (* import modules DefaultProdOrder or DefaultProdLexiOrder, *) (* DefaultSeqProdOrder or DefaultSeqLexiOrder, *) (* DefaultTupleProdOrder or DefaultTupleLexiOrder, *) (* and DefaultSetSubsetOrder. *) (* *) (* We also provide specialized versions of some theorems from path.v. *) (* *) (* We provide Order.enum_val, Order.enum_rank, and Order.enum_rank_in, which *) (* are monotonic variations of enum_val, enum_rank, and enum_rank_in *) (* whenever the type is porderType, and their monotonicity is provided if *) (* this order is total. The theory is in the module Order (Order.enum_valK, *) (* Order.enum_rank_inK, etc) but Order.Enum can be imported to shorten these. *) (* *) (* We provide an opaque monotonous bijection tagnat.sig / tagnat.rank between *) (* the finite types {i : 'I_n & 'I_(p_ i)} and 'I_(\sum_i p_ i): *) (* tagnat.sig : 'I_(\sum_i p_ i) -> {i : 'I_n & 'I_(p_ i)} *) (* tagnat.rank : {i : 'I_n & 'I_(p_ i)} -> 'I_(\sum_i p_ i) *) (* tagnat.sig1 : 'I_(\sum_i p_ i) -> 'I_n *) (* tagnat.sig2 : forall p : 'I_(\sum_i p_ i), 'I_(p_ (tagnat.sig1 p)) *) (* tagnat.Rank : forall i, 'I_(p_ i) -> 'I_(\sum_i p_ i) *) (* *) (* Acknowledgments: This file is based on prior work by D. Dreyer, G. *) (* Gonthier, A. Nanevski, P-Y Strub, B. Ziliani *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope order_scope. Delimit Scope order_scope with O. Local Open Scope order_scope. Reserved Notation "<= y" (at level 35). Reserved Notation ">= y" (at level 35). Reserved Notation "< y" (at level 35). Reserved Notation "> y" (at level 35). Reserved Notation "<= y :> T" (at level 35, y at next level). Reserved Notation ">= y :> T" (at level 35, y at next level). Reserved Notation "< y :> T" (at level 35, y at next level). Reserved Notation "> y :> T" (at level 35, y at next level). Reserved Notation "x >=< y" (at level 70, no associativity). Reserved Notation ">=< y" (at level 35). Reserved Notation ">=< y :> T" (at level 35, y at next level). Reserved Notation "x >< y" (at level 70, no associativity). Reserved Notation ">< x" (at level 35). Reserved Notation ">< y :> T" (at level 35, y at next level). Reserved Notation "f \min g" (at level 50, left associativity). Reserved Notation "f \max g" (at level 50, left associativity). Reserved Notation "x < y ?<= 'if' c" (c at next level, format "x '[hv' < y '/' ?<= 'if' c ']'"). Reserved Notation "x < y ?<= 'if' c :> T" ( format "x '[hv' < y '/' ?<= 'if' c :> T ']'"). (* Reserved notations for bottom/top elements *) Reserved Notation "\bot". Reserved Notation "\top". (* Reserved notations for dual order *) Reserved Notation "x <=^d y" (at level 70, y at next level). Reserved Notation "x >=^d y" (at level 70, y at next level). Reserved Notation "x <^d y" (at level 70, y at next level). Reserved Notation "x >^d y" (at level 70, y at next level). Reserved Notation "x <=^d y :> T" (at level 70, y at next level). Reserved Notation "x >=^d y :> T" (at level 70, y at next level). Reserved Notation "x <^d y :> T" (at level 70, y at next level). Reserved Notation "x >^d y :> T" (at level 70, y at next level). Reserved Notation "<=^d y" (at level 35). Reserved Notation ">=^d y" (at level 35). Reserved Notation "<^d y" (at level 35). Reserved Notation ">^d y" (at level 35). Reserved Notation "<=^d y :> T" (at level 35, y at next level). Reserved Notation ">=^d y :> T" (at level 35, y at next level). Reserved Notation "<^d y :> T" (at level 35, y at next level). Reserved Notation ">^d y :> T" (at level 35, y at next level). Reserved Notation "x >=<^d y" (at level 70, no associativity). Reserved Notation ">=<^d y" (at level 35). Reserved Notation ">=<^d y :> T" (at level 35, y at next level). Reserved Notation "x ><^d y" (at level 70, no associativity). Reserved Notation "><^d x" (at level 35). Reserved Notation "><^d y :> T" (at level 35, y at next level). Reserved Notation "x <=^d y <=^d z" (at level 70, y, z at next level). Reserved Notation "x <^d y <=^d z" (at level 70, y, z at next level). Reserved Notation "x <=^d y <^d z" (at level 70, y, z at next level). Reserved Notation "x <^d y <^d z" (at level 70, y, z at next level). Reserved Notation "x <=^d y ?= 'iff' c" (at level 70, y, c at next level, format "x '[hv' <=^d y '/' ?= 'iff' c ']'"). Reserved Notation "x <=^d y ?= 'iff' c :> T" (at level 70, y, c at next level, format "x '[hv' <=^d y '/' ?= 'iff' c :> T ']'"). Reserved Notation "x <^d y ?<= 'if' c" (at level 70, y, c at next level, format "x '[hv' <^d y '/' ?<= 'if' c ']'"). Reserved Notation "x <^d y ?<= 'if' c :> T" (at level 70, y, c at next level, format "x '[hv' <^d y '/' ?<= 'if' c :> T ']'"). Reserved Notation "\bot^d". Reserved Notation "\top^d". (* Reserved notations for product ordering of prod *) Reserved Notation "x <=^p y" (at level 70, y at next level). Reserved Notation "x >=^p y" (at level 70, y at next level). Reserved Notation "x <^p y" (at level 70, y at next level). Reserved Notation "x >^p y" (at level 70, y at next level). Reserved Notation "x <=^p y :> T" (at level 70, y at next level). Reserved Notation "x >=^p y :> T" (at level 70, y at next level). Reserved Notation "x <^p y :> T" (at level 70, y at next level). Reserved Notation "x >^p y :> T" (at level 70, y at next level). Reserved Notation "<=^p y" (at level 35). Reserved Notation ">=^p y" (at level 35). Reserved Notation "<^p y" (at level 35). Reserved Notation ">^p y" (at level 35). Reserved Notation "<=^p y :> T" (at level 35, y at next level). Reserved Notation ">=^p y :> T" (at level 35, y at next level). Reserved Notation "<^p y :> T" (at level 35, y at next level). Reserved Notation ">^p y :> T" (at level 35, y at next level). Reserved Notation "x >=<^p y" (at level 70, no associativity). Reserved Notation ">=<^p x" (at level 35). Reserved Notation ">=<^p y :> T" (at level 35, y at next level). Reserved Notation "x ><^p y" (at level 70, no associativity). Reserved Notation "><^p x" (at level 35). Reserved Notation "><^p y :> T" (at level 35, y at next level). Reserved Notation "x <=^p y <=^p z" (at level 70, y, z at next level). Reserved Notation "x <^p y <=^p z" (at level 70, y, z at next level). Reserved Notation "x <=^p y <^p z" (at level 70, y, z at next level). Reserved Notation "x <^p y <^p z" (at level 70, y, z at next level). Reserved Notation "x <=^p y ?= 'iff' c" (at level 70, y, c at next level, format "x '[hv' <=^p y '/' ?= 'iff' c ']'"). Reserved Notation "x <=^p y ?= 'iff' c :> T" (at level 70, y, c at next level, format "x '[hv' <=^p y '/' ?= 'iff' c :> T ']'"). Reserved Notation "\bot^p". Reserved Notation "\top^p". (* Reserved notations for product ordering of seq *) Reserved Notation "x <=^sp y" (at level 70, y at next level). Reserved Notation "x >=^sp y" (at level 70, y at next level). Reserved Notation "x <^sp y" (at level 70, y at next level). Reserved Notation "x >^sp y" (at level 70, y at next level). Reserved Notation "x <=^sp y :> T" (at level 70, y at next level). Reserved Notation "x >=^sp y :> T" (at level 70, y at next level). Reserved Notation "x <^sp y :> T" (at level 70, y at next level). Reserved Notation "x >^sp y :> T" (at level 70, y at next level). Reserved Notation "<=^sp y" (at level 35). Reserved Notation ">=^sp y" (at level 35). Reserved Notation "<^sp y" (at level 35). Reserved Notation ">^sp y" (at level 35). Reserved Notation "<=^sp y :> T" (at level 35, y at next level). Reserved Notation ">=^sp y :> T" (at level 35, y at next level). Reserved Notation "<^sp y :> T" (at level 35, y at next level). Reserved Notation ">^sp y :> T" (at level 35, y at next level). Reserved Notation "x >=<^sp y" (at level 70, no associativity). Reserved Notation ">=<^sp x" (at level 35). Reserved Notation ">=<^sp y :> T" (at level 35, y at next level). Reserved Notation "x ><^sp y" (at level 70, no associativity). Reserved Notation "><^sp x" (at level 35). Reserved Notation "><^sp y :> T" (at level 35, y at next level). Reserved Notation "x <=^sp y <=^sp z" (at level 70, y, z at next level). Reserved Notation "x <^sp y <=^sp z" (at level 70, y, z at next level). Reserved Notation "x <=^sp y <^sp z" (at level 70, y, z at next level). Reserved Notation "x <^sp y <^sp z" (at level 70, y, z at next level). Reserved Notation "x <=^sp y ?= 'iff' c" (at level 70, y, c at next level, format "x '[hv' <=^sp y '/' ?= 'iff' c ']'"). Reserved Notation "x <=^sp y ?= 'iff' c :> T" (at level 70, y, c at next level, format "x '[hv' <=^sp y '/' ?= 'iff' c :> T ']'"). Reserved Notation "\bot^sp". Reserved Notation "\top^sp". (* Reserved notations for lexicographic ordering of prod *) Reserved Notation "x <=^l y" (at level 70, y at next level). Reserved Notation "x >=^l y" (at level 70, y at next level). Reserved Notation "x <^l y" (at level 70, y at next level). Reserved Notation "x >^l y" (at level 70, y at next level). Reserved Notation "x <=^l y :> T" (at level 70, y at next level). Reserved Notation "x >=^l y :> T" (at level 70, y at next level). Reserved Notation "x <^l y :> T" (at level 70, y at next level). Reserved Notation "x >^l y :> T" (at level 70, y at next level). Reserved Notation "<=^l y" (at level 35). Reserved Notation ">=^l y" (at level 35). Reserved Notation "<^l y" (at level 35). Reserved Notation ">^l y" (at level 35). Reserved Notation "<=^l y :> T" (at level 35, y at next level). Reserved Notation ">=^l y :> T" (at level 35, y at next level). Reserved Notation "<^l y :> T" (at level 35, y at next level). Reserved Notation ">^l y :> T" (at level 35, y at next level). Reserved Notation "x >=<^l y" (at level 70, no associativity). Reserved Notation ">=<^l x" (at level 35). Reserved Notation ">=<^l y :> T" (at level 35, y at next level). Reserved Notation "x ><^l y" (at level 70, no associativity). Reserved Notation "><^l x" (at level 35). Reserved Notation "><^l y :> T" (at level 35, y at next level). Reserved Notation "x <=^l y <=^l z" (at level 70, y, z at next level). Reserved Notation "x <^l y <=^l z" (at level 70, y, z at next level). Reserved Notation "x <=^l y <^l z" (at level 70, y, z at next level). Reserved Notation "x <^l y <^l z" (at level 70, y, z at next level). Reserved Notation "x <=^l y ?= 'iff' c" (at level 70, y, c at next level, format "x '[hv' <=^l y '/' ?= 'iff' c ']'"). Reserved Notation "x <=^l y ?= 'iff' c :> T" (at level 70, y, c at next level, format "x '[hv' <=^l y '/' ?= 'iff' c :> T ']'"). Reserved Notation "\bot^l". Reserved Notation "\top^l". (* Reserved notations for lexicographic ordering of seq *) Reserved Notation "x <=^sl y" (at level 70, y at next level). Reserved Notation "x >=^sl y" (at level 70, y at next level). Reserved Notation "x <^sl y" (at level 70, y at next level). Reserved Notation "x >^sl y" (at level 70, y at next level). Reserved Notation "x <=^sl y :> T" (at level 70, y at next level). Reserved Notation "x >=^sl y :> T" (at level 70, y at next level). Reserved Notation "x <^sl y :> T" (at level 70, y at next level). Reserved Notation "x >^sl y :> T" (at level 70, y at next level). Reserved Notation "<=^sl y" (at level 35). Reserved Notation ">=^sl y" (at level 35). Reserved Notation "<^sl y" (at level 35). Reserved Notation ">^sl y" (at level 35). Reserved Notation "<=^sl y :> T" (at level 35, y at next level). Reserved Notation ">=^sl y :> T" (at level 35, y at next level). Reserved Notation "<^sl y :> T" (at level 35, y at next level). Reserved Notation ">^sl y :> T" (at level 35, y at next level). Reserved Notation "x >=<^sl y" (at level 70, no associativity). Reserved Notation ">=<^sl x" (at level 35). Reserved Notation ">=<^sl y :> T" (at level 35, y at next level). Reserved Notation "x ><^sl y" (at level 70, no associativity). Reserved Notation "><^sl x" (at level 35). Reserved Notation "><^sl y :> T" (at level 35, y at next level). Reserved Notation "x <=^sl y <=^sl z" (at level 70, y, z at next level). Reserved Notation "x <^sl y <=^sl z" (at level 70, y, z at next level). Reserved Notation "x <=^sl y <^sl z" (at level 70, y, z at next level). Reserved Notation "x <^sl y <^sl z" (at level 70, y, z at next level). Reserved Notation "x <=^sl y ?= 'iff' c" (at level 70, y, c at next level, format "x '[hv' <=^sl y '/' ?= 'iff' c ']'"). Reserved Notation "x <=^sl y ?= 'iff' c :> T" (at level 70, y, c at next level, format "x '[hv' <=^sl y '/' ?= 'iff' c :> T ']'"). Reserved Notation "\bot^sl". Reserved Notation "\top^sl". (* Reserved notations for divisibility *) Reserved Notation "x %<| y" (at level 70, no associativity). Reserved Notation "\min_ i F" (at level 34, F at level 41, i at level 0, format "'[' \min_ i '/ ' F ']'"). Reserved Notation "\min_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \min_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\min_ ( i <- r ) F" (F at level 41, format "'[' \min_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\min_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \min_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\min_ ( m <= i < n ) F" (F at level 41, format "'[' \min_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\min_ ( i | P ) F" (F at level 41, format "'[' \min_ ( i | P ) '/ ' F ']'"). Reserved Notation "\min_ ( i : t | P ) F" (F at level 41). Reserved Notation "\min_ ( i : t ) F" (F at level 41). Reserved Notation "\min_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \min_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\min_ ( i < n ) F" (F at level 41, format "'[' \min_ ( i < n ) F ']'"). Reserved Notation "\min_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \min_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\min_ ( i 'in' A ) F" (F at level 41, format "'[' \min_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\max_ i F" (at level 34, F at level 41, i at level 0, format "'[' \max_ i '/ ' F ']'"). Reserved Notation "\max_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \max_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i <- r ) F" (F at level 41, format "'[' \max_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\max_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \max_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\max_ ( m <= i < n ) F" (F at level 41, format "'[' \max_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\max_ ( i | P ) F" (F at level 41, format "'[' \max_ ( i | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i : t | P ) F" (F at level 41). Reserved Notation "\max_ ( i : t ) F" (F at level 41). Reserved Notation "\max_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \max_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i < n ) F" (F at level 41, format "'[' \max_ ( i < n ) F ']'"). Reserved Notation "\max_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \max_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\max_ ( i 'in' A ) F" (F at level 41, format "'[' \max_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\min^d_ i F" (at level 41, F at level 41, i at level 0, format "'[' \min^d_ i '/ ' F ']'"). Reserved Notation "\min^d_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \min^d_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\min^d_ ( i <- r ) F" (F at level 41, r at level 60, format "'[' \min^d_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\min^d_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \min^d_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\min^d_ ( m <= i < n ) F" (F at level 41, format "'[' \min^d_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\min^d_ ( i | P ) F" (F at level 41, format "'[' \min^d_ ( i | P ) '/ ' F ']'"). Reserved Notation "\min^d_ ( i : t | P ) F" (F at level 41). Reserved Notation "\min^d_ ( i : t ) F" (F at level 41). Reserved Notation "\min^d_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \min^d_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\min^d_ ( i < n ) F" (F at level 41, format "'[' \min^d_ ( i < n ) F ']'"). Reserved Notation "\min^d_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \min^d_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\min^d_ ( i 'in' A ) F" (F at level 41, format "'[' \min^d_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "\max^d_ i F" (at level 41, F at level 41, i at level 0, format "'[' \max^d_ i '/ ' F ']'"). Reserved Notation "\max^d_ ( i <- r | P ) F" (F at level 41, i, r at level 60, format "'[' \max^d_ ( i <- r | P ) '/ ' F ']'"). Reserved Notation "\max^d_ ( i <- r ) F" (F at level 41, r at level 60, format "'[' \max^d_ ( i <- r ) '/ ' F ']'"). Reserved Notation "\max^d_ ( m <= i < n | P ) F" (F at level 41, i, n at level 60, format "'[' \max^d_ ( m <= i < n | P ) '/ ' F ']'"). Reserved Notation "\max^d_ ( m <= i < n ) F" (F at level 41, format "'[' \max^d_ ( m <= i < n ) '/ ' F ']'"). Reserved Notation "\max^d_ ( i | P ) F" (F at level 41, format "'[' \max^d_ ( i | P ) '/ ' F ']'"). Reserved Notation "\max^d_ ( i : t | P ) F" (F at level 41). Reserved Notation "\max^d_ ( i : t ) F" (F at level 41). Reserved Notation "\max^d_ ( i < n | P ) F" (F at level 41, n at level 60, format "'[' \max^d_ ( i < n | P ) '/ ' F ']'"). Reserved Notation "\max^d_ ( i < n ) F" (F at level 41, format "'[' \max^d_ ( i < n ) F ']'"). Reserved Notation "\max^d_ ( i 'in' A | P ) F" (F at level 41, A at level 60, format "'[' \max^d_ ( i 'in' A | P ) '/ ' F ']'"). Reserved Notation "\max^d_ ( i 'in' A ) F" (F at level 41, format "'[' \max^d_ ( i 'in' A ) '/ ' F ']'"). Reserved Notation "'{' 'omorphism' U '->' V '}'" (at level 0, U at level 98, V at level 99, format "{ 'omorphism' U -> V }"). Module Order. #[projections(primitive)] Record disp_t := Disp {d1 : unit; d2 : unit}. #[key="T", primitive] HB.mixin Record isDuallyPreorder (d : disp_t) T of Equality T := { le : rel T; lt : rel T; lt_def : forall x y, lt x y = (le x y) && ~~ (le y x); gt_def : forall x y, lt y x = (le y x) && ~~ (le x y); le_refl : reflexive le; ge_refl : reflexive (fun x y => le y x); le_trans : transitive le; ge_trans : transitive (fun x y => le y x); }. #[short(type="preorderType")] HB.structure Definition Preorder (d : disp_t) := { T of Choice T & isDuallyPreorder d T }. #[key="T", primitive] HB.mixin Record hasBottom d T of Preorder d T := { bottom : T; le0x : forall x, le bottom x; }. #[key="T", primitive] HB.mixin Record hasTop d T of Preorder d T := { top : T; lex1 : forall x, le x top; }. #[short(type="bPreorderType")] HB.structure Definition BPreorder d := { T of hasBottom d T & Preorder d T }. #[short(type="tPreorderType")] HB.structure Definition TPreorder d := { T of hasTop d T & Preorder d T }. #[short(type="tbPreorderType")] HB.structure Definition TBPreorder d := { T of hasTop d T & BPreorder d T }. Section PreorderDef. Variable (disp : disp_t) (T : preorderType disp). Local Notation "x <= y" := (le x y) : order_scope. Local Notation "x < y" := (lt x y) : order_scope. Definition comparable : rel T := fun (x y : T) => (x <= y) || (y <= x). Local Notation "x >=< y" := (comparable x y) : order_scope. Local Notation "x >< y" := (~~ (x >=< y)) : order_scope. Definition ge : simpl_rel T := [rel x y | y <= x]. Definition gt : simpl_rel T := [rel x y | y < x]. Definition leif (x y : T) C : Prop := ((x <= y) * ((x == y) = C))%type. Definition le_of_leif x y C (le_xy : @leif x y C) := le_xy.1 : le x y. Definition lteif (x y : T) C := if C then x <= y else x < y. Variant le_xor_gt (x y : T) : T -> T -> T -> T -> bool -> bool -> Set := | LeNotGt of x <= y : le_xor_gt x y x x y y true false | GtNotLe of y < x : le_xor_gt x y y y x x false true. Variant lt_xor_ge (x y : T) : T -> T -> T -> T -> bool -> bool -> Set := | LtNotGe of x < y : lt_xor_ge x y x x y y false true | GeNotLt of y <= x : lt_xor_ge x y y y x x true false. Definition min (x y : T) := if x < y then x else y. Definition max (x y : T) := if x < y then y else x. Variant compare (x y : T) : T -> T -> T -> T -> bool -> bool -> bool -> bool -> bool -> bool -> Set := | CompareLt of x < y : compare x y x x y y false false false true false true | CompareGt of y < x : compare x y y y x x false false true false true false | CompareEq of x = y : compare x y x x x x true true true true false false. Variant incompare (x y : T) : T -> T -> T -> T -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> Set := | InCompareLt of x < y : incompare x y x x y y false false false true false true true true | InCompareGt of y < x : incompare x y y y x x false false true false true false true true | InCompare of x >< y : incompare x y x y y x false false false false false false false false | InCompareEq of x = y : incompare x y x x x x true true true true false false true true. Definition arg_min {I : finType} := @extremum T I le. Definition arg_max {I : finType} := @extremum T I ge. (* Lifted min/max operations. *) Section LiftedPreorder. Variable T' : Type. Implicit Type f : T' -> T. Definition min_fun f g x := min (f x) (g x). Definition max_fun f g x := max (f x) (g x). End LiftedPreorder. Definition nondecreasing disp' (T' : preorderType disp') (f : T -> T') : Prop := {homo f : x y / x <= y}. End PreorderDef. Prenex Implicits lt le leif lteif. Arguments ge {_ _}. Arguments gt {_ _}. Arguments min {_ _}. Arguments max {_ _}. Arguments comparable {_ _}. Arguments min_fun {_ _ _} f g _ /. Arguments max_fun {_ _ _} f g _ /. Module Import Def. Notation nondecreasing := nondecreasing. Notation min := min. Notation max := max. End Def. Module Import PreOSyntax. Notation "<=%O" := le : function_scope. Notation ">=%O" := ge : function_scope. Notation "<%O" := lt : function_scope. Notation ">%O" := gt : function_scope. Notation "<?=%O" := leif : function_scope. Notation "<?<=%O" := lteif : function_scope. Notation ">=<%O" := comparable : function_scope. Notation "><%O" := (fun x y => ~~ (comparable x y)) : function_scope. Notation "<= y" := (ge y) : order_scope. Notation "<= y :> T" := (<= (y : T)) (only parsing) : order_scope. Notation ">= y" := (le y) : order_scope. Notation ">= y :> T" := (>= (y : T)) (only parsing) : order_scope. Notation "< y" := (gt y) : order_scope. Notation "< y :> T" := (< (y : T)) (only parsing) : order_scope. Notation "> y" := (lt y) : order_scope. Notation "> y :> T" := (> (y : T)) (only parsing) : order_scope. Notation "x <= y" := (le x y) : order_scope. Notation "x <= y :> T" := ((x : T) <= (y : T)) (only parsing) : order_scope. Notation "x >= y" := (y <= x) (only parsing) : order_scope. Notation "x >= y :> T" := ((x : T) >= (y : T)) (only parsing) : order_scope. Notation "x < y" := (lt x y) : order_scope. Notation "x < y :> T" := ((x : T) < (y : T)) (only parsing) : order_scope. Notation "x > y" := (y < x) (only parsing) : order_scope. Notation "x > y :> T" := ((x : T) > (y : T)) (only parsing) : order_scope. Notation "x <= y <= z" := ((x <= y) && (y <= z)) : order_scope. Notation "x < y <= z" := ((x < y) && (y <= z)) : order_scope. Notation "x <= y < z" := ((x <= y) && (y < z)) : order_scope. Notation "x < y < z" := ((x < y) && (y < z)) : order_scope. Notation "x <= y ?= 'iff' C" := (leif x y C) : order_scope. Notation "x <= y ?= 'iff' C :> T" := ((x : T) <= (y : T) ?= iff C) (only parsing) : order_scope. Notation "x < y ?<= 'if' C" := (lteif x y C) : order_scope. Notation "x < y ?<= 'if' C :> T" := ((x : T) < (y : T) ?<= if C) (only parsing) : order_scope. Notation ">=< y" := [pred x | comparable x y] : order_scope. Notation ">=< y :> T" := (>=< (y : T)) (only parsing) : order_scope. Notation "x >=< y" := (comparable x y) : order_scope. Notation ">< y" := [pred x | ~~ comparable x y] : order_scope. Notation ">< y :> T" := (>< (y : T)) (only parsing) : order_scope. Notation "x >< y" := (~~ (comparable x y)) : order_scope. Notation "[ 'arg' 'min_' ( i < i0 | P ) F ]" := (arg_min i0 (fun i => P%B) (fun i => F)) (i, i0 at level 10, format "[ 'arg' 'min_' ( i < i0 | P ) F ]") : order_scope. Notation "[ 'arg' 'min_' ( i < i0 'in' A ) F ]" := [arg min_(i < i0 | i \in A) F] (format "[ 'arg' 'min_' ( i < i0 'in' A ) F ]") : order_scope. Notation "[ 'arg' 'min_' ( i < i0 ) F ]" := [arg min_(i < i0 | true) F] (i0 at level 10, format "[ 'arg' 'min_' ( i < i0 ) F ]") : order_scope. Notation "[ 'arg' 'max_' ( i > i0 | P ) F ]" := (arg_max i0 (fun i => P%B) (fun i => F)) (i, i0 at level 10, format "[ 'arg' 'max_' ( i > i0 | P ) F ]") : order_scope. Notation "[ 'arg' 'max_' ( i > i0 'in' A ) F ]" := [arg max_(i > i0 | i \in A) F] (i, i0 at level 10, format "[ 'arg' 'max_' ( i > i0 'in' A ) F ]") : order_scope. Notation "[ 'arg' 'max_' ( i > i0 ) F ]" := [arg max_(i > i0 | true) F] (i, i0 at level 10, format "[ 'arg' 'max_' ( i > i0 ) F ]") : order_scope. Notation "f \min g" := (min_fun f g) : function_scope. Notation "f \max g" := (max_fun f g) : function_scope. Notation leLHS := (X in (X <= _)%O)%pattern. Notation leRHS := (X in (_ <= X)%O)%pattern. Notation ltLHS := (X in (X < _)%O)%pattern. Notation ltRHS := (X in (_ < X)%O)%pattern. Notation "\bot" := bottom : order_scope. Notation "\top" := top : order_scope. End PreOSyntax. HB.export PreOSyntax. Module PreOCoercions. Coercion le_of_leif : leif >-> is_true. End PreOCoercions. HB.export PreOCoercions. (**********) (* FINITE *) (**********) #[short(type="finPreorderType")] HB.structure Definition FinPreorder d := { T of Finite T & Preorder d T }. #[short(type="finBPreorderType")] HB.structure Definition FinBPreorder d := { T of FinPreorder d T & hasBottom d T }. #[short(type="finTPreorderType")] HB.structure Definition FinTPreorder d := { T of FinPreorder d T & hasTop d T }. #[short(type="finTBPreorderType")] HB.structure Definition FinTBPreorder d := { T of FinBPreorder d T & hasTop d T }. (********) (* DUAL *) (********) Definition dual T : Type := T. Definition dual_display (d : disp_t) := {| d1 := d2 d; d2 := d1 d |}. Notation dual_le := (@le (dual_display _) _). Notation dual_lt := (@lt (dual_display _) _). Notation dual_comparable := (@comparable (dual_display _) _). Notation dual_ge := (@ge (dual_display _) _). Notation dual_gt := (@gt (dual_display _) _). Notation dual_leif := (@leif (dual_display _) _). Notation dual_lteif := (@lteif (dual_display _) _). Notation dual_max := (@max (dual_display _) _). Notation dual_min := (@min (dual_display _) _). Notation dual_bottom := (@bottom (dual_display _) _). Notation dual_top := (@top (dual_display _) _). Module Import DualSyntax. Notation "T ^d" := (dual T) (format "T ^d") : type_scope. Notation "<=^d%O" := dual_le : function_scope. Notation ">=^d%O" := dual_ge : function_scope. Notation "<^d%O" := dual_lt : function_scope. Notation ">^d%O" := dual_gt : function_scope. Notation "<?=^d%O" := dual_leif : function_scope. Notation "<?<=^d%O" := dual_lteif : function_scope. Notation ">=<^d%O" := dual_comparable : function_scope. Notation "><^d%O" := (fun x y => ~~ dual_comparable x y) : function_scope. Notation "<=^d y" := (>=^d%O y) : order_scope. Notation "<=^d y :> T" := (<=^d (y : T)) (only parsing) : order_scope. Notation ">=^d y" := (<=^d%O y) : order_scope. Notation ">=^d y :> T" := (>=^d (y : T)) (only parsing) : order_scope. Notation "<^d y" := (>^d%O y) : order_scope. Notation "<^d y :> T" := (<^d (y : T)) (only parsing) : order_scope. Notation ">^d y" := (<^d%O y) : order_scope. Notation ">^d y :> T" := (>^d (y : T)) (only parsing) : order_scope. Notation "x <=^d y" := (<=^d%O x y) : order_scope. Notation "x <=^d y :> T" := ((x : T) <=^d (y : T)) (only parsing) : order_scope. Notation "x >=^d y" := (y <=^d x) (only parsing) : order_scope. Notation "x >=^d y :> T" := ((x : T) >=^d (y : T)) (only parsing) : order_scope. Notation "x <^d y" := (<^d%O x y) : order_scope. Notation "x <^d y :> T" := ((x : T) <^d (y : T)) (only parsing) : order_scope. Notation "x >^d y" := (y <^d x) (only parsing) : order_scope. Notation "x >^d y :> T" := ((x : T) >^d (y : T)) (only parsing) : order_scope. Notation "x <=^d y <=^d z" := ((x <=^d y) && (y <=^d z)) : order_scope. Notation "x <^d y <=^d z" := ((x <^d y) && (y <=^d z)) : order_scope. Notation "x <=^d y <^d z" := ((x <=^d y) && (y <^d z)) : order_scope. Notation "x <^d y <^d z" := ((x <^d y) && (y <^d z)) : order_scope. Notation "x <=^d y ?= 'iff' C" := (<?=^d%O x y C) : order_scope. Notation "x <=^d y ?= 'iff' C :> T" := ((x : T) <=^d (y : T) ?= iff C) (only parsing) : order_scope. Notation "x <^d y ?<= 'if' C" := (<?<=^d%O x y C) : order_scope. Notation "x <^d y ?<= 'if' C :> T" := ((x : T) <^d (y : T) ?<= if C) (only parsing) : order_scope. Notation ">=<^d x" := (>=<^d%O x) : order_scope. Notation ">=<^d y :> T" := (>=<^d (y : T)) (only parsing) : order_scope. Notation "x >=<^d y" := (>=<^d%O x y) : order_scope. Notation "><^d y" := [pred x | ~~ dual_comparable x y] : order_scope. Notation "><^d y :> T" := (><^d (y : T)) (only parsing) : order_scope. Notation "x ><^d y" := (~~ (><^d%O x y)) : order_scope. Notation "\bot^d" := dual_bottom : order_scope. Notation "\top^d" := dual_top : order_scope. End DualSyntax. Module DualPreorder. HB.instance Definition _ (T : eqType) := Equality.on T^d. HB.instance Definition _ (T : choiceType) := Choice.on T^d. HB.instance Definition _ (T : countType) := Countable.on T^d. HB.instance Definition _ (T : finType) := Finite.on T^d. HB.instance Definition _ (d : disp_t) (T : preorderType d) := isDuallyPreorder.Build (dual_display d) T^d gt_def lt_def ge_refl le_refl ge_trans le_trans. Lemma leEdual (d : disp_t) (T : preorderType d) (x y : T) : (x <=^d y :> T^d) = (y <= x). Proof. by []. Qed. Lemma ltEdual (d : disp_t) (T : preorderType d) (x y : T) : (x <^d y :> T^d) = (y < x). Proof. by []. Qed. HB.instance Definition _ d (T : tPreorderType d) := hasBottom.Build (dual_display d) T^d lex1. Lemma botEdual d (T : tPreorderType d) : (dual_bottom : T^d) = \top :> T. Proof. by []. Qed. HB.instance Definition _ d (T : bPreorderType d) := hasTop.Build (dual_display d) T^d le0x. Lemma topEdual d (T : bPreorderType d) : (dual_top : T^d) = \bot :> T. Proof. by []. Qed. End DualPreorder. HB.export DualPreorder. (**********) (* THEORY *) (**********) Module Import PreorderTheory. Section PreorderTheory. Context {disp : disp_t} {T : preorderType disp}. Implicit Types (x y : T) (s : seq T). Definition nondecreasing disp' (T' : preorderType disp') (f : T -> T') : Prop := {homo f : x y / x <= y}. Lemma geE x y : ge x y = (y <= x). Proof. by []. Qed. Lemma gtE x y : gt x y = (y < x). Proof. by []. Qed. Lemma lexx (x : T) : x <= x. Proof. exact: le_refl. Qed. Hint Resolve lexx : core. Definition le_refl : reflexive le := lexx. Definition ge_refl : reflexive ge := lexx. Hint Resolve le_refl : core. Lemma le_trans: transitive (<=%O : rel T). Proof. exact: le_trans. Qed. Lemma ge_trans: transitive (>=%O : rel T). Proof. by move=> ? ? ? ? /le_trans; apply. Qed. Lemma le_le_trans x y z t : z <= x -> y <= t -> x <= y -> z <= t. Proof. by move=> + /(le_trans _)/[apply]; apply: le_trans. Qed. Lemma lt_le_def x y: (x < y) = (x <= y) && ~~ (y <= x). Proof. exact: lt_def. Qed. Lemma ltxx x: x < x = false. Proof. by rewrite lt_le_def andbN. Qed. Definition lt_irreflexive : irreflexive lt := ltxx. Hint Resolve lt_irreflexive : core. Definition ltexx := (lexx, ltxx). Lemma lt_eqF x y: x < y -> x == y = false. Proof. by apply: contraTF => /eqP ->; rewrite ltxx. Qed. Lemma gt_eqF x y : y < x -> x == y = false. Proof. by move=> /lt_eqF; rewrite eq_sym. Qed. Lemma ltW x y: x < y -> x <= y. Proof. by rewrite lt_le_def => /andP[]. Qed. Lemma lt_le_trans y x z: x < y -> y <= z -> x < z. Proof. rewrite !lt_le_def => /andP[] xy /negP yx yz. apply/andP; split; first exact/(le_trans xy). by apply/negP => /(le_trans yz). Qed. Lemma lt_trans: transitive (<%O : rel T). Proof. by move=> y x z le1 /ltW le2; apply/(@lt_le_trans y). Qed. Lemma le_lt_trans y x z: x <= y -> y < z -> x < z. Proof. rewrite !lt_le_def => xy /andP[] yz /negP zy. apply/andP; split; first exact/(le_trans xy). by apply/negP => /(fun zx => le_trans zx xy). Qed. Lemma lt_nsym x y : x < y -> y < x -> False. Proof. by move=> xy /(lt_trans xy); rewrite ltxx. Qed. Lemma lt_asym x y : x < y < x = false. Proof. by apply/negP => /andP []; apply: lt_nsym. Qed. Lemma le_gtF x y: x <= y -> y < x = false. Proof. by move=> le_xy; apply/negP => /lt_le_trans /(_ le_xy); rewrite ltxx. Qed. Lemma lt_geF x y : x < y -> y <= x = false. Proof. by apply: contraTF => /le_gtF ->. Qed. Definition lt_gtF x y hxy := le_gtF (@ltW x y hxy). Lemma lt_leAnge x y : (x < y) = (x <= y) && ~~ (y <= x). Proof. exact: lt_le_def. Qed. Lemma lt_le_asym x y : x < y <= x = false. Proof. by apply/negP; move=> /andP[] xy /(lt_le_trans xy); rewrite ltxx. Qed. Lemma le_lt_asym x y : x <= y < x = false. Proof. by rewrite andbC lt_le_asym. Qed. Lemma le_path_min x s : path <=%O x s -> all (>= x) s. Proof. exact/order_path_min/le_trans. Qed. Lemma lt_path_min x s : path <%O x s -> all (> x) s. Proof. exact/order_path_min/lt_trans. Qed. Lemma le_path_sortedE x s : path <=%O x s = all (>= x) s && sorted <=%O s. Proof. exact/path_sortedE/le_trans. Qed. Lemma lt_path_sortedE x s : path <%O x s = all (> x) s && sorted <%O s. Proof. exact/path_sortedE/lt_trans. Qed. Lemma le_sorted_pairwise s : sorted <=%O s = pairwise <=%O s. Proof. exact/sorted_pairwise/le_trans. Qed. Lemma lt_sorted_pairwise s : sorted <%O s = pairwise <%O s. Proof. exact/sorted_pairwise/lt_trans. Qed. Lemma le_path_pairwise x s : path <=%O x s = pairwise <=%O (x :: s). Proof. exact/path_pairwise/le_trans. Qed. Lemma lt_path_pairwise x s : path <%O x s = pairwise <%O (x :: s). Proof. exact/path_pairwise/lt_trans. Qed. Lemma lt_sorted_is_uniq_le s : sorted <%O s -> uniq s && sorted <=%O s. Proof. rewrite le_sorted_pairwise lt_sorted_pairwise uniq_pairwise -pairwise_relI. apply/sub_pairwise => x y/= /[dup] + /ltW ->. by case: eqVneq => // ->; rewrite ltxx. Qed. Lemma le_sorted_mask m s : sorted <=%O s -> sorted <=%O (mask m s). Proof. exact/sorted_mask/le_trans. Qed. Lemma lt_sorted_mask m s : sorted <%O s -> sorted <%O (mask m s). Proof. exact/sorted_mask/lt_trans. Qed. Lemma le_sorted_filter a s : sorted <=%O s -> sorted <=%O (filter a s). Proof. exact/sorted_filter/le_trans. Qed. Lemma lt_sorted_filter a s : sorted <%O s -> sorted <%O (filter a s). Proof. exact/sorted_filter/lt_trans. Qed. Lemma le_path_mask x m s : path <=%O x s -> path <=%O x (mask m s). Proof. exact/path_mask/le_trans. Qed. Lemma lt_path_mask x m s : path <%O x s -> path <%O x (mask m s). Proof. exact/path_mask/lt_trans. Qed. Lemma le_path_filter x a s : path <=%O x s -> path <=%O x (filter a s). Proof. exact/path_filter/le_trans. Qed. Lemma lt_path_filter x a s : path <%O x s -> path <%O x (filter a s). Proof. exact/path_filter/lt_trans. Qed. Lemma le_sorted_ltn_nth (x0 : T) (s : seq T) : sorted <=%O s -> {in [pred n | (n < size s)%N] &, {homo nth x0 s : i j / (i < j)%N >-> i <= j}}. Proof. exact/sorted_ltn_nth/le_trans. Qed. Lemma le_sorted_leq_nth (x0 : T) (s : seq T) : sorted <=%O s -> {in [pred n | (n < size s)%N] &, {homo nth x0 s : i j / (i <= j)%N >-> i <= j}}. Proof. exact/sorted_leq_nth/le_refl/le_trans. Qed. Lemma lt_sorted_leq_nth (x0 : T) (s : seq T) : sorted <%O s -> {in [pred n | (n < size s)%N] &, {mono nth x0 s : i j / (i <= j)%N >-> i <= j}}. Proof. move=> /[dup] lt_s /lt_sorted_is_uniq_le /andP[s_uniq le_s] i j ilt jlt. case/boolP: (i <= j)%N; first exact/le_sorted_leq_nth. rewrite -ltnNge => /(sorted_ltn_nth lt_trans x0 lt_s j i jlt ilt). by rewrite lt_le_def => /andP[_] /negPf. Qed. Lemma lt_sorted_ltn_nth (x0 : T) (s : seq T) : sorted <%O s -> {in [pred n | (n < size s)%N] &, {mono nth x0 s : i j / (i < j)%N >-> i < j}}. Proof. move=> ss i j ilt jlt. rewrite lt_le_def (lt_sorted_leq_nth x0 ss)// (lt_sorted_leq_nth x0 ss)//. by rewrite -ltnNge andbC ltn_neqAle -andbA andbb. Qed. Lemma subseq_le_path x s1 s2 : subseq s1 s2 -> path <=%O x s2 -> path <=%O x s1. Proof. exact/subseq_path/le_trans. Qed. Lemma subseq_lt_path x s1 s2 : subseq s1 s2 -> path <%O x s2 -> path <%O x s1. Proof. exact/subseq_path/lt_trans. Qed. Lemma subseq_le_sorted s1 s2 : subseq s1 s2 -> sorted <=%O s2 -> sorted <=%O s1. Proof. exact/subseq_sorted/le_trans. Qed. Lemma subseq_lt_sorted s1 s2 : subseq s1 s2 -> sorted <%O s2 -> sorted <%O s1. Proof. exact/subseq_sorted/lt_trans. Qed. Lemma lt_sorted_uniq s : sorted <%O s -> uniq s. Proof. exact/sorted_uniq/ltxx/lt_trans. Qed. Lemma lt_sorted_eq s1 s2 : sorted <%O s1 -> sorted <%O s2 -> s1 =i s2 -> s1 = s2. Proof. exact/irr_sorted_eq/ltxx/lt_trans. Qed. Lemma filter_lt_nth x0 s i : sorted <%O s -> (i < size s)%N -> [seq x <- s | x < nth x0 s i] = take i s. Proof. move=> ss i_lt/=; rewrite -[X in filter _ X](mkseq_nth x0) filter_map. under eq_in_filter => j do [rewrite ?mem_iota => j_s /=; rewrite lt_sorted_ltn_nth//]. by rewrite (filter_iota_ltn 0) ?map_nth_iota0 // ltnW. Qed. Lemma count_lt_nth x0 s i : sorted <%O s -> (i < size s)%N -> count (< nth x0 s i) s = i. Proof. by move=> ss i_lt; rewrite -size_filter/= filter_lt_nth// size_take i_lt. Qed. Lemma filter_le_nth x0 s i : sorted <%O s -> (i < size s)%N -> [seq x <- s | x <= nth x0 s i] = take i.+1 s. Proof. move=> ss i_lt/=; rewrite -[X in filter _ X](mkseq_nth x0) filter_map. under eq_in_filter => j do [rewrite ?mem_iota => j_s /=; rewrite lt_sorted_leq_nth//]. by rewrite (filter_iota_leq 0)// map_nth_iota0. Qed. Lemma count_le_nth x0 s i : sorted <%O s -> (i < size s)%N -> count (<= nth x0 s i) s = i.+1. Proof. by move=> ss i_lt; rewrite -size_filter/= filter_le_nth// size_takel. Qed. Lemma sorted_filter_lt x s : sorted <=%O s -> [seq y <- s | y < x] = take (count (< x) s) s. Proof. elim: s => [//|y s IHs]/=; rewrite (path_sortedE le_trans) => /andP[le_y_s ss]. case: ifP => [|ltyxF]; rewrite IHs//. rewrite (@eq_in_count _ _ pred0) ?count_pred0/= ?take0// => z. by move=> /(allP le_y_s) yz; apply: contraFF ltyxF; apply: le_lt_trans. Qed. Lemma sorted_filter_le x s : sorted <=%O s -> [seq y <- s | y <= x] = take (count (<= x) s) s. Proof. elim: s => [//|y s IHs]/=; rewrite (path_sortedE le_trans) => /andP[le_y_s ss]. case: ifP => [|leyxF]; rewrite IHs//. rewrite (@eq_in_count _ _ pred0) ?count_pred0/= ?take0// => z. by move=> /(allP le_y_s) yz; apply: contraFF leyxF; apply: le_trans. Qed. Lemma nth_count_le x x0 s i : sorted <=%O s -> (i < count (<= x) s)%N -> nth x0 s i <= x. Proof. move=> ss iltc; rewrite -(nth_take _ iltc) -sorted_filter_le //. by apply/(all_nthP _ (filter_all (<= x) _)); rewrite size_filter. Qed. Lemma nth_count_lt x x0 s i : sorted <=%O s -> (i < count (< x) s)%N -> nth x0 s i < x. Proof. move=> ss iltc; rewrite -(nth_take _ iltc) -sorted_filter_lt //. by apply/(all_nthP _ (filter_all (< x) _)); rewrite size_filter. Qed. Lemma sort_le_id s : sorted <=%O s -> sort <=%O s = s. Proof. exact/sorted_sort/le_trans. Qed. Lemma sort_lt_id s : sorted <%O s -> sort <%O s = s. Proof. exact/sorted_sort/lt_trans. Qed. Lemma comparable_leNgt x y : x >=< y -> (x <= y) = ~~ (y < x). Proof. rewrite /comparable lt_le_def. by case: (x <= y) => //=; case: (y <= x). Qed. Lemma comparable_ltNge x y : x >=< y -> (x < y) = ~~ (y <= x). Proof. rewrite /comparable lt_le_def. by case: (x <= y) => //=; case: (y <= x). Qed. Lemma comparable_sym x y : (y >=< x) = (x >=< y). Proof. by rewrite /comparable orbC. Qed. Lemma comparablexx x : x >=< x. Proof. by rewrite /comparable lexx. Qed. Lemma incomparable_eqF x y : (x >< y) -> (x == y) = false. Proof. by apply: contraNF => /eqP ->; rewrite comparablexx. Qed. Lemma incomparable_leF x y : (x >< y) -> (x <= y) = false. Proof. by apply: contraNF; rewrite /comparable => ->. Qed. Lemma incomparable_ltF x y : (x >< y) -> (x < y) = false. Proof. by rewrite lt_le_def => /incomparable_leF ->. Qed. Lemma le_comparable (x y : T) : x <= y -> x >=< y. Proof. by rewrite /comparable => ->. Qed. Lemma lt_comparable (x y : T) : x < y -> x >=< y. Proof. by rewrite /comparable => /ltW ->. Qed. Lemma ge_comparable (x y : T) : y <= x -> x >=< y. Proof. by rewrite /comparable orbC => ->. Qed. Lemma gt_comparable (x y : T) : y < x -> x >=< y. Proof. by rewrite /comparable orbC => /ltW ->. Qed. (* leif *) Lemma leif_refl x C : reflect (x <= x ?= iff C) C. Proof. by apply: (iffP idP) => [-> | <-] //; split; rewrite ?eqxx. Qed. Lemma eq_leif x y C : x <= y ?= iff C -> (x == y) = C. Proof. by move=> []. Qed. Lemma eqTleif x y C : x <= y ?= iff C -> C -> x = y. Proof. by move=> [] _ <- /eqP. Qed. (* lteif *) Lemma lteif_trans x y z C1 C2 : x < y ?<= if C1 -> y < z ?<= if C2 -> x < z ?<= if C1 && C2. Proof. case: C1 C2 => [][]; [exact: le_trans | exact: le_lt_trans | exact: lt_le_trans | exact: lt_trans]. Qed. Lemma lteifxx x C : (x < x ?<= if C) = C. Proof. by case: C; rewrite /= ltexx. Qed. Lemma lteifNF x y C : y < x ?<= if ~~ C -> x < y ?<= if C = false. Proof. by case: C => [/lt_geF|/le_gtF]. Qed. Lemma lteifS x y C : x < y -> x < y ?<= if C. Proof. by case: C => //= /ltW. Qed. Lemma lteifT x y : x < y ?<= if true = (x <= y). Proof. by []. Qed. Lemma lteifF x y : x < y ?<= if false = (x < y). Proof. by []. Qed. Lemma lteif_orb x y : {morph lteif x y : p q / p || q}. Proof. case=> [][] /=. - by rewrite orbb. - by case/boolP: (x < y) => [/ltW -> //|_]; rewrite orbF. - by case/boolP: (x < y) => [/ltW ->|]. - by rewrite orbb. Qed. Lemma lteif_andb x y : {morph lteif x y : p q / p && q}. Proof. case=> [][] /=. - by rewrite andbb. - by rewrite lt_le_def andbA andbb. - by rewrite andbC lt_le_def andbA andbb. - by rewrite andbb. Qed. Lemma lteif_imply C1 C2 x y : C1 ==> C2 -> x < y ?<= if C1 -> x < y ?<= if C2. Proof. by case: C1 C2 => [][] //= _ /ltW. Qed. Lemma lteifW C x y : x < y ?<= if C -> x <= y. Proof. by case: C => // /ltW. Qed. Lemma ltrW_lteif C x y : x < y -> x < y ?<= if C. Proof. by case: C => // /ltW. Qed. (* min and max *) Lemma minElt x y : min x y = if x < y then x else y. Proof. by []. Qed. Lemma maxElt x y : max x y = if x < y then y else x. Proof. by []. Qed. Lemma minxx : idempotent_op (min : T -> T -> T). Proof. by rewrite /min => x; rewrite ltxx. Qed. Lemma maxxx : idempotent_op (max : T -> T -> T). Proof. by rewrite /max => x; rewrite ltxx. Qed. Lemma min_minKx x y : min (min x y) y = min x y. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma min_minxK x y : min x (min x y) = min x y. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma max_maxKx x y : max (max x y) y = max x y. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma max_maxxK x y : max x (max x y) = max x y. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma comparable_minl z : {in >=< z &, forall x y, min x y >=< z}. Proof. by move=> x y cmp_xz cmp_yz; rewrite /min; case: ifP. Qed. Lemma comparable_minr z : {in >=<%O z &, forall x y, z >=< min x y}. Proof. by move=> x y cmp_xz cmp_yz; rewrite /min; case: ifP. Qed. Lemma comparable_maxl z : {in >=< z &, forall x y, max x y >=< z}. Proof. by move=> x y cmp_xz cmp_yz; rewrite /max; case: ifP. Qed. Lemma comparable_maxr z : {in >=<%O z &, forall x y, z >=< max x y}. Proof. by move=> x y cmp_xz cmp_yz; rewrite /max; case: ifP. Qed. Section Comparable2. Variables (z x y : T) (cmp_xy : x >=< y). Lemma comparable_le_min : (z <= min x y) = (z <= x) && (z <= y). Proof. move: cmp_xy; rewrite /min /comparable lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - by rewrite andbC; case/boolP: (z <= y) => zy //=; apply/esym/(le_trans zy). - by case/boolP: (z <= x) => zx //=; apply/esym/(le_trans zx). - by rewrite andbC; case/boolP: (z <= y) => zy //=; apply/esym/(le_trans zy). Qed. Lemma comparable_ge_min : (min x y <= z) = (x <= z) || (y <= z). Proof. move: cmp_xy; rewrite /min /comparable lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - rewrite orbC; case/boolP: (y <= z) => //= /negP yz. by apply/esym/negP => /(le_trans yx). - by case/boolP: (x <= z) => //= /negP xz; apply/esym/negP => /(le_trans xy). - rewrite orbC; case/boolP: (y <= z) => //= /negP yz. by apply/esym/negP => /(le_trans yx). Qed. Lemma comparable_lt_min : (z < min x y) = (z < x) && (z < y). Proof. move: cmp_xy; rewrite /min /comparable !lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - rewrite -!lt_le_def; case/boolP: (z < x) => //= /negP zx. by apply/negP => zy; apply/zx/(lt_le_trans zy). - rewrite -!lt_le_def; case/boolP: (z < x) => //= zx; apply/esym/(lt_trans zx). by rewrite lt_le_def xy yx. - rewrite -!lt_le_def andbC; case/boolP: (z < y) => //= zy; apply/esym/(lt_trans zy). by rewrite lt_le_def xy yx. Qed. Lemma comparable_gt_min : (min x y < z) = (x < z) || (y < z). Proof. move: cmp_xy; rewrite /min /comparable !lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - rewrite -!lt_le_def orbC; case/boolP: (y < z) => //= /negP yz. by apply/esym/negP => xz; apply/yz/(le_lt_trans yx). - rewrite -!lt_le_def; case/boolP: (x < z) => //= /negP xz. by apply/esym/negP => yz; apply/xz/(le_lt_trans xy). - rewrite -!lt_le_def orbC; case/boolP: (y < z) => //= /negP yz. by apply/esym/negP => xz; apply/yz/(le_lt_trans yx). Qed. Lemma comparable_le_max : (z <= max x y) = (z <= x) || (z <= y). Proof. move: cmp_xy; rewrite /max /comparable lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - case/boolP: (z <= x) => //= /negP zx. by apply/esym/negP => zy; apply/zx/(le_trans zy). - rewrite orbC; case/boolP: (z <= y) => //= /negP zy. by apply/esym/negP => zx; apply/zy/(le_trans zx). - case/boolP: (z <= x) => //= /negP zx. by apply/esym/negP => zy; apply/zx/(le_trans zy). Qed. Lemma comparable_ge_max : (max x y <= z) = (x <= z) && (y <= z). Proof. move: cmp_xy; rewrite /max /comparable lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - case/boolP: (x <= z) => //= xz. by apply/esym/(le_trans yx). - rewrite andbC; case/boolP: (y <= z) => //= yz. by apply/esym/(le_trans xy). - case/boolP: (x <= z) => //= xz. by apply/esym/(le_trans yx). Qed. Lemma comparable_lt_max : (z < max x y) = (z < x) || (z < y). Proof. move: cmp_xy; rewrite /max /comparable !lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - rewrite -!lt_le_def; case/boolP: (z < x) => //= /negP zx. by apply/esym/negP => zy; apply/zx/(lt_le_trans zy). - rewrite -!lt_le_def orbC; case/boolP: (z < y) => //= /negP zy. by apply/esym/negP => zx; apply/zy/(lt_le_trans zx). - rewrite -!lt_le_def; case/boolP: (z < x) => //= /negP zx. by apply/esym/negP => zy; apply/zx/(lt_le_trans zy). Qed. Lemma comparable_gt_max : (max x y < z) = (x < z) && (y < z). Proof. move: cmp_xy; rewrite /max /comparable !lt_le_def. case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _. - rewrite -!lt_le_def; case/boolP: (x < z) => //= xz. by apply/esym/(le_lt_trans yx). - rewrite -!lt_le_def andbC; case/boolP: (y < z) => //= yz. by apply/esym/(le_lt_trans xy). - rewrite -!lt_le_def; case/boolP: (x < z) => //= xz. by apply/esym/(le_lt_trans yx). Qed. Lemma comparable_minxK : max (min x y) y = y. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma comparable_minKx : max x (min x y) = x. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma comparable_maxxK : min (max x y) y = y. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma comparable_maxKx : min x (max x y) = x. Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed. Lemma comparable_lteif_minr C : (z < min x y ?<= if C) = (z < x ?<= if C) && (z < y ?<= if C). Proof. by case: C; rewrite /= (comparable_le_min, comparable_lt_min). Qed. Lemma comparable_lteif_minl C : (min x y < z ?<= if C) = (x < z ?<= if C) || (y < z ?<= if C). Proof. by case: C; rewrite /= (comparable_ge_min, comparable_gt_min). Qed. Lemma comparable_lteif_maxr C : (z < max x y ?<= if C) = (z < x ?<= if C) || (z < y ?<= if C). Proof. by case: C; rewrite /= (comparable_le_max, comparable_lt_max). Qed. Lemma comparable_lteif_maxl C : (max x y < z ?<= if C) = (x < z ?<= if C) && (y < z ?<= if C). Proof. by case: C; rewrite /= (comparable_ge_max, comparable_gt_max). Qed. End Comparable2. Section Comparable3. Variables (x y z : T) (cmp_xy : x >=< y) (cmp_xz : x >=< z) (cmp_yz : y >=< z). Lemma comparable_minA : min x (min y z) = min (min x y) z. Proof. move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def. case/boolP: (x <= y) => xy; case/boolP: (y <= x) => yx; case/boolP: (x <= z) => xz; case/boolP: (z <= x) => zx; case/boolP: (y <= z) => yz; case/boolP: (z <= y) => zy //= _ _ _. - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). - by move: zy; rewrite (le_trans zx xy). - by move: zy; rewrite (le_trans zx xy). - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). Qed. Lemma comparable_maxA : max x (max y z) = max (max x y) z. Proof. move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def. case/boolP: (x <= y) => xy; case/boolP: (y <= x) => yx; case/boolP: (x <= z) => xz; case/boolP: (z <= x) => zx; case/boolP: (y <= z) => yz; case/boolP: (z <= y) => zy //= _ _ _. - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). - by move: zy; rewrite (le_trans zx xy). - by move: zy; rewrite (le_trans zx xy). - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). Qed. Lemma comparable_min_maxl : min (max x y) z = max (min x z) (min y z). Proof. move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def. case/boolP: (x <= y) => xy; case/boolP: (y <= x) => yx; case/boolP: (x <= z) => xz; case/boolP: (z <= x) => zx; case/boolP: (y <= z) => yz; case/boolP: (z <= y) => zy; rewrite ?lexx => //= _ _ _. - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). - by move: zy; rewrite (le_trans zx xy). - by move: zy; rewrite (le_trans zx xy). - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). Qed. Lemma comparable_max_minr : max x (min y z) = min (max x y) (max x z). Proof. move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def. case/boolP: (x <= y) => xy; case/boolP: (y <= x) => yx; case/boolP: (x <= z) => xz; case/boolP: (z <= x) => zx; case/boolP: (y <= z) => yz; case/boolP: (z <= y) => zy; rewrite ?lexx => //= _ _ _. - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). - by move: zy; rewrite (le_trans zx xy). - by move: zy; rewrite (le_trans zx xy). - by move: zx; rewrite (le_trans zy yx). - by move: zx; rewrite (le_trans zy yx). Qed. End Comparable3. Section ArgExtremum. Context (I : finType) (i0 : I) (P : {pred I}) (F : I -> T) (Pi0 : P i0). Hypothesis F_comparable : {in P &, forall i j, F i >=< F j}. Lemma comparable_arg_minP: extremum_spec <=%O P F (arg_min i0 P F). Proof. by apply: extremum_inP => // [x _|y x z _ _ _]; [apply: lexx|apply: le_trans]. Qed. Lemma comparable_arg_maxP: extremum_spec >=%O P F (arg_max i0 P F). Proof. apply: extremum_inP => // [x _|y x z _ _ _|]; [exact: lexx|exact: ge_trans|]. by move=> x y xP yP; rewrite orbC [_ || _]F_comparable. Qed. End ArgExtremum. (* monotonicity *) Lemma comparable_bigl x x0 op I (P : pred I) F (s : seq I) : {in >=< x &, forall y z, op y z >=< x} -> x0 >=< x -> {in P, forall i, F i >=< x} -> \big[op/x0]_(i <- s | P i) F i >=< x. Proof. by move=> *; elim/big_ind : _. Qed. Lemma comparable_bigr x x0 op I (P : pred I) F (s : seq I) : {in >=<%O x &, forall y z, x >=< op y z} -> x >=< x0 -> {in P, forall i, x >=< F i} -> x >=< \big[op/x0]_(i <- s | P i) F i. Proof. by move=> *; elim/big_ind : _. Qed. Section bigminmax. Variables (I : Type) (r : seq I) (f : I -> T) (x0 x : T) (P : pred I). Lemma bigmax_lt : x0 < x -> (forall i, P i -> f i < x) -> \big[max/x0]_(i <- r | P i) f i < x. Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite maxElt; case: ifPn. Qed. Lemma lt_bigmin : x < x0 -> (forall i, P i -> x < f i) -> x < \big[min/x0]_(i <- r | P i) f i. Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite minElt; case: ifPn. Qed. End bigminmax. End PreorderTheory. #[global] Hint Resolve comparable_minr comparable_minl : core. #[global] Hint Resolve comparable_maxr comparable_maxl : core. Section ContraTheory. Context {disp1 disp2 : disp_t} {T1 : preorderType disp1} {T2 : preorderType disp2}. Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop). Lemma comparable_contraTle b x y : x >=< y -> (y < x -> ~~ b) -> (b -> x <= y). Proof. by move=> /comparable_leNgt ->; case: (y < x); case: b. Qed. Lemma comparable_contraTlt b x y : x >=< y -> (y <= x -> ~~ b) -> (b -> x < y). Proof. by move=> /comparable_ltNge ->; case: (y <= x); case: b. Qed. Lemma comparable_contraPle P x y : x >=< y -> (y < x -> ~ P) -> (P -> x <= y). Proof. by move=> /comparable_leNgt -> np p; apply/negP => /np. Qed. Lemma comparable_contraPlt P x y : x >=< y -> (y <= x -> ~ P) -> (P -> x < y). Proof. by move=> /comparable_ltNge -> np p; apply/negP => /np. Qed. Lemma comparable_contraNle b x y : x >=< y -> (y < x -> b) -> (~~ b -> x <= y). Proof. by move=> /comparable_leNgt ->; case: (y < x); case: b. Qed. Lemma comparable_contraNlt b x y : x >=< y -> (y <= x -> b) -> (~~ b -> x < y). Proof. by move=> /comparable_ltNge ->; case: (y <= x); case: b. Qed. Lemma comparable_contra_not_le P x y : x >=< y -> (y < x -> P) -> (~ P -> x <= y). Proof. by move=> /comparable_leNgt -> np p; apply/negP => /np. Qed. Lemma comparable_contra_not_lt P x y : x >=< y -> (y <= x -> P) -> (~ P -> x < y). Proof. by move=> /comparable_ltNge -> np p; apply/negP => /np. Qed. Lemma comparable_contraFle b x y : x >=< y -> (y < x -> b) -> (b = false -> x <= y). Proof. by move=> /comparable_leNgt -> np /negP p; apply/negP => /np. Qed. Lemma comparable_contraFlt b x y : x >=< y -> (y <= x -> b) -> (b = false -> x < y). Proof. by move=> /comparable_ltNge -> np /negP p; apply/negP => /np. Qed. Lemma comparable_contra_leq_le m n x y : x >=< y -> (y < x -> (n < m)%N) -> ((m <= n)%N -> x <= y). Proof. by rewrite ltnNge; apply/comparable_contraTle. Qed. Lemma comparable_contra_leq_lt m n x y : x >=< y -> (y <= x -> (n < m)%N) -> ((m <= n)%N -> x < y). Proof. by rewrite ltnNge; apply/comparable_contraTlt. Qed. Lemma comparable_contra_ltn_le m n x y : x >=< y -> (y < x -> (n <= m)%N) -> ((m < n)%N -> x <= y). Proof. by rewrite ltnNge; apply/comparable_contraNle. Qed. Lemma comparable_contra_ltn_lt m n x y : x >=< y -> (y <= x -> (n <= m)%N) -> ((m < n)%N -> x < y). Proof. by rewrite ltnNge; apply/comparable_contraNlt. Qed. Lemma comparable_contra_le x y z t : z >=< t -> (t < z -> y < x) -> (x <= y -> z <= t). Proof. rewrite /comparable lt_le_def; case: (z <= t) => //= -> /(_ erefl) yx. by move=> /(lt_le_trans yx); rewrite ltxx. Qed. Lemma comparable_contra_le_lt x y z t : z >=< t -> (t <= z -> y < x) -> (x <= y -> z < t). Proof. rewrite /comparable [z < t]lt_le_def orbC; case: (t <= z) => /= [_|-> //]. by move=> /(_ erefl) yx /(lt_le_trans yx); rewrite ltxx. Qed. Lemma comparable_contra_lt_le x y z t : z >=< t -> (t < z -> y <= x) -> (x < y -> z <= t). Proof. rewrite /comparable lt_le_def; case: (z <= t) => //= -> /(_ erefl) yx. by move=> /(le_lt_trans yx); rewrite ltxx. Qed. Lemma comparable_contra_lt x y z t : z >=< t -> (t <= z -> y <= x) -> (x < y -> z < t). Proof. rewrite /comparable [z < t]lt_le_def orbC; case: (t <= z) => /= [_|-> //]. by move=> /(_ erefl) yx /(le_lt_trans yx); rewrite ltxx. Qed. End ContraTheory. Section PreorderMonotonyTheory. Context {disp disp' : disp_t}. Context {T : preorderType disp} {T' : preorderType disp'}. Implicit Types (m n p : nat) (x y z : T) (u v w : T'). Variables (D D' : {pred T}) (f : T -> T'). Hint Resolve lexx lt_le_def : core. Lemma leW_mono : {mono f : x y / x <= y} -> {mono f : x y / x < y}. Proof. by move=> fmono x y; rewrite !lt_le_def !fmono. Qed. Lemma leW_nmono : {mono f : x y /~ x <= y} -> {mono f : x y /~ x < y}. Proof. by move=> fmono x y; rewrite !lt_le_def !fmono. Qed. Lemma leW_mono_in : {in D &, {mono f : x y / x <= y}} -> {in D &, {mono f : x y / x < y}}. Proof. by move=> fmono x y xD yD; rewrite !lt_le_def !fmono. Qed. Lemma leW_nmono_in : {in D &, {mono f : x y /~ x <= y}} -> {in D &, {mono f : x y /~ x < y}}. Proof. by move=> fmono x y xD yD; rewrite !lt_le_def !fmono. Qed. End PreorderMonotonyTheory. End PreorderTheory. #[global] Hint Resolve lexx le_refl ltxx lt_irreflexive ltW lt_eqF : core. Arguments leif_refl {disp T x C}. Module Import BPreorderTheory. Section BPreorderTheory. Context {disp : disp_t} {T : bPreorderType disp}. Implicit Types (x y : T). Lemma le0x x : \bot <= x. Proof. exact: le0x. Qed. Lemma ltx0 x : (x < \bot) = false. Proof. exact/le_gtF/le0x. Qed. End BPreorderTheory. End BPreorderTheory. Module Import TPreorderTheory. Section TPreorderTheory. Context {disp : disp_t} {T : tPreorderType disp}. Implicit Types (x y : T). Lemma lex1 x : x <= \top. Proof. exact: lex1. Qed. Lemma lt1x x : (\top < x) = false. Proof. exact: (@ltx0 _ T^d). Qed. End TPreorderTheory. End TPreorderTheory. #[global] Hint Extern 0 (is_true (\bot <= _)) => exact: le0x : core. #[global] Hint Extern 0 (is_true (_ <= \top)) => exact: lex1 : core. (*************) (* FACTORIES *) (*************) (* preorder *) HB.factory Record isPreorder (d : disp_t) T of Equality T := { le : rel T; lt : rel T; lt_def : forall x y, lt x y = (le x y) && ~~ (le y x); le_refl : reflexive le; le_trans : transitive le; }. HB.builders Context (d : disp_t) T of isPreorder d T. (* TODO: print nice error message when keyed type is not provided *) Let ge_trans : transitive (fun x y => le y x). Proof. by move=> x y z /[swap]; apply: le_trans. Qed. #[warning="-HB.no-new-instance"] HB.instance Definition _ := @isDuallyPreorder.Build d T le _ lt_def (fun x y => lt_def y x) le_refl le_refl le_trans ge_trans. HB.end. HB.factory Record Le_isPreorder (d : disp_t) T of Equality T := { le : rel T; le_refl : reflexive le; le_trans : transitive le; }. HB.builders Context (d : disp_t) T of Le_isPreorder d T. (* TODO: print nice error message when keyed type is not provided *) #[warning="-HB.no-new-instance"] HB.instance Definition _ := @isPreorder.Build d T le _ (fun _ _ => erefl) le_refl le_trans. HB.end. HB.factory Record LtLe_isPreorder (d : disp_t) T of Equality T := { le : rel T; lt : rel T; le_def : forall x y, le x y = (x == y) || lt x y; lt_irr : irreflexive lt; lt_trans : transitive lt; }. HB.builders Context (d : disp_t) T of LtLe_isPreorder d T. Let le_refl : reflexive le. Proof. by move=> x; rewrite le_def eqxx. Qed. Let le_trans : transitive le. Proof. move=> y x z; rewrite !le_def; case: (eqVneq x y) => [->|]//= neq_xy. by case: (eqVneq y z) => /= [<- ->|_ /lt_trans yx /yx ->]; rewrite orbT. Qed. Let lt_le_def x y : lt x y = (le x y) && ~~ (le y x). Proof. rewrite !le_def eq_sym; have [->|_ /=] := eqVneq x y; first by rewrite lt_irr. case/boolP: (lt x y) => //= xy; apply/esym/negP => /(lt_trans xy). by rewrite lt_irr. Qed. #[warning="-HB.no-new-instance"] HB.instance Definition _ := @isPreorder.Build d T le lt lt_le_def le_refl le_trans . HB.end. HB.factory Record Lt_isPreorder (d : disp_t) T of Equality T := { lt : rel T; lt_irr : irreflexive lt; lt_trans : transitive lt; }. HB.builders Context (d : disp_t) (T : Type) of Lt_isPreorder d T. #[warning="-HB.no-new-instance"] HB.instance Definition _ := @LtLe_isPreorder.Build d T _ lt (fun _ _ => erefl) lt_irr lt_trans. HB.end. Module PreCancelPartial. Section PreCancelPartial. Variables (disp : disp_t) (T : choiceType). Variables (disp' : disp_t) (T' : preorderType disp') (f : T -> T'). Definition le (x y : T) := f x <= f y. Definition lt (x y : T) := f x < f y. Fact refl : reflexive le. Proof. by move=> ?; apply: lexx. Qed. Fact trans : transitive le. Proof. by move=> ? ? ?; apply: le_trans. Qed. Fact ge_trans : transitive (fun x y => le y x). Proof. by move=> ? ? ?; apply: ge_trans. Qed. Fact lt_le_def x y : lt x y = le x y && ~~ le y x. Proof. exact: lt_le_def. Qed. Definition PrePcan := isPreorder.Build disp T lt_le_def refl trans. End PreCancelPartial. End PreCancelPartial. (* FIXME Fail #[export] HB.instance Definition _ (disp : disp_t) (T : choiceType) (disp' : disp_t) (T' : porderType disp') (f : T -> T') (f_inj : injective f): isPreorder disp (inj_type f_inj) := @PreCancelPartial.PrePcan disp (inj_type f_inj) disp' T' f. *) #[export] HB.instance Definition _ (disp : disp_t) (T : Type) (disp' : disp_t) (T' : preorderType disp') (f : T -> T') (f' : T' -> option T) (f_can : pcancel f f') : isPreorder disp (pcan_type f_can) := @PreCancelPartial.PrePcan disp (pcan_type f_can) disp' T' f. #[export] HB.instance Definition _ (disp : disp_t) (T : Type) (disp' : disp_t) (T' : preorderType disp') (f : T -> T') (f' : T' -> T) (f_can : cancel f f') : isPreorder disp (can_type f_can) := @PreCancelPartial.PrePcan disp (can_type f_can) disp' T' f. (* Morphism hierarchy. *) Definition order_morphism d (T : preorderType d) d' (T' : preorderType d') (f : T -> T') : Prop := {mono f : x y / x <= y}. HB.mixin Record isOrderMorphism d (T : preorderType d) d' (T' : preorderType d') (apply : T -> T') := { omorph_le_subproof : {homo apply : x y / x <= y} ; }. HB.structure Definition OrderMorphism d (T : preorderType d) d' (T' : preorderType d') := {f of isOrderMorphism d T d' T' f}. Module OrderMorphismExports. Notation "{ 'omorphism' T -> T' }" := (@OrderMorphism.type _ T%type _ T'%type) : type_scope. End OrderMorphismExports. HB.export OrderMorphismExports. Module Import OrderMorphismTheory. Section OrderMorphismTheory. Lemma omorph_le (d : disp_t) (T : preorderType d) (d' : disp_t) (T' : preorderType d') (f : {omorphism T -> T'}) : {homo f : x y / x <= y}. Proof. exact: omorph_le_subproof. Qed. Section IdCompFun. Variables (d : disp_t) (T : preorderType d) (d' : disp_t) (T' : preorderType d'). Variables (d'' : disp_t) (T'' : preorderType d''). Variables (f : {omorphism T' -> T''}) (g : {omorphism T -> T'}). Fact idfun_is_nondecreasing : nondecreasing (@idfun T). Proof. by []. Qed. #[export] HB.instance Definition _ := isOrderMorphism.Build d T d T idfun idfun_is_nondecreasing. Fact comp_is_nondecreasing : nondecreasing (f \o g). Proof. by move=> ? ? ?; do 2 apply: omorph_le. Qed. #[export] HB.instance Definition _ := isOrderMorphism.Build d T d'' T'' (f \o g) comp_is_nondecreasing. End IdCompFun. End OrderMorphismTheory. End OrderMorphismTheory. HB.mixin Record isSubPreorder d (T : preorderType d) (S : pred T) d' U of SubType T S U & Preorder d' U := { le_val : {mono (val : U -> T) : x y / x <= y}; }. #[short(type="subPreorder")] HB.structure Definition SubPreorder d (T : preorderType d) S d' := { U of SubEquality T S U & Preorder d' U & isSubPreorder d T S d' U }. Module Import SubPreorderTheory. Section SubPreorderTheory. Context (d : disp_t) (T : preorderType d) (S : pred T). Context (d' : disp_t) (U : SubPreorder.type S d'). Local Notation val := (val : U -> T). #[deprecated(since="mathcomp 2.3.0", note="Use le_val instead.")] Lemma leEsub x y : (x <= y) = (val x <= val y). Proof. by rewrite le_val. Qed. Lemma lt_val : {mono val : x y / x < y}. Proof. by move=> x y; rewrite !lt_leAnge !le_val. Qed. #[deprecated(since="mathcomp 2.3.0", note="Use lt_val instead.")] Lemma ltEsub x y : (x < y) = (val x < val y). Proof. by rewrite lt_val. Qed. Lemma le_wval : {homo val : x y / x <= y}. Proof. exact/mono2W/le_val. Qed. Lemma lt_wval : {homo val : x y / x < y}. Proof. exact/mono2W/lt_val. Qed. HB.instance Definition _ := isOrderMorphism.Build d' U d T val le_wval. End SubPreorderTheory. Arguments lt_val {d T S d' U} x y. Arguments le_wval {d T S d' U} x y. Arguments lt_wval {d T S d' U} x y. End SubPreorderTheory. HB.factory Record SubChoice_isSubPreorder d (T : preorderType d) S (d' : disp_t) U of SubChoice T S U := {}. HB.builders Context d T S d' U of SubChoice_isSubPreorder d T S d' U. HB.instance Definition _ : isPreorder d' U := @PreCancelPartial.PrePcan d' U d T val. Fact valD : order_morphism (val : U -> T). Proof. by []. Qed. HB.instance Definition _ := isSubPreorder.Build d T S d' U valD. HB.end. Module SubOrderExports. Notation "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: ]" := (SubChoice_isSubPreorder.Build _ _ _ _ U) (at level 0, format "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: 'with' disp ]" := (SubChoice_isSubPreorder.Build _ _ _ disp U) (at level 0, format "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: 'with' disp ]") : form_scope. End SubOrderExports. HB.export SubOrderExports. (*************) (* INSTANCES *) (*************) (********************) (* Instances on nat *) (********************) (******************************************************************************) (* This is an example of creation of multiple instances on the same type, *) (* with distinct displays, using natural numbers. *) (* We declare two distinct canonical orders: *) (* - leq which is total, and where meet and join are minn and maxn, on nat *) (* - dvdn which is partial, and where meet and join are gcdn and lcmn, *) (* on natdvd *) (******************************************************************************) (******************************************************************************) (* The Module NatOrder defines leq as the canonical order on the type nat, *) (* i.e., without creating an alias. We define and use nat_display and proceed *) (* like a standard canonical structure declaration, except that we use this *) (* display. We also use a single factory LeOrderMixin to instantiate three *) (* different canonical declarations porderType, distrLatticeType, orderType. *) (* We finish by providing theorems to convert the operations of ordered and *) (* lattice types to their definition without structure abstraction. *) (******************************************************************************) Module NatOrder. Section NatOrder. Fact nat_display : disp_t. Proof. exact. Qed. Lemma ltn_def x y : (x < y)%N = (x <= y)%N && ~~ (y <= x)%N. Proof. by rewrite -ltnNge andbC; case: (ltnP x y) => //= /ltnW. Qed. #[export] HB.instance Definition _ := isPreorder.Build nat_display nat ltn_def leqnn leq_trans. #[export] HB.instance Definition _ := hasBottom.Build nat_display nat leq0n. Lemma leEnat : le = leq. Proof. by []. Qed. Lemma ltEnat : lt = ltn. Proof. by []. Qed. Lemma minEnat : min = minn. Proof. by []. Qed. Lemma maxEnat : max = maxn. Proof. by []. Qed. Lemma botEnat : \bot = 0%N :> nat. Proof. by []. Qed. End NatOrder. Module Exports. HB.reexport NatOrder. Definition leEnat := leEnat. Definition ltEnat := ltEnat. Definition minEnat := minEnat. Definition maxEnat := maxEnat. Definition botEnat := botEnat. End Exports. End NatOrder. HB.export NatOrder.Exports. Module NatMonotonyTheory. Section NatMonotonyTheory. Context {disp : disp_t} {T : preorderType disp}. Variables (D : {pred nat}) (f : nat -> T). Hypothesis Dconvex : {in D &, forall i j k, i < k < j -> k \in D}. Lemma homo_ltn_lt_in : {in D, forall i, i.+1 \in D -> f i < f i.+1} -> {in D &, {homo f : i j / i < j}}. Proof. by apply: homo_ltn_in Dconvex; apply: lt_trans. Qed. Lemma nondecn_inP : {in D, forall i, i.+1 \in D -> f i <= f i.+1} -> {in D &, {homo f : i j / i <= j}}. Proof. by apply: homo_leq_in Dconvex => //; apply: le_trans. Qed. Lemma nhomo_ltn_lt_in : {in D, forall i, i.+1 \in D -> f i > f i.+1} -> {in D &, {homo f : i j /~ i < j}}. Proof. move=> f_dec; apply: homo_sym_in. by apply: homo_ltn_in Dconvex f_dec => ? ? ? ? /lt_trans->. Qed. Lemma nonincn_inP : {in D, forall i, i.+1 \in D -> f i >= f i.+1} -> {in D &, {homo f : i j /~ i <= j}}. Proof. move=> /= f_dec; apply: homo_sym_in. by apply: homo_leq_in Dconvex f_dec => //= ? ? ? ? /le_trans->. Qed. Lemma homo_ltn_lt : (forall i, f i < f i.+1) -> {homo f : i j / i < j}. Proof. by apply: homo_ltn; apply: lt_trans. Qed. Lemma nondecnP : (forall i, f i <= f i.+1) -> {homo f : i j / i <= j}. Proof. by apply: homo_leq => //; apply: le_trans. Qed. Lemma nhomo_ltn_lt : (forall i, f i > f i.+1) -> {homo f : i j /~ i < j}. Proof. move=> f_dec; apply: homo_sym. by apply: homo_ltn f_dec => ? ? ? ? /lt_trans->. Qed. Lemma nonincnP : (forall i, f i >= f i.+1) -> {homo f : i j /~ i <= j}. Proof. move=> /= f_dec; apply: homo_sym. by apply: homo_leq f_dec => //= ? ? ? ? /le_trans->. Qed. End NatMonotonyTheory. Arguments homo_ltn_lt_in {disp T} [D f]. Arguments nondecn_inP {disp T} [D f]. Arguments nhomo_ltn_lt_in {disp T} [D f]. Arguments nonincn_inP {disp T} [D f]. Arguments homo_ltn_lt {disp T} [f]. Arguments nondecnP {disp T} [f]. Arguments nhomo_ltn_lt {disp T} [f]. Arguments nonincnP {disp T} [f]. End NatMonotonyTheory. (****************************************************************************) (* The Module DvdSyntax introduces a new set of notations using the newly *) (* created display dvd_display. We first define the display as an opaque *) (* definition of type disp_t, and we use it as the first argument of the *) (* operator which display we want to change from the default one (here le, *) (* lt, dvd sdvd, meet, join, top and bottom, as well as big op notations on *) (* gcd and lcm). This notations will now be used for any ordered type which *) (* first parameter is set to dvd_display. *) (****************************************************************************) Fact dvd_display : disp_t. Proof. exact. Qed. Module DvdSyntax. Notation dvd := (@le dvd_display _). Notation "@ 'dvd' T" := (@le dvd_display T) (at level 10, T at level 8, only parsing) : function_scope. Notation sdvd := (@lt dvd_display _). Notation "@ 'sdvd' T" := (@lt dvd_display T) (at level 10, T at level 8, only parsing) : function_scope. Notation "x %| y" := (dvd x y) : order_scope. Notation "x %<| y" := (sdvd x y) : order_scope. Notation nat0 := (@top dvd_display _). Notation nat1 := (@bottom dvd_display _). End DvdSyntax. (******************************************************************************) (* The Module NatDvd defines dvdn as the canonical order on NatDvd.t, which *) (* is abbreviated using the notation natdvd at the end of the module. *) (* We use the newly defined dvd_display, described above. *) (* We first recover structures that are common to both nat and natdvd *) (* (eqType, choiceType, countType) through the copy mechanism, then we use *) (* a single factory MeetJoinMixin to instantiate both porderType and *) (* distrLatticeType canonical structures, and end with top and bottom. *) (* We finish by providing theorems to convert the operations of ordered and *) (* lattice types to their definition without structure abstraction. *) (******************************************************************************) Module NatDvd. Section NatDvd. Implicit Types (m n p : nat). Definition t := nat. #[export] HB.instance Definition _ := Choice.copy t nat. (* Note that this where the dvd_display is associated with the type NatDvd.t. *) #[export] HB.instance Definition _ := @Le_isPreorder.Build dvd_display t dvdn dvdnn dvdn_trans. (* NatDvd.t is associated below with the notation "natdvd". *) #[export] HB.instance Definition _ := @hasBottom.Build _ t 1 dvd1n. #[export] HB.instance Definition _ := @hasTop.Build _ t 0 dvdn0. Import DvdSyntax. Lemma dvdE : dvd = dvdn :> rel t. Proof. by []. Qed. Lemma nat1E : nat1 = 1%N :> t. Proof. by []. Qed. Lemma nat0E : nat0 = 0%N :> t. Proof. by []. Qed. End NatDvd. Module Exports. HB.reexport NatDvd. Notation natdvd := t. Definition dvdEnat := dvdE. Definition nat1E := nat1E. Definition nat0E := nat0E. End Exports. End NatDvd. HB.export NatDvd.Exports. (************************) (* Instances on ordinal *) (************************) Module OrdinalOrder. Section OrdinalOrder. Fact ord_display : disp_t. Proof. exact. Qed. Section PossiblyTrivial. Context (n : nat). #[export] HB.instance Definition _ := [SubChoice_isSubPreorder of 'I_n by <: with ord_display]. Lemma leEord : (le : rel 'I_n) = leq. Proof. by []. Qed. Lemma ltEord : (lt : rel 'I_n) = (fun m n => m < n)%N. Proof. by []. Qed. End PossiblyTrivial. Section NonTrivial. Context (n' : nat). Let n := n'.+1. #[export] HB.instance Definition _ := @hasBottom.Build _ 'I_n ord0 leq0n. #[export] HB.instance Definition _ := @hasTop.Build _ 'I_n ord_max (@leq_ord _). Lemma botEord : \bot = ord0. Proof. by []. Qed. Lemma topEord : \top = ord_max. Proof. by []. Qed. End NonTrivial. End OrdinalOrder. Module Exports. HB.reexport OrdinalOrder. Definition leEord := leEord. Definition ltEord := ltEord. Definition botEord := botEord. Definition topEord := topEord. End Exports. End OrdinalOrder. HB.export OrdinalOrder.Exports. (*********************) (* Instances on bool *) (*********************) Module BoolOrder. Section BoolOrder. Implicit Types (x y : bool). Fact bool_display : disp_t. Proof. exact. Qed. Fact ltn_def x y : (x < y)%N = (x <= y)%N && ~~ (y <= x)%N. Proof. by case: x y => [] []. Qed. #[export] HB.instance Definition _ := @isPreorder.Build bool_display bool _ _ ltn_def leqnn leq_trans. #[export] HB.instance Definition _ := @hasBottom.Build _ bool false leq0n. #[export] HB.instance Definition _ := @hasTop.Build _ bool true leq_b1. Lemma leEbool : le = (leq : rel bool). Proof. by []. Qed. Lemma ltEbool x y : (x < y) = (x < y)%N. Proof. by []. Qed. End BoolOrder. Module Exports. HB.reexport BoolOrder. Definition leEbool := leEbool. Definition ltEbool := ltEbool. End Exports. End BoolOrder. HB.export BoolOrder.Exports. (******************************) (* Definition of prod_display *) (******************************) Fact prod_display_unit (_ _ : unit) : unit. Proof. exact: tt. Qed. Definition prod_display (displ dispr : disp_t) : disp_t := Disp (prod_display_unit (d1 displ) (d1 dispr)) (prod_display_unit (d2 displ) (d2 dispr)). Fact seqprod_display (disp : disp_t) : disp_t. Proof. exact: disp. Qed. Module Import ProdSyntax. Notation "<=^p%O" := (@le (prod_display _ _) _) : function_scope. Notation ">=^p%O" := (@ge (prod_display _ _) _) : function_scope. Notation ">=^p%O" := (@ge (prod_display _ _) _) : function_scope. Notation "<^p%O" := (@lt (prod_display _ _) _) : function_scope. Notation ">^p%O" := (@gt (prod_display _ _) _) : function_scope. Notation "<?=^p%O" := (@leif (prod_display _ _) _) : function_scope. Notation ">=<^p%O" := (@comparable (prod_display _ _) _) : function_scope. Notation "><^p%O" := (fun x y => ~~ (@comparable (prod_display _ _) _ x y)) : function_scope. Notation "<=^p y" := (>=^p%O y) : order_scope. Notation "<=^p y :> T" := (<=^p (y : T)) (only parsing) : order_scope. Notation ">=^p y" := (<=^p%O y) : order_scope. Notation ">=^p y :> T" := (>=^p (y : T)) (only parsing) : order_scope. Notation "<^p y" := (>^p%O y) : order_scope. Notation "<^p y :> T" := (<^p (y : T)) (only parsing) : order_scope. Notation ">^p y" := (<^p%O y) : order_scope. Notation ">^p y :> T" := (>^p (y : T)) (only parsing) : order_scope. Notation "x <=^p y" := (<=^p%O x y) : order_scope. Notation "x <=^p y :> T" := ((x : T) <=^p (y : T)) (only parsing) : order_scope. Notation "x >=^p y" := (y <=^p x) (only parsing) : order_scope. Notation "x >=^p y :> T" := ((x : T) >=^p (y : T)) (only parsing) : order_scope. Notation "x <^p y" := (<^p%O x y) : order_scope. Notation "x <^p y :> T" := ((x : T) <^p (y : T)) (only parsing) : order_scope. Notation "x >^p y" := (y <^p x) (only parsing) : order_scope. Notation "x >^p y :> T" := ((x : T) >^p (y : T)) (only parsing) : order_scope. Notation "x <=^p y <=^p z" := ((x <=^p y) && (y <=^p z)) : order_scope. Notation "x <^p y <=^p z" := ((x <^p y) && (y <=^p z)) : order_scope. Notation "x <=^p y <^p z" := ((x <=^p y) && (y <^p z)) : order_scope. Notation "x <^p y <^p z" := ((x <^p y) && (y <^p z)) : order_scope. Notation "x <=^p y ?= 'iff' C" := (<?=^p%O x y C) : order_scope. Notation "x <=^p y ?= 'iff' C :> T" := ((x : T) <=^p (y : T) ?= iff C) (only parsing) : order_scope. Notation ">=<^p y" := [pred x | >=<^p%O x y] : order_scope. Notation ">=<^p y :> T" := (>=<^p (y : T)) (only parsing) : order_scope. Notation "x >=<^p y" := (>=<^p%O x y) : order_scope. Notation "><^p y" := [pred x | ~~ (>=<^p%O x y)] : order_scope. Notation "><^p y :> T" := (><^p (y : T)) (only parsing) : order_scope. Notation "x ><^p y" := (~~ (><^p%O x y)) : order_scope. End ProdSyntax. Module Import SeqProdSyntax. Notation "<=^sp%O" := (@le (seqprod_display _) _) : function_scope. Notation ">=^sp%O" := (@ge (seqprod_display _) _) : function_scope. Notation ">=^sp%O" := (@ge (seqprod_display _) _) : function_scope. Notation "<^sp%O" := (@lt (seqprod_display _) _) : function_scope. Notation ">^sp%O" := (@gt (seqprod_display _) _) : function_scope. Notation "<?=^sp%O" := (@leif (seqprod_display _) _) : function_scope. Notation ">=<^sp%O" := (@comparable (seqprod_display _) _) : function_scope. Notation "><^sp%O" := (fun x y => ~~ (@comparable (seqprod_display _) _ x y)) : function_scope. Notation "<=^sp y" := (>=^sp%O y) : order_scope. Notation "<=^sp y :> T" := (<=^sp (y : T)) (only parsing) : order_scope. Notation ">=^sp y" := (<=^sp%O y) : order_scope. Notation ">=^sp y :> T" := (>=^sp (y : T)) (only parsing) : order_scope. Notation "<^sp y" := (>^sp%O y) : order_scope. Notation "<^sp y :> T" := (<^sp (y : T)) (only parsing) : order_scope. Notation ">^sp y" := (<^sp%O y) : order_scope. Notation ">^sp y :> T" := (>^sp (y : T)) (only parsing) : order_scope. Notation "x <=^sp y" := (<=^sp%O x y) : order_scope. Notation "x <=^sp y :> T" := ((x : T) <=^sp (y : T)) (only parsing) : order_scope. Notation "x >=^sp y" := (y <=^sp x) (only parsing) : order_scope. Notation "x >=^sp y :> T" := ((x : T) >=^sp (y : T)) (only parsing) : order_scope. Notation "x <^sp y" := (<^sp%O x y) : order_scope. Notation "x <^sp y :> T" := ((x : T) <^sp (y : T)) (only parsing) : order_scope. Notation "x >^sp y" := (y <^sp x) (only parsing) : order_scope. Notation "x >^sp y :> T" := ((x : T) >^sp (y : T)) (only parsing) : order_scope. Notation "x <=^sp y <=^sp z" := ((x <=^sp y) && (y <=^sp z)) : order_scope. Notation "x <^sp y <=^sp z" := ((x <^sp y) && (y <=^sp z)) : order_scope. Notation "x <=^sp y <^sp z" := ((x <=^sp y) && (y <^sp z)) : order_scope. Notation "x <^sp y <^sp z" := ((x <^sp y) && (y <^sp z)) : order_scope. Notation "x <=^sp y ?= 'iff' C" := (<?=^sp%O x y C) : order_scope. Notation "x <=^sp y ?= 'iff' C :> T" := ((x : T) <=^sp (y : T) ?= iff C) (only parsing) : order_scope. Notation ">=<^sp y" := [pred x | >=<^sp%O x y] : order_scope. Notation ">=<^sp y :> T" := (>=<^sp (y : T)) (only parsing) : order_scope. Notation "x >=<^sp y" := (>=<^sp%O x y) : order_scope. Notation "><^sp y" := [pred x | ~~ (>=<^sp%O x y)] : order_scope. Notation "><^sp y :> T" := (><^sp (y : T)) (only parsing) : order_scope. Notation "x ><^sp y" := (~~ (><^sp%O x y)) : order_scope. End SeqProdSyntax. (******************************) (* Definition of lexi_display *) (******************************) Fact lexi_display (disp _ : disp_t) : disp_t. Proof. exact: disp. Qed. Fact seqlexi_display (disp : disp_t) : disp_t. Proof. exact: disp. Qed. Module Import LexiSyntax. Notation "<=^l%O" := (@le (lexi_display _ _) _) : function_scope. Notation ">=^l%O" := (@ge (lexi_display _ _) _) : function_scope. Notation ">=^l%O" := (@ge (lexi_display _ _) _) : function_scope. Notation "<^l%O" := (@lt (lexi_display _ _) _) : function_scope. Notation ">^l%O" := (@gt (lexi_display _ _) _) : function_scope. Notation "<?=^l%O" := (@leif (lexi_display _ _) _) : function_scope. Notation ">=<^l%O" := (@comparable (lexi_display _ _) _) : function_scope. Notation "><^l%O" := (fun x y => ~~ (@comparable (lexi_display _ _) _ x y)) : function_scope. Notation "<=^l y" := (>=^l%O y) : order_scope. Notation "<=^l y :> T" := (<=^l (y : T)) (only parsing) : order_scope. Notation ">=^l y" := (<=^l%O y) : order_scope. Notation ">=^l y :> T" := (>=^l (y : T)) (only parsing) : order_scope. Notation "<^l y" := (>^l%O y) : order_scope. Notation "<^l y :> T" := (<^l (y : T)) (only parsing) : order_scope. Notation ">^l y" := (<^l%O y) : order_scope. Notation ">^l y :> T" := (>^l (y : T)) (only parsing) : order_scope. Notation "x <=^l y" := (<=^l%O x y) : order_scope. Notation "x <=^l y :> T" := ((x : T) <=^l (y : T)) (only parsing) : order_scope. Notation "x >=^l y" := (y <=^l x) (only parsing) : order_scope. Notation "x >=^l y :> T" := ((x : T) >=^l (y : T)) (only parsing) : order_scope. Notation "x <^l y" := (<^l%O x y) : order_scope. Notation "x <^l y :> T" := ((x : T) <^l (y : T)) (only parsing) : order_scope. Notation "x >^l y" := (y <^l x) (only parsing) : order_scope. Notation "x >^l y :> T" := ((x : T) >^l (y : T)) (only parsing) : order_scope. Notation "x <=^l y <=^l z" := ((x <=^l y) && (y <=^l z)) : order_scope. Notation "x <^l y <=^l z" := ((x <^l y) && (y <=^l z)) : order_scope. Notation "x <=^l y <^l z" := ((x <=^l y) && (y <^l z)) : order_scope. Notation "x <^l y <^l z" := ((x <^l y) && (y <^l z)) : order_scope. Notation "x <=^l y ?= 'iff' C" := (<?=^l%O x y C) : order_scope. Notation "x <=^l y ?= 'iff' C :> T" := ((x : T) <=^l (y : T) ?= iff C) (only parsing) : order_scope. Notation ">=<^l y" := [pred x | >=<^l%O x y] : order_scope. Notation ">=<^l y :> T" := (>=<^l (y : T)) (only parsing) : order_scope. Notation "x >=<^l y" := (>=<^l%O x y) : order_scope. Notation "><^l y" := [pred x | ~~ (>=<^l%O x y)] : order_scope. Notation "><^l y :> T" := (><^l (y : T)) (only parsing) : order_scope. Notation "x ><^l y" := (~~ (><^l%O x y)) : order_scope. End LexiSyntax. Module Import SeqLexiSyntax. Notation "<=^l%O" := (@le (seqlexi_display _ _) _) : function_scope. Notation ">=^l%O" := (@ge (seqlexi_display _ _) _) : function_scope. Notation ">=^l%O" := (@ge (seqlexi_display _ _) _) : function_scope. Notation "<^l%O" := (@lt (seqlexi_display _ _) _) : function_scope. Notation ">^l%O" := (@gt (seqlexi_display _ _) _) : function_scope. Notation "<?=^l%O" := (@leif (seqlexi_display _ _) _) : function_scope. Notation ">=<^l%O" := (@comparable (seqlexi_display _ _) _) : function_scope. Notation "><^l%O" := (fun x y => ~~ (@comparable (seqlexi_display _ _) _ x y)) : function_scope. Notation "<=^l y" := (>=^l%O y) : order_scope. Notation "<=^l y :> T" := (<=^l (y : T)) (only parsing) : order_scope. Notation ">=^l y" := (<=^l%O y) : order_scope. Notation ">=^l y :> T" := (>=^l (y : T)) (only parsing) : order_scope. Notation "<^l y" := (>^l%O y) : order_scope. Notation "<^l y :> T" := (<^l (y : T)) (only parsing) : order_scope. Notation ">^l y" := (<^l%O y) : order_scope. Notation ">^l y :> T" := (>^l (y : T)) (only parsing) : order_scope. Notation "x <=^l y" := (<=^l%O x y) : order_scope. Notation "x <=^l y :> T" := ((x : T) <=^l (y : T)) (only parsing) : order_scope. Notation "x >=^l y" := (y <=^l x) (only parsing) : order_scope. Notation "x >=^l y :> T" := ((x : T) >=^l (y : T)) (only parsing) : order_scope. Notation "x <^l y" := (<^l%O x y) : order_scope. Notation "x <^l y :> T" := ((x : T) <^l (y : T)) (only parsing) : order_scope. Notation "x >^l y" := (y <^l x) (only parsing) : order_scope. Notation "x >^l y :> T" := ((x : T) >^l (y : T)) (only parsing) : order_scope. Notation "x <=^l y <=^l z" := ((x <=^l y) && (y <=^l z)) : order_scope. Notation "x <^l y <=^l z" := ((x <^l y) && (y <=^l z)) : order_scope. Notation "x <=^l y <^l z" := ((x <=^l y) && (y <^l z)) : order_scope. Notation "x <^l y <^l z" := ((x <^l y) && (y <^l z)) : order_scope. Notation "x <=^l y ?= 'iff' C" := (<?=^l%O x y C) : order_scope. Notation "x <=^l y ?= 'iff' C :> T" := ((x : T) <=^l (y : T) ?= iff C) (only parsing) : order_scope. Notation ">=<^l y" := [pred x | >=<^l%O x y] : order_scope. Notation ">=<^l y :> T" := (>=<^l (y : T)) (only parsing) : order_scope. Notation "x >=<^l y" := (>=<^l%O x y) : order_scope. Notation "><^l y" := [pred x | ~~ (>=<^l%O x y)] : order_scope. Notation "><^l y :> T" := (><^l (y : T)) (only parsing) : order_scope. Notation "x ><^l y" := (~~ (><^l%O x y)) : order_scope. End SeqLexiSyntax. (************************************************) (* We declare an alias of the cartesian product *) (* which has canonical product order. *) (************************************************) Module ProdOrder. Local Open Scope type_scope. (* FIXME *) Definition type (disp : disp_t) (T T' : Type) := T * T'. Definition type_ (disp1 disp2 : disp_t) (T : preorderType disp1) (T' : preorderType disp2) := type (prod_display disp1 disp2) T T'. Section Basis. Context {disp : disp_t}. Local Notation "T * T'" := (type disp T T') : type_scope. #[export] HB.instance Definition _ (T T' : eqType) := Equality.on (T * T'). #[export] HB.instance Definition _ (T T' : choiceType) := Choice.on (T * T'). #[export] HB.instance Definition _ (T T' : countType) := Countable.on (T * T'). #[export] HB.instance Definition _ (T T' : finType) := Finite.on (T * T'). End Basis. Section Preorder. Context (disp1 disp2 : disp_t). Context (T1 : preorderType disp1) (T2 : preorderType disp2). Implicit Types (x y : T1 * T2). Let le x y := (x.1 <= y.1) && (x.2 <= y.2). Let lt x y := (x.1 < y.1) && (x.2 <= y.2) || (x.1 <= y.1) && (x.2 < y.2). Fact lt_def x y : lt x y = le x y && ~~ le y x. Proof. rewrite /lt /le !lt_leAnge -andbA -andb_orr. by rewrite [~~ _ && _]andbC -andb_orr andbA negb_and. Qed. Fact refl : reflexive le. Proof. by move=> ?; rewrite /le !lexx. Qed. Fact trans : transitive le. Proof. rewrite /le => y x z /andP [] hxy ? /andP [] /(le_trans hxy) ->. by apply: le_trans. Qed. End Preorder. Section Preorder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : preorderType disp1) (T2 : preorderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := Preorder.on T1'. Let T2' : Type := T2. HB.instance Definition _ := Preorder.on T2'. Definition le x y := (x.1 <= y.1) && (x.2 <= y.2). Definition lt x y := (x.1 < y.1) && (x.2 <= y.2) || (x.1 <= y.1) && (x.2 < y.2). #[export] HB.instance Definition _ := @isDuallyPreorder.Build disp3 (T1 * T2) le lt (@lt_def _ _ T1' T2') (@lt_def _ _ T1^d T2^d) (@refl _ _ T1' T2') (@refl _ _ T1^d T2^d) (@trans _ _ T1' T2') (@trans _ _ T1^d T2^d). Lemma leEprod x y : (x <= y) = (x.1 <= y.1) && (x.2 <= y.2). Proof. by []. Qed. Lemma ltEprod x y : (x < y) = (x.1 < y.1) && (x.2 <= y.2) || (x.1 <= y.1) && (x.2 < y.2). Proof. rewrite lt_leAnge !leEprod negb_and andb_orr andbAC -lt_leAnge -andbA. by rewrite -lt_leAnge. Qed. Lemma le_pair (x1 y1 : T1) (x2 y2 : T2) : (x1, x2) <= (y1, y2) :> T1 * T2 = (x1 <= y1) && (x2 <= y2). Proof. by []. Qed. Lemma lt_pair (x1 y1 : T1) (x2 y2 : T2) : (x1, x2) < (y1, y2) :> T1 * T2 = (x1 < y1) && (x2 <= y2) || (x1 <= y1) && (x2 < y2). Proof. exact/ltEprod. Qed. End Preorder. Section BPreorder. Context (disp1 disp2 : disp_t). Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2). Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope. Implicit Types (x : T1 * T2). Fact le0x x : (\bot, \bot) <= x :> T1 * T2. Proof. by rewrite leEprod !le0x. Qed. End BPreorder. Section BPreorder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Let T1' : Type := T1. HB.instance Definition _ := BPreorder.on T1'. Let T2' : Type := T2. HB.instance Definition _ := BPreorder.on T2'. #[export] HB.instance Definition _ := @hasBottom.Build disp3 (T1 * T2) (\bot, \bot) (@le0x _ _ T1' T2'). Lemma botEprod : \bot = (\bot, \bot) :> T1 * T2. Proof. by []. Qed. End BPreorder. Section TPreorder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : tPreorderType disp1) (T2 : tPreorderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. #[export] HB.instance Definition _ := @hasTop.Build disp3 (T1 * T2) (\top, \top) (@le0x _ _ T1^d T2^d). Lemma topEprod : \top = (\top, \top) :> T1 * T2. Proof. by []. Qed. End TPreorder. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) := Preorder.on (type disp3 T1 T2). (* FIXME: use HB.saturate *) Section FinPreorder. Context (disp1 disp2 disp3 : disp_t). #[export] HB.instance Definition _ (T1 : finPreorderType disp1) (T2 : finPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finBPreorderType disp1) (T2 : finBPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTPreorderType disp1) (T2 : finTPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTBPreorderType disp1) (T2 : finTBPreorderType disp2) := Preorder.on (type disp3 T1 T2). End FinPreorder. Module Exports. HB.reexport ProdOrder. Notation "T *prod[ d ] T'" := (type d T T') (at level 70, d at next level, format "T *prod[ d ] T'") : type_scope. Notation "T *p T'" := (type_ T T') (at level 70, format "T *p T'") : type_scope. Definition leEprod := @leEprod. Definition ltEprod := @ltEprod. Definition le_pair := @le_pair. Definition lt_pair := @lt_pair. Definition botEprod := @botEprod. Definition topEprod := @topEprod. End Exports. End ProdOrder. HB.export ProdOrder.Exports. Module DefaultProdOrder. Section DefaultProdOrder. Context {disp1 disp2 : disp_t}. Let prod T1 T2 := T1 *prod[prod_display disp1 disp2] T2. (* FIXME: Scopes of arguments are broken in several places. *) (* FIXME: Declaring a bunch of copies is still a bit painful. *) HB.instance Definition _ (T : preorderType disp1) (T' : preorderType disp2) := Preorder.copy (T * T')%type (T *p T'). HB.instance Definition _ (T1 : bPreorderType disp1) (T2 : bPreorderType disp2) := BPreorder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tPreorderType disp1) (T2 : tPreorderType disp2) := TPreorder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) := TBPreorder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finPreorderType disp1) (T2 : finPreorderType disp2) := FinPreorder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finBPreorderType disp1) (T2 : finBPreorderType disp2) := FinBPreorder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finTPreorderType disp1) (T2 : finTPreorderType disp2) := FinTPreorder.copy (T1 * T2)%type (prod T1 T2). HB.instance Definition _ (T1 : finTBPreorderType disp1) (T2 : finTBPreorderType disp2) := FinTBPreorder.copy (T1 * T2)%type (prod T1 T2). End DefaultProdOrder. End DefaultProdOrder. (*************************************************) (* We declare an alias of the cartesian product, *) (* which has canonical lexicographic order. *) (*************************************************) Module ProdLexiOrder. Local Open Scope type_scope. (* FIXME *) Definition type (disp : disp_t) (T T' : Type) := T * T'. Definition type_ (disp1 disp2 : disp_t) (T : preorderType disp1) (T' : preorderType disp2) := type (lexi_display disp1 disp2) T T'. Section Basis. Context {disp : disp_t}. Local Notation "T * T'" := (type disp T T') : type_scope. #[export] HB.instance Definition _ (T T' : eqType) := Equality.on (T * T'). #[export] HB.instance Definition _ (T T' : choiceType) := Choice.on (T * T'). #[export] HB.instance Definition _ (T T' : countType) := Countable.on (T * T'). #[export] HB.instance Definition _ (T T' : finType) := Finite.on (T * T'). End Basis. Section Preorder. Context (disp1 disp2 : disp_t). Context (T1 : preorderType disp1) (T2 : preorderType disp2). Implicit Types (x y : T1 * T2). Let le x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 <= y.2)). Let lt x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 < y.2)). Fact refl : reflexive le. Proof. by move=> ?; rewrite /le !lexx. Qed. Fact trans : transitive le. Proof. move=> y x z /andP [hxy /implyP hxy'] /andP [hyz /implyP hyz']. rewrite /le (le_trans hxy) //=; apply/implyP => hzx. by apply/le_trans/hxy'/(le_trans hyz): (hyz' (le_trans hzx hxy)). Qed. Fact lt_le_def x y : lt x y = le x y && ~~ le y x. Proof. rewrite /lt /le; case: x y => [x1 x2] [y1 y2]/=. case/boolP: (x1 <= y1); case/boolP: (y1 <= x1) => //= _ _. exact/lt_le_def. Qed. End Preorder. Section Preorder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : preorderType disp1) (T2 : preorderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Implicit Types (x y : T1 * T2). Let T1' : Type := T1. HB.instance Definition _ := Preorder.on T1'. Let T2' : Type := T2. HB.instance Definition _ := Preorder.on T2'. Definition le x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 <= y.2)). Definition lt x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 < y.2)). #[export] HB.instance Definition _ := @isDuallyPreorder.Build disp3 (T1 * T2) le lt (@lt_le_def _ _ T1' T2') (@lt_le_def _ _ T1^d T2^d) (@refl _ _ T1' T2') (@refl _ _ T1^d T2^d) (@trans _ _ T1' T2') (@trans _ _ T1^d T2^d). Lemma leEprodlexi x y : (x <= y) = (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 <= y.2)). Proof. by []. Qed. Lemma ltEprodlexi x y : (x < y) = (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 < y.2)). Proof. by []. Qed. Lemma lexi_pair (x1 y1 : T1) (x2 y2 : T2) : (x1, x2) <= (y1, y2) :> T1 * T2 = (x1 <= y1) && ((x1 >= y1) ==> (x2 <= y2)). Proof. by []. Qed. Lemma ltxi_pair (x1 y1 : T1) (x2 y2 : T2) : (x1, x2) < (y1, y2) :> T1 * T2 = (x1 <= y1) && ((x1 >= y1) ==> (x2 < y2)). Proof. by []. Qed. End Preorder. Section BPreorder. Context (disp1 disp2 : disp_t). Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2). Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope. Implicit Types (x : T1 * T2). Fact le0x x : (\bot, \bot) <= x :> T1 * T2. Proof. by rewrite leEprodlexi !le0x implybT. Qed. End BPreorder. Section BPreorder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. Let T1' : Type := T1. HB.instance Definition _ := BPreorder.on T1'. Let T2' : Type := T2. HB.instance Definition _ := BPreorder.on T2'. #[export] HB.instance Definition _ := @hasBottom.Build disp3 (T1 * T2) (\bot, \bot) (@le0x _ _ T1' T2'). Lemma botEprodlexi : \bot = (\bot, \bot) :> T1 * T2. Proof. by []. Qed. End BPreorder. Section TPreorder. Context (disp1 disp2 disp3 : disp_t). Context (T1 : tPreorderType disp1) (T2 : tPreorderType disp2). Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope. #[export] HB.instance Definition _ := @hasTop.Build disp3 (T1 * T2) (\top, \top) (@le0x _ _ T1^d T2^d). Lemma topEprodlexi : \top = (\top, \top) :> T1 * T2. Proof. by []. Qed. End TPreorder. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (disp1 disp2 disp3 : disp_t) (T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) := Preorder.on (type disp3 T1 T2). Lemma sub_prod_lexi (disp1 disp2 disp3 disp4 : disp_t) (T1 : preorderType disp1) (T2 : preorderType disp2) : subrel (<=%O : rel (T1 *prod[disp3] T2)) (<=%O : rel (type disp4 T1 T2)). Proof. case=> [x1 x2] [y1 y2]; rewrite leEprod leEprodlexi /= => /andP[] -> ->. exact: implybT. Qed. (* FIXME: use HB.saturate *) Section ProdLexiOrder. Context (disp1 disp2 disp3 : disp_t). #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (T1 : bPreorderType disp1) (T2 : bPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (T1 : tPreorderType disp1) (T2 : tPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finPreorderType disp1) (T2 : finPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finBPreorderType disp1) (T2 : finBPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTPreorderType disp1) (T2 : finTPreorderType disp2) := Preorder.on (type disp3 T1 T2). #[export] HB.instance Definition _ (T1 : finTBPreorderType disp1) (T2 : finTBPreorderType disp2) := Preorder.on (type disp3 T1 T2). End ProdLexiOrder. Module Exports. HB.reexport ProdLexiOrder. Notation "T *lexi[ d ] T'" := (type d T T') (at level 70, d at next level, format "T *lexi[ d ] T'") : type_scope. Notation "T *l T'" := (type_ T T') (at level 70, format "T *l T'") : type_scope. Definition leEprodlexi := @leEprodlexi. Definition ltEprodlexi := @ltEprodlexi. Definition lexi_pair := @lexi_pair. Definition ltxi_pair := @ltxi_pair. Definition topEprodlexi := @topEprodlexi. Definition botEprodlexi := @botEprodlexi. Definition sub_prod_lexi := @sub_prod_lexi. End Exports. End ProdLexiOrder. HB.export ProdLexiOrder.Exports. Module DefaultProdLexiOrder. Section DefaultProdLexiOrder. Context {disp1 disp2 : disp_t}. Let prodlexi T1 T2 := T1 *lexi[lexi_display disp1 disp2] T2. (* FIXME: Scopes of arguments are broken in several places. *) (* FIXME: Declaring a bunch of copies is still a bit painful. *) HB.instance Definition _ (T1 : preorderType disp1) (T2 : preorderType disp2) := Preorder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : bPreorderType disp1) (T2 : bPreorderType disp2) := BPreorder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : tPreorderType disp1) (T2 : tPreorderType disp2) := TPreorder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) := TBPreorder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finPreorderType disp1) (T2 : finPreorderType disp2) := FinPreorder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finBPreorderType disp1) (T2 : finBPreorderType disp2) := FinBPreorder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finTPreorderType disp1) (T2 : finTPreorderType disp2) := FinTPreorder.copy (T1 * T2)%type (prodlexi T1 T2). HB.instance Definition _ (T1 : finTBPreorderType disp1) (T2 : finTBPreorderType disp2) := FinTBPreorder.copy (T1 * T2)%type (prodlexi T1 T2). End DefaultProdLexiOrder. End DefaultProdLexiOrder. (*****************************************) (* We declare an alias of the sequences, *) (* which has canonical product order. *) (*****************************************) Module SeqProdOrder. Section SeqProdOrder. Definition type (disp : disp_t) T := seq T. Definition type_ (disp : disp_t) (T : preorderType disp) := type (seqprod_display disp) T. Context {disp disp' : disp_t}. Local Notation seq := (type disp'). #[export] HB.instance Definition _ (T : eqType) := Equality.on (seq T). #[export] HB.instance Definition _ (T : choiceType) := Choice.on (seq T). #[export] HB.instance Definition _ (T : countType) := Countable.on (seq T). Section Preorder. Context (T : preorderType disp). Implicit Types (s : seq T). Fixpoint le s1 s2 := if s1 isn't x1 :: s1' then true else if s2 isn't x2 :: s2' then false else (x1 <= x2) && le s1' s2'. Fact refl : reflexive le. Proof. by elim=> //= ? ? ?; rewrite !lexx. Qed. Fact trans : transitive le. Proof. elim=> [|y ys ihs] [|x xs] [|z zs] //= /andP[xy xys] /andP[yz yzs]. by rewrite (le_trans xy)// ihs. Qed. #[export] HB.instance Definition _ := isPreorder.Build disp' (seq T) (rrefl _) refl trans. Lemma leEseq s1 s2 : s1 <= s2 = if s1 isn't x1 :: s1' then true else if s2 isn't x2 :: s2' then false else (x1 <= x2) && (s1' <= s2' :> seq _). Proof. by case: s1. Qed. Lemma le0s s : [::] <= s :> seq _. Proof. by []. Qed. Lemma les0 s : s <= [::] = (s == [::]). Proof. by rewrite leEseq. Qed. Lemma le_cons x1 s1 x2 s2 : x1 :: s1 <= x2 :: s2 :> seq _ = (x1 <= x2) && (s1 <= s2). Proof. by []. Qed. #[export] HB.instance Definition _ := hasBottom.Build _ (seq T) le0s. Lemma botEseq : \bot = [::] :> seq T. Proof. by []. Qed. End Preorder. End SeqProdOrder. Module Exports. HB.reexport SeqProdOrder. Notation seqprod_with := type. Notation seqprod := type_. Definition leEseq := @leEseq. Definition le0s := @le0s. Definition les0 := @les0. Definition le_cons := @le_cons. Definition botEseq := @botEseq. End Exports. End SeqProdOrder. HB.export SeqProdOrder.Exports. Module DefaultSeqProdOrder. Section DefaultSeqProdOrder. Context {disp : disp_t}. Notation seqprod := (seqprod_with (seqprod_display disp)). HB.instance Definition _ (T : preorderType disp) := Preorder.copy (seq T) (seqprod T). HB.instance Definition _ (T : preorderType disp) := BPreorder.copy (seq T) (seqprod T). End DefaultSeqProdOrder. End DefaultSeqProdOrder. (*********************************************) (* We declare an alias of the sequences, *) (* which has canonical lexicographic order. *) (*********************************************) Module SeqLexiOrder. Section SeqLexiOrder. Definition type (disp : disp_t) T := seq T. Definition type_ (disp : disp_t) (T : preorderType disp) := type (seqlexi_display disp) T. Context {disp disp' : disp_t}. Local Notation seq := (type disp'). #[export] HB.instance Definition _ (T : eqType) := Equality.on (seq T). #[export] HB.instance Definition _ (T : choiceType) := Choice.on (seq T). #[export] HB.instance Definition _ (T : countType) := Countable.on (seq T). Section Preorder. Context (T : preorderType disp). Implicit Types (s : seq T). Fixpoint le s1 s2 := if s1 isn't x1 :: s1' then true else if s2 isn't x2 :: s2' then false else (x1 <= x2) && ((x1 >= x2) ==> le s1' s2'). Fixpoint lt s1 s2 := if s2 isn't x2 :: s2' then false else if s1 isn't x1 :: s1' then true else (x1 <= x2) && ((x1 >= x2) ==> lt s1' s2'). Fact refl: reflexive le. Proof. by elim => [|x s ih] //=; rewrite lexx. Qed. Fact trans: transitive le. Proof. elim=> [|y sy ihs] [|x sx] [|z sz] //= /andP[] xy /implyP yx /andP[] yz /implyP zy /=. rewrite (le_trans xy yz)/=; apply/implyP => zx. apply/ihs; first exact/yx/(le_trans yz zx). exact/zy/(le_trans zx xy). Qed. Lemma lt_le_def s1 s2 : lt s1 s2 = le s1 s2 && ~~ le s2 s1. Proof. elim: s1 s2 => [|x s1 ihs1] [|y s2]//=; rewrite ihs1. by case: (x <= y); case (y <= x). Qed. #[export] HB.instance Definition _ := isPreorder.Build disp' (seq T) lt_le_def refl trans. Lemma leEseqlexi s1 s2 : s1 <= s2 = if s1 isn't x1 :: s1' then true else if s2 isn't x2 :: s2' then false else (x1 <= x2) && ((x1 >= x2) ==> (s1' <= s2' :> seq T)). Proof. by case: s1. Qed. Lemma ltEseqlexi s1 s2 : s1 < s2 = if s2 isn't x2 :: s2' then false else if s1 isn't x1 :: s1' then true else (x1 <= x2) && ((x1 >= x2) ==> (s1' < s2' :> seq T)). Proof. by case: s1. Qed. Lemma lexi0s s : [::] <= s :> seq T. Proof. by []. Qed. Lemma lexis0 s : s <= [::] = (s == [::]). Proof. by rewrite leEseqlexi. Qed. Lemma ltxi0s s : ([::] < s :> seq T) = (s != [::]). Proof. by case: s. Qed. Lemma ltxis0 s : s < [::] = false. Proof. by rewrite ltEseqlexi. Qed. Lemma lexi_cons x1 s1 x2 s2 : x1 :: s1 <= x2 :: s2 :> seq T = (x1 <= x2) && ((x1 >= x2) ==> (s1 <= s2)). Proof. by []. Qed. Lemma ltxi_cons x1 s1 x2 s2 : x1 :: s1 < x2 :: s2 :> seq T = (x1 <= x2) && ((x1 >= x2) ==> (s1 < s2)). Proof. by []. Qed. Lemma lexi_lehead x s1 y s2 : x :: s1 <= y :: s2 :> seq T -> x <= y. Proof. by rewrite lexi_cons => /andP[]. Qed. Lemma ltxi_lehead x s1 y s2 : x :: s1 < y :: s2 :> seq T -> x <= y. Proof. by rewrite ltxi_cons => /andP[]. Qed. Lemma eqhead_lexiE (x : T) s1 s2 : (x :: s1 <= x :: s2 :> seq _) = (s1 <= s2). Proof. by rewrite lexi_cons lexx. Qed. Lemma eqhead_ltxiE (x : T) s1 s2 : (x :: s1 < x :: s2 :> seq _) = (s1 < s2). Proof. by rewrite ltxi_cons lexx. Qed. #[export] HB.instance Definition _ := hasBottom.Build _ (seq T) lexi0s. End Preorder. Lemma sub_seqprod_lexi d (T : preorderType disp) : subrel (<=%O : rel (seqprod_with d T)) (<=%O : rel (seq T)). Proof. elim=> [|x1 s1 ihs1] [|x2 s2]//=; rewrite le_cons lexi_cons /=. by move=> /andP[-> /ihs1->]; rewrite implybT. Qed. End SeqLexiOrder. Module Exports. HB.reexport SeqLexiOrder. Notation seqlexi_with := type. Notation seqlexi := type_. Definition leEseqlexi := @leEseqlexi. Definition lexi0s := @lexi0s. Definition lexis0 := @lexis0. Definition lexi_cons := @lexi_cons. Definition lexi_lehead := @lexi_lehead. Definition eqhead_lexiE := @eqhead_lexiE. Definition ltEseqltxi := @ltEseqlexi. Definition ltxi0s := @ltxi0s. Definition ltxis0 := @ltxis0. Definition ltxi_cons := @ltxi_cons. Definition ltxi_lehead := @ltxi_lehead. Definition eqhead_ltxiE := @eqhead_ltxiE. Definition sub_seqprod_lexi := @sub_seqprod_lexi. End Exports. End SeqLexiOrder. HB.export SeqLexiOrder.Exports. Module DefaultSeqLexiOrder. Section DefaultSeqLexiOrder. Context {disp : disp_t}. Notation seqlexi := (seqlexi_with (seqlexi_display disp)). HB.instance Definition _ (T : preorderType disp) := Preorder.copy (seq T) (seqlexi T). HB.instance Definition _ (T : preorderType disp) := BPreorder.copy (seq T) (seqlexi T). End DefaultSeqLexiOrder. End DefaultSeqLexiOrder. (***************************************) (* We declare an alias of the tuples, *) (* which has canonical product order. *) (***************************************) Module TupleProdOrder. Import DefaultSeqProdOrder. Section TupleProdOrder. Definition type (disp : disp_t) n T := n.-tuple T. Definition type_ (disp : disp_t) n (T : preorderType disp) := type (seqprod_display disp) n T. Context {disp disp' : disp_t}. Local Notation "n .-tuple" := (type disp' n) : type_scope. Section Basics. Context (n : nat). #[export] HB.instance Definition _ (T : eqType) := Equality.on (n.-tuple T). #[export] HB.instance Definition _ (T : eqType) := SubEquality.on (n.-tuple T). #[export] HB.instance Definition _ (T : choiceType) := SubChoice.on (n.-tuple T). #[export] HB.instance Definition _ (T : countType) := SubCountable.on (n.-tuple T). #[export] HB.instance Definition _ (T : finType) := SubFinite.on (n.-tuple T). End Basics. Section Preorder. Implicit Types (n : nat) (T : preorderType disp). (* FIXME: this instance should be dualizable, but then we should not depend *) (* on the subtype mechanism, because the pointwise order on seq cannot be the *) (* dual of itself. *) #[export] HB.instance Definition _ n T := [SubChoice_isSubPreorder of n.-tuple T by <: with disp']. Lemma leEtprod n T (t1 t2 : n.-tuple T) : t1 <= t2 = [forall i, tnth t1 i <= tnth t2 i]. Proof. elim: n => [|n IHn] in t1 t2 *. by rewrite tuple0 [t2]tuple0/= lexx; symmetry; apply/forallP => []. case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2]. rewrite [_ <= _]le_cons [t1 <= t2 :> seq _]IHn. apply/idP/forallP => [/andP[lex12 /forallP/= let12 i]|lext12]. by case: (unliftP ord0 i) => [j ->|->]//; rewrite !tnthS. rewrite (lext12 ord0)/=; apply/forallP=> i. by have := lext12 (lift ord0 i); rewrite !tnthS. Qed. Lemma ltEtprod n T (t1 t2 : n.-tuple T) : t1 < t2 = [exists i, tnth t1 i < tnth t2 i] && [forall i, tnth t1 i <= tnth t2 i]. Proof. rewrite lt_leAnge !leEtprod negb_forall andbC. apply/andP/andP => -[] /existsP[x] xlt le; split=> //; apply/existsP; exists x. rewrite lt_leAnge xlt. by move: le => /forallP ->. by move: xlt; rewrite lt_leAnge => /andP[]. Qed. End Preorder. Section BPreorder. Context (n : nat) (T : bPreorderType disp). Implicit Types (t : n.-tuple T). Fact le0x t : [tuple \bot | _ < n] <= t :> n.-tuple T. Proof. by rewrite leEtprod; apply/forallP => i; rewrite tnth_mktuple le0x. Qed. #[export] HB.instance Definition _ := hasBottom.Build _ (n.-tuple T) le0x. Lemma botEtprod : \bot = [tuple \bot | _ < n] :> n.-tuple T. Proof. by []. Qed. End BPreorder. Section TPreorder. Context (n : nat) (T : tPreorderType disp). Implicit Types (t : n.-tuple T). Fact lex1 t : t <= [tuple \top | _ < n] :> n.-tuple T. Proof. by rewrite leEtprod; apply/forallP => i; rewrite tnth_mktuple lex1. Qed. #[export] HB.instance Definition _ := hasTop.Build _ (n.-tuple T) lex1. Lemma topEtprod : \top = [tuple \top | _ < n] :> n.-tuple T. Proof. by []. Qed. End TPreorder. (* FIXME: use HB.saturate *) #[export] HB.instance Definition _ (n : nat) (T : tbPreorderType disp) := Preorder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finPreorderType disp) := Preorder.on (n.-tuple T). #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (n : nat) (T : finPreorderType disp) := Preorder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finBPreorderType disp) := Preorder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTPreorderType disp) := Preorder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : finTBPreorderType disp) := Preorder.on (n.-tuple T). End TupleProdOrder. Module Exports. HB.reexport TupleProdOrder. Notation "n .-tupleprod[ disp ]" := (type disp n) (format "n .-tupleprod[ disp ]") : type_scope. Notation "n .-tupleprod" := (type_ n) (format "n .-tupleprod") : type_scope. Definition leEtprod := @leEtprod. Definition ltEtprod := @ltEtprod. Definition botEtprod := @botEtprod. Definition topEtprod := @topEtprod. End Exports. End TupleProdOrder. HB.export TupleProdOrder.Exports. Module DefaultTupleProdOrder. Section DefaultTupleProdOrder. Context {disp : disp_t}. Notation "n .-tupleprod" := n.-tupleprod[seqprod_display disp]. HB.instance Definition _ n (T : preorderType disp) := Preorder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : bPreorderType disp) := BPreorder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tPreorderType disp) := TPreorder.copy (n.-tuple T) (n.-tupleprod T). HB.instance Definition _ n (T : tbPreorderType disp) := TBPreorder.copy (n.-tuple T) (n.-tupleprod T). End DefaultTupleProdOrder. End DefaultTupleProdOrder. (*********************************************) (* We declare an alias of the tuples, *) (* which has canonical lexicographic order. *) (*********************************************) Module TupleLexiOrder. Section TupleLexiOrder. Import DefaultSeqLexiOrder. Definition type (disp : disp_t) n T := n.-tuple T. Definition type_ (disp : disp_t) n (T : preorderType disp) := type (seqlexi_display disp) n T. Context {disp disp' : disp_t}. Local Notation "n .-tuple" := (type disp' n) : type_scope. Section Basics. Context (n : nat). #[export] HB.instance Definition _ (T : eqType) := Equality.on (n.-tuple T). #[export] HB.instance Definition _ (T : choiceType) := SubChoice.on (n.-tuple T). #[export] HB.instance Definition _ (T : countType) := SubCountable.on (n.-tuple T). #[export] HB.instance Definition _ (T : finType) := SubFinite.on (n.-tuple T). End Basics. Section Preorder. Implicit Types (T : preorderType disp). #[export, warning="-HB.no-new-instance"] HB.instance Definition _ n T := SubChoice.on (n.-tuple T). #[export] HB.instance Definition _ n T := [SubChoice_isSubPreorder of n.-tuple T by <: with disp']. End Preorder. Section BPreorder. Context (n : nat) (T : bPreorderType disp). Implicit Types (t : n.-tuple T). Fact le0x t : [tuple \bot | _ < n] <= t :> n.-tuple T. Proof. by apply: sub_seqprod_lexi; apply: le0x (t : n.-tupleprod T). Qed. #[export] HB.instance Definition _ := hasBottom.Build _ (n.-tuple T) le0x. Lemma botEtlexi : \bot = [tuple \bot | _ < n] :> n.-tuple T. Proof. by []. Qed. End BPreorder. Section TPreorder. Context (n : nat) (T : tPreorderType disp). Implicit Types (t : n.-tuple T). Fact lex1 t : t <= [tuple \top | _ < n]. Proof. by apply: sub_seqprod_lexi; apply: lex1 (t : n.-tupleprod T). Qed. #[export] HB.instance Definition _ := hasTop.Build _ (n.-tuple T) lex1. Lemma topEtlexi : \top = [tuple \top | _ < n] :> n.-tuple T. Proof. by []. Qed. End TPreorder. (* FIXME: use HB.saturate *) #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (n : nat) (T : bPreorderType disp) := Preorder.on (n.-tuple T). #[export, warning="-HB.no-new-instance"] HB.instance Definition _ (n : nat) (T : tPreorderType disp) := Preorder.on (n.-tuple T). #[export] HB.instance Definition _ (n : nat) (T : tbPreorderType disp) := Preorder.on (n.-tuple T). Lemma sub_tprod_lexi d n (T : preorderType disp) : subrel (<=%O : rel (n.-tupleprod[d] T)) (<=%O : rel (n.-tuple T)). Proof. exact: sub_seqprod_lexi. Qed. End TupleLexiOrder. Module Exports. HB.reexport TupleLexiOrder. Notation "n .-tuplelexi[ disp ]" := (type disp n) (format "n .-tuplelexi[ disp ]") : type_scope. Notation "n .-tuplelexi" := (type_ n) (format "n .-tuplelexi") : type_scope. Definition topEtlexi := @topEtlexi. Definition botEtlexi := @botEtlexi. Definition sub_tprod_lexi := @sub_tprod_lexi. End Exports. End TupleLexiOrder. HB.export TupleLexiOrder.Exports. Module DefaultTupleLexiOrder. Section DefaultTupleLexiOrder. Context {disp : disp_t}. Notation "n .-tuplelexi" := n.-tuplelexi[seqlexi_display disp]. HB.instance Definition _ n (T : preorderType disp) := Preorder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : bPreorderType disp) := BPreorder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : tPreorderType disp) := TPreorder.copy (n.-tuple T) (n.-tuplelexi T). HB.instance Definition _ n (T : tbPreorderType disp) := TBPreorder.copy (n.-tuple T) (n.-tuplelexi T). End DefaultTupleLexiOrder. End DefaultTupleLexiOrder. (*********************************************) (* We declare an alias of the sets, *) (* which is canonically ordered by inclusion *) (*********************************************) Module SetSubsetOrder. Section SetSubsetOrder. Fact subset_display : disp_t. Proof. exact. Qed. Definition type (disp : disp_t) (T : finType) := {set T}. Context {disp : disp_t} {T : finType}. Local Notation "{ 'subset' T }" := (type disp T). Implicit Type (A B C : {subset T}). Lemma le_def A B : A \subset B = (A :&: B == A). Proof. exact/setIidPl/eqP. Qed. #[export] HB.instance Definition _ := Choice.on {subset T}. #[export] HB.instance Definition _ := Le_isPreorder.Build disp {subset T} (@subxx _ _) (fun A B => @subset_trans _ B A). #[export] HB.instance Definition _ := hasBottom.Build disp {subset T} (@sub0set _). #[export] HB.instance Definition _ := hasTop.Build disp {subset T} (@subsetT _). Lemma leEsubset A B : (A <= B) = (A \subset B). Proof. by []. Qed. End SetSubsetOrder. Module Exports. Arguments type disp T%_type. Notation "{ 'subset' [ d ] T }" := (type d T) (d at next level, format "{ 'subset' [ d ] T }") : type_scope. Notation "{ 'subset' T }" := {subset[subset_display] T} (format "{ 'subset' T }") : type_scope. HB.reexport. Definition leEsubset := @leEsubset. End Exports. End SetSubsetOrder. Export SetSubsetOrder.Exports. Module DefaultSetSubsetOrder. HB.instance Definition _ (T : finType) := TBPreorder.copy {set T} {subset T}. End DefaultSetSubsetOrder. Notation enum A := (sort <=%O (enum A)). Section Enum. Variables (d : disp_t) (T : finPreorderType d). Lemma cardE (A : {pred T}) : #|A| = size (enum A). Proof. by rewrite size_sort cardE. Qed. Lemma mem_enum (A : {pred T}) : enum A =i A. Proof. by move=> x; rewrite mem_sort mem_enum. Qed. Lemma enum_uniq (A : {pred T}) : uniq (enum A). Proof. by rewrite sort_uniq enum_uniq. Qed. Lemma cardT : #|T| = size (enum T). Proof. by rewrite cardT size_sort. Qed. Lemma enumT : enum T = sort <=%O (Finite.enum T). Proof. by rewrite enumT. Qed. Lemma enum0 : enum (pred0 : {pred T}) = [::]. Proof. by rewrite enum0. Qed. Lemma enum1 (x : T) : enum (pred1 x) = [:: x]. Proof. by rewrite enum1. Qed. Lemma eq_enum (A B : {pred T}) : A =i B -> enum A = enum B. Proof. by move=> /eq_enum->. Qed. Lemma eq_cardT (A : {pred T}) : A =i predT -> #|A| = size (enum T). Proof. by move=> /eq_enum<-; rewrite cardE. Qed. Lemma set_enum (A : {set T}) : [set x in enum A] = A. Proof. by apply/setP => x; rewrite inE mem_enum. Qed. Lemma enum_set0 : enum (set0 : {set T}) = [::]. Proof. by rewrite enum_set0. Qed. Lemma enum_setT : enum [set: T] = sort <=%O (Finite.enum T). Proof. by rewrite enum_setT. Qed. Lemma enum_set1 (a : T) : enum [set a] = [:: a]. Proof. by rewrite enum_set1. Qed. End Enum. Section Ordinal. Import OrdinalOrder.Exports. Lemma enum_ord n : enum 'I_n = fintype.enum 'I_n. Proof. rewrite (sorted_sort le_trans)// -(@sorted_map _ _ (val : 'I_n -> nat))/=. by rewrite val_enum_ord iota_sorted. Qed. Lemma val_enum_ord n : [seq val i | i <- enum 'I_n] = iota 0 n. Proof. by rewrite enum_ord val_enum_ord. Qed. Lemma size_enum_ord n : size (enum 'I_n) = n. Proof. by rewrite -cardE card_ord. Qed. Lemma nth_enum_ord (n : nat) (i0 : 'I_n) (m : nat) : (m < n)%N -> nth i0 (enum 'I_n) m = m :> nat. Proof. by move=> lemn; rewrite enum_ord nth_enum_ord. Qed. Lemma nth_ord_enum (n : nat) (i0 i : 'I_n) : nth i0 (enum 'I_n) i = i. Proof. by rewrite enum_ord nth_ord_enum. Qed. Lemma index_enum_ord (n : nat) (i : 'I_n) : index i (enum 'I_n) = i. Proof. by rewrite enum_ord index_enum_ord. Qed. End Ordinal. Lemma mono_sorted_enum d d' (T : finPreorderType d) (T' : preorderType d') (f : T -> T') : total (<=%O : rel T) -> {mono f : x y / (x <= y)%O} -> sorted <=%O [seq f x | x <- enum T]. Proof. move=> /sort_sorted ss_sorted lef; wlog [x0 x'0] : / (T * T')%type. by case: (enum T) => // x ? => /(_ (x, f x)). rewrite (sorted_pairwise le_trans). apply/(pairwiseP x'0) => i j; rewrite !inE !size_map -!cardT. move=> ilt jlt ij; rewrite !(nth_map x0) -?cardT// lef. by rewrite (sorted_leq_nth le_trans le_refl) ?inE -?cardT// 1?ltnW. Qed. (* This module should be exported on demand, as in module tagnat below *) Module Import EnumVal. Section EnumVal. Import OrdinalOrder.Exports. Variables (d : disp_t) (T : finPreorderType d). Implicit Types (x : T) (A : {pred T}). Definition enum_rank_in x0 A (Ax0 : x0 \in A) x := insubd (Ordinal (@enum_rank_subproof _ x0 A Ax0)) (index x (enum A)). Definition enum_rank x := @enum_rank_in x T (erefl true) x. Definition enum_val A i := nth (@enum_default _ A i) (enum A) i. Prenex Implicits enum_val. Lemma enum_valP A i : @enum_val A i \in A. Proof. suff: enum_val i \in enum A by rewrite mem_enum. by apply: mem_nth; rewrite -cardE. Qed. Lemma enum_val_nth A x i : @enum_val A i = nth x (enum A) i. Proof. by apply: set_nth_default; rewrite cardE in i *. Qed. Lemma nth_enum_rank_in x00 x0 A Ax0 : {in A, cancel (@enum_rank_in x0 A Ax0) (nth x00 (enum A))}. Proof. move=> x Ax; rewrite /= insubdK ?nth_index ?mem_enum //. by rewrite cardE [_ \in _]index_mem mem_enum. Qed. Lemma nth_enum_rank x0 : cancel enum_rank (nth x0 (enum T)). Proof. by move=> x; apply: nth_enum_rank_in. Qed. Lemma enum_rankK_in x0 A Ax0 : {in A, cancel (@enum_rank_in x0 A Ax0) enum_val}. Proof. by move=> x; apply: nth_enum_rank_in. Qed. Lemma enum_rankK : cancel enum_rank enum_val. Proof. by move=> x; apply: enum_rankK_in. Qed. Lemma enum_valK_in x0 A Ax0 : cancel enum_val (@enum_rank_in x0 A Ax0). Proof. move=> x; apply: ord_inj; rewrite insubdK; last first. by rewrite cardE [_ \in _]index_mem mem_nth // -cardE. by rewrite index_uniq ?enum_uniq // -cardE. Qed. Lemma enum_valK : cancel enum_val enum_rank. Proof. by move=> x; apply: enum_valK_in. Qed. Lemma enum_rank_inj : injective enum_rank. Proof. exact: can_inj enum_rankK. Qed. Lemma enum_val_inj A : injective (@enum_val A). Proof. by move=> i; apply: can_inj (enum_valK_in (enum_valP i)) (i). Qed. Lemma enum_val_bij_in x0 A : x0 \in A -> {on A, bijective (@enum_val A)}. Proof. move=> Ax0; exists (enum_rank_in Ax0) => [i _|]; last exact: enum_rankK_in. exact: enum_valK_in. Qed. Lemma eq_enum_rank_in (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) : {in A, enum_rank_in Ax0 =1 enum_rank_in Ay0}. Proof. by move=> x xA; apply: enum_val_inj; rewrite !enum_rankK_in. Qed. Lemma enum_rank_in_inj (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) : {in A &, forall x y, enum_rank_in Ax0 x = enum_rank_in Ay0 y -> x = y}. Proof. by move=> x y xA yA /(congr1 enum_val); rewrite !enum_rankK_in. Qed. Lemma enum_rank_bij : bijective enum_rank. Proof. by move: enum_rankK enum_valK; exists (@enum_val T). Qed. Lemma enum_val_bij : bijective (@enum_val T). Proof. by move: enum_rankK enum_valK; exists enum_rank. Qed. End EnumVal. Arguments enum_val {d T A}. Arguments enum_rank {d T}. End EnumVal. Notation enum_val := enum_val. Notation enum_rank_in := enum_rank_in. Notation enum_rank := enum_rank. Notation enum_valP := enum_valP. Notation enum_val_nth := enum_val_nth. Notation nth_enum_rank_in := nth_enum_rank_in. Notation nth_enum_rank := nth_enum_rank. Notation enum_rankK_in := enum_rankK_in. Notation enum_rankK := enum_rankK. Notation enum_valK_in := enum_valK_in. Notation enum_valK := enum_valK. Notation enum_rank_inj := enum_rank_inj. Notation enum_val_inj := enum_val_inj. Notation enum_val_bij_in := enum_val_bij_in. Notation eq_enum_rank_in := eq_enum_rank_in. Notation enum_rank_in_inj := enum_rank_in_inj. Notation enum_rank_bij := enum_rank_bij. Notation enum_val_bij := enum_val_bij. Module Syntax. Export PreOSyntax. Export DualSyntax. Export DvdSyntax. End Syntax. Module Theory. Export PreorderTheory. Export PreOCoercions. Export BPreorderTheory. Export TPreorderTheory. Export DualPreorder. (* FIXME? *) Export OrderMorphismTheory. Export SubPreorderTheory. End Theory. Module Exports. HB.reexport. End Exports. End Order. Export Order.Exports. Export Order.Syntax. Export Order.Preorder.Exports. Export Order.BPreorder.Exports. Export Order.TPreorder.Exports. Export Order.TBPreorder.Exports. Export Order.FinPreorder.Exports. Export Order.FinBPreorder.Exports. Export Order.FinTPreorder.Exports. Export Order.FinTBPreorder.Exports. (* FIXME: check if covered by Order.Exports *) (* Export Order.NatOrder.Exports. *) (* Export Order.NatMonotonyTheory. *) (* Export Order.NatDvd.Exports. *) (* Export Order.OrdinalOrder.Exports. *) (* Export Order.BoolOrder.Exports. *) (* Export Order.ProdOrder.Exports. *) (* Export Order.SigmaOrder.Exports. *) (* Export Order.ProdLexiOrder.Exports. *) (* Export Order.SeqProdOrder.Exports. *) (* Export Order.SeqLexiOrder.Exports. *) (* Export Order.TupleProdOrder.Exports. *) (* Export Order.TupleLexiOrder.Exports. *) Module DefaultProdOrder := Order.DefaultProdOrder. Module DefaultSeqProdOrder := Order.DefaultSeqProdOrder. Module DefaultTupleProdOrder := Order.DefaultTupleProdOrder. Module DefaultProdLexiOrder := Order.DefaultProdLexiOrder. Module DefaultSeqLexiOrder := Order.DefaultSeqLexiOrder. Module DefaultTupleLexiOrder := Order.DefaultTupleLexiOrder.
sesquilinear.v
From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div. From mathcomp Require Import choice fintype tuple bigop ssralg finset fingroup. From mathcomp Require Import zmodp poly order ssrnum matrix mxalgebra vector. (******************************************************************************) (* Sesquilinear forms *) (* *) (* e_ j := the row matrix with a 1 in column j *) (* M ^ phi := map_mx phi M *) (* Notation in scope sesquilinear_scope. *) (* M ^t phi := (M ^T) ^ phi *) (* Notation in scope sesquilinear_scope. *) (* involutive_rmorphism R == the type of involutive functions *) (* R has type nzRingType. *) (* The HB class is InvolutiveRMorphism. *) (* *) (* {bilinear U -> U' -> V | s & s'} == the type of bilinear forms which are *) (* essentially functions of type U -> U' -> V *) (* U and U' are lmodType's, V is a zmodType, s and *) (* s' are scaling operations of type R -> V -> V. *) (* The HB class is Bilinear. *) (* The factory bilinear_isBilinear provides a way *) (* to instantiate a bilinear form from two *) (* GRing.linear_for proofs. *) (* {bilinear U -> V -> W | s } := {bilinear U -> V -> W | s.1 & s.2} *) (* {bilinear U -> V -> W} := {bilinear U -> V -> W | *:%R & *:%R } *) (* {biscalar U} := {bilinear U -> U -> _ | *%R & *%R } *) (* *) (* applyr f x := f ^~ x with f : U -> U' -> V *) (* form theta M u v == form defined from a matrix M *) (* := (u *m M *m (v ^t theta)) 0 0 *) (* u and v are row vectors, M is a square matrix, *) (* coefficients have type R : fieldType, *) (* theta is a morphism *) (* *) (* {hermitian U for eps & theta} == hermitian/skew-hermitian form *) (* eps is a boolean flag, *) (* (false -> hermitian, true -> skew-hermitian), *) (* theta is a function R -> R (R : nzRingType). *) (* The HB class is Hermitian. *) (* *%R is used as a the first scaling operator. *) (* theta \; *R is used as the second scaling *) (* operation of the bilinear form. *) (* The archetypal case is theta being the complex *) (* conjugate. *) (* *) (* M \is (eps, theta).-sesqui == M is a sesquilinear form *) (* *) (* orthomx theta M B == M-orthogonal complement of B *) (* := kermx (M *m B ^t theta) *) (* M is a square matrix representing a sesquilinear *) (* form, B is a rectangle matrix representing a *) (* subspace *) (* (local notation: B ^_|_) *) (* ortho theta M B == orthomx theta M B with theta a morphism *) (* A '_|_ B := (A%MS <= B^_|_)%MS *) (* This is a local notation. *) (* rad theta M := ortho theta M 1%:M *) (* (local notation: 1%:M^_|_) *) (* *) (* {symmetric U} == symmetric form *) (* := {hermitian U for false & idfun} *) (* {skew_symmetric U} == skew-symmetric form *) (* := {hermitian U for true & idfun} *) (* {hermitian_sym U for theta} := hermitian form using theta (eps = false) *) (* {dot U for theta} == type of positive definite forms *) (* The HB class is Dot. *) (* *) (* is_skew eps theta form := eps = true /\ theta = idfun *) (* is_sym eps theta form := eps = false /\ theta = idfun *) (* is_hermsym eps theta form := eps = false *) (* *) (* ortho_rec s1 s2 := elements of s1 and s2 are pairwise orthogonal *) (* pairwise_orthogonal s == elements of s are pairwise orthogonal and *) (* s does not contain 0 *) (* orthogonal s1 s2 == the inner product of an element of S1 and *) (* an element of S2 is 0 *) (* := ortho_rec s1 s2 *) (* orthonormal s == s is an orthonormal set of unit vectors *) (* *) (* isometry form1 form2 tau == tau is an isometry from form1 to form2 *) (* form1 and form2 are hermitian forms. *) (* {in D, isometry tau, to R} == local notation for now *) (* *) (* orthov (V : {vspace vT}) == the space orthogonal to V *) (* *) (* In the following definitions, we have f : {hermitian vT for eps & theta} *) (* with vT : vectType F (F : fieldType): *) (* nondegenerate f == f is non-degenerated *) (* is_symplectic f == f is a symplectic bilinear form *) (* is_orthogonal f == f is an orthogonal form *) (* is_unitary f == f is a unitary form *) (* *) (* form_of_matrix theta M U V := \tr (U *m M *m (V ^t theta)) *) (* matrix_of_form f := \matrix_(i, j) form 'e_i 'e_j *) (* M \is hermitianmx eps theta == same as M \is (eps, theta).-sesqui *) (* without the constraint that theta is a morphism *) (* *) (* symmetricmx := hermitianmx _ false idfun *) (* skewmx := hermitianmx _ true idfun *) (* hermsymmx := hermitianmx _ false conjC *) (* *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "M ^t phi" (at level 39, left associativity, format "M ^t phi"). Reserved Notation "A ^!" (format "A ^!"). Reserved Notation "A ^_|_" (format "A ^_|_"). Reserved Notation "A ''_|_' B" (at level 69, format "A ''_|_' B"). Reserved Notation "eps_theta .-sesqui" (format "eps_theta .-sesqui"). Local Open Scope ring_scope. Import GRing.Theory Order.Theory Num.Theory. Notation "''e_' j" := (delta_mx 0 j) (format "''e_' j", at level 8, j at level 2) : ring_scope. Declare Scope sesquilinear_scope. Delimit Scope sesquilinear_scope with sesqui. Local Open Scope sesquilinear_scope. Notation "M ^ phi" := (map_mx phi M) : sesquilinear_scope. Notation "M ^t phi" := ((M ^T) ^ phi) : sesquilinear_scope. (* TODO: move? *) Lemma eq_map_mx_id (R : nzRingType) m n (M : 'M[R]_(m, n)) (f : R -> R) : f =1 id -> M ^ f = M. Proof. by move=> /eq_map_mx->; rewrite map_mx_id. Qed. HB.mixin Record isInvolutive (R : nzRingType) (f : R -> R) := { involutive_subproof : involutive f }. (* TODO: move? *) #[short(type="involutive_rmorphism")] HB.structure Definition InvolutiveRMorphism (R : nzRingType) := { f of @GRing.RMorphism R R f & @isInvolutive R f }. Section InvolutiveTheory. Variable R : nzRingType. Let idfunK : involutive (@idfun R). Proof. by []. Qed. HB.instance Definition _ := isInvolutive.Build _ _ idfunK. Lemma rmorphK (f : involutive_rmorphism R) : involutive f. Proof. by move: f => [? [? ? []]]. Qed. End InvolutiveTheory. Definition conjC {C : numClosedFieldType} (c : C) : C := c^*. HB.instance Definition _ (C : numClosedFieldType) := GRing.RMorphism.on (@conjC C). Section conjC_involutive. Variable C : numClosedFieldType. Let conjCfun_involutive : involutive (@conjC C). Proof. exact: conjCK. Qed. HB.instance Definition _ := isInvolutive.Build _ (@conjC C) conjCfun_involutive. End conjC_involutive. Lemma map_mxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) : (A ^ conjC) ^ conjC = A. Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed. (*Structure revop X Y Z (f : Y -> X -> Z) := RevOp { fun_of_revop :> X -> Y -> Z; _ : forall x, f x =1 fun_of_revop^~ x }. Notation "[ 'revop' revop 'of' op ]" := (@RevOp _ _ _ revop op (fun _ _ => erefl)) (format "[ 'revop' revop 'of' op ]") : form_scope.*) HB.mixin Record isBilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) (f : U -> U' -> V) := { zmod_morphisml_subproof : forall u', zmod_morphism (f ^~ u') ; zmod_morphismr_subproof : forall u, zmod_morphism (f u) ; linearl_subproof : forall u', scalable_for s (f ^~ u') ; linearr_subproof : forall u, scalable_for s' (f u) }. #[short(type="bilinear")] HB.structure Definition Bilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) := {f of isBilinear R U U' V s s' f}. Definition bilinear_for (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : GRing.Scale.law R V) (s' : GRing.Scale.law R V) (f : U -> U' -> V) := ((forall u', GRing.linear_for (s : R -> V -> V) (f ^~ u')) * (forall u, GRing.linear_for s' (f u)))%type. HB.factory Record bilinear_isBilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : GRing.Scale.law R V) (s' : GRing.Scale.law R V) (f : U -> U' -> V) := { bilinear_subproof : bilinear_for s s' f }. HB.builders Context R U U' V s s' f of bilinear_isBilinear R U U' V s s' f. HB.instance Definition _ := isBilinear.Build R U U' V s s' f (fun u' => zmod_morphism_linear (bilinear_subproof.1 u')) (fun u => zmod_morphism_linear (bilinear_subproof.2 u)) (fun u' => scalable_linear (bilinear_subproof.1 u')) (fun u => scalable_linear (bilinear_subproof.2 u)). HB.end. Module BilinearExports. Module Bilinear. Section bilinear. Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V). Local Notation bilinear f := (bilinear_for *:%R *:%R f). Local Notation biscalar f := (bilinear_for *%R *%R f). (* Support for right-to-left rewriting with the generic linearZ rule. *) Notation mapUUV := (@Bilinear.type R U U' V s s'). Definition map_class := mapUUV. Definition map_at_left (a : R) := mapUUV. Definition map_at_right (b : R) := mapUUV. Definition map_at_both (a b : R) := mapUUV. Structure map_for_left a s_a := MapForLeft {map_for_left_map : mapUUV; _ : s a = s_a }. Structure map_for_right b s'_b := MapForRight {map_for_right_map : mapUUV; _ : s' b = s'_b }. Structure map_for_both a b s_a s'_b := MapForBoth {map_for_both_map : mapUUV; _ : s a = s_a ; _ : s' b = s'_b }. Definition unify_map_at_left a (f : map_at_left a) := MapForLeft f (erefl (s a)). Definition unify_map_at_right b (f : map_at_right b) := MapForRight f (erefl (s' b)). Definition unify_map_at_both a b (f : map_at_both a b) := MapForBoth f (erefl (s a)) (erefl (s' b)). Structure wrapped := Wrap {unwrap : mapUUV}. Definition wrap (f : map_class) := Wrap f. End bilinear. End Bilinear. Notation "{ 'bilinear' U -> V -> W | s & t }" := (@Bilinear.type _ U%type V%type W%type s t) (U at level 98, V at level 98, W at level 99, format "{ 'bilinear' U -> V -> W | s & t }") : ring_scope. Notation "{ 'bilinear' U -> V -> W | s }" := ({bilinear U -> V -> W | s.1 & s.2}) (U at level 98, V at level 98, W at level 99, format "{ 'bilinear' U -> V -> W | s }") : ring_scope. Notation "{ 'bilinear' U -> V -> W }" := {bilinear U -> V -> W | *:%R & *:%R} (U at level 98, V at level 98, W at level 99, format "{ 'bilinear' U -> V -> W }") : ring_scope. Notation "{ 'biscalar' U }" := {bilinear U%type -> U%type -> _ | *%R & *%R} (format "{ 'biscalar' U }") : ring_scope. End BilinearExports. Export BilinearExports. #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) (f : {bilinear U -> U' -> V | s & s'}) (u : U) := @GRing.isZmodMorphism.Build U' V (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u). #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) (f : @bilinear R U U' V s s') (u : U) := @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u). Section applyr. Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V). Definition applyr_head t (f : U -> U' -> V) u v := let: tt := t in f v u. End applyr. Notation applyr := (applyr_head tt). Coercion Bilinear.map_for_left_map : Bilinear.map_for_left >-> Bilinear.type. Coercion Bilinear.map_for_right_map : Bilinear.map_for_right >-> Bilinear.type. Coercion Bilinear.map_for_both_map : Bilinear.map_for_both >-> Bilinear.type. Coercion Bilinear.unify_map_at_left : Bilinear.map_at_left >-> Bilinear.map_for_left. Coercion Bilinear.unify_map_at_right : Bilinear.map_at_right >-> Bilinear.map_for_right. Coercion Bilinear.unify_map_at_both : Bilinear.map_at_both >-> Bilinear.map_for_both. Canonical Bilinear.unify_map_at_left. Canonical Bilinear.unify_map_at_right. Canonical Bilinear.unify_map_at_both. Coercion Bilinear.unwrap : Bilinear.wrapped >-> Bilinear.type. Coercion Bilinear.wrap : Bilinear.map_class >-> Bilinear.wrapped. Canonical Bilinear.wrap. Section BilinearTheory. Variable R : nzRingType. Section GenericProperties. Variables (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V). Variable f : {bilinear U -> U' -> V | s & s'}. Section GenericPropertiesr. Variable z : U. Lemma linear0r : f z 0 = 0. Proof. by rewrite raddf0. Qed. Lemma linearNr : {morph f z : x / - x}. Proof. exact: raddfN. Qed. Lemma linearDr : {morph f z : x y / x + y}. Proof. exact: raddfD. Qed. Lemma linearBr : {morph f z : x y / x - y}. Proof. exact: raddfB. Qed. Lemma linearMnr n : {morph f z : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma linearMNnr n : {morph f z : x / x *- n}. Proof. exact: raddfMNn. Qed. Lemma linear_sumr I r (P : pred I) E : f z (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f z (E i). Proof. exact: raddf_sum. Qed. Lemma linearZr_LR : scalable_for s' (f z). Proof. exact: linearZ_LR. Qed. Lemma linearPr a : {morph f z : u v / a *: u + v >-> s' a u + v}. Proof. exact: linearP. Qed. End GenericPropertiesr. Lemma applyrE x : applyr f x =1 f^~ x. Proof. by []. Qed. Section GenericPropertiesl. Variable z : U'. HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ (applyr f z) (@zmod_morphisml_subproof _ _ _ _ _ _ f z). HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ (applyr f z) (@linearl_subproof _ _ _ _ _ _ f z). Lemma linear0l : f 0 z = 0. Proof. by rewrite -applyrE raddf0. Qed. Lemma linearNl : {morph f^~ z : x / - x}. Proof. by move=> ?; rewrite -applyrE raddfN. Qed. Lemma linearDl : {morph f^~ z : x y / x + y}. Proof. by move=> ? ?; rewrite -applyrE raddfD. Qed. Lemma linearBl : {morph f^~ z : x y / x - y}. Proof. by move=> ? ?; rewrite -applyrE raddfB. Qed. Lemma linearMnl n : {morph f^~ z : x / x *+ n}. Proof. by move=> ?; rewrite -applyrE raddfMn. Qed. Lemma linearMNnl n : {morph f^~ z : x / x *- n}. Proof. by move=> ?; rewrite -applyrE raddfMNn. Qed. Lemma linear_sumlz I r (P : pred I) E : f (\sum_(i <- r | P i) E i) z = \sum_(i <- r | P i) f (E i) z. Proof. by rewrite -applyrE raddf_sum. Qed. Lemma linearZl_LR : scalable_for s (f ^~ z). Proof. by move=> ? ?; rewrite -applyrE linearZ_LR. Qed. Lemma linearPl a : {morph f^~ z : u v / a *: u + v >-> s a u + v}. Proof. by move=> ? ?; rewrite -applyrE linearP. Qed. End GenericPropertiesl. End GenericProperties. Section BidirectionalLinearZ. Variables (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V). Variables (S : nzRingType) (h : GRing.Scale.law S V) (h' : GRing.Scale.law S V). Lemma linearZl z (c : S) (a : R) (h_c := h c) (f : Bilinear.map_for_left U U' s s' a h_c) u : f (a *: u) z = h_c (Bilinear.wrap f u z). Proof. by rewrite linearZl_LR; case: f => f /= ->. Qed. Lemma linearZr z c' b (h'_c' := h' c') (f : Bilinear.map_for_right U U' s s' b h'_c') u : f z (b *: u) = h'_c' (Bilinear.wrap f z u). Proof. by rewrite linearZr_LR; case: f => f /= ->. Qed. Lemma linearZlr c c' a b (h_c := h c) (h'_c' := h' c') (f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v : f (a *: u) (b *: v) = h_c (h'_c' (Bilinear.wrap f u v)). Proof. by rewrite linearZl_LR linearZ_LR; case: f => f /= -> ->. Qed. Lemma linearZrl c c' a b (h_c := h c) (h'_c' := h' c') (f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v : f (a *: u) (b *: v) = h'_c' (h_c (Bilinear.wrap f u v)). Proof. by rewrite linearZ_LR/= linearZl_LR; case: f => f /= -> ->. Qed. End BidirectionalLinearZ. End BilinearTheory. (* TODO Canonical rev_mulmx (R : nzRingType) m n p := [revop mulmxr of @mulmx R m n p]. *) (*Canonical mulmx_bilinear (R : comNzRingType) m n p := [bilinear of @mulmx R m n p].*) Lemma mulmx_is_bilinear (R : comNzRingType) m n p : bilinear_for (GRing.Scale.Law.clone _ _ *:%R _) (GRing.Scale.Law.clone _ _ *:%R _) (@mulmx R m n p). Proof. split=> [u'|u] a x y /=. - by rewrite mulmxDl scalemxAl. - by rewrite mulmxDr scalemxAr. Qed. HB.instance Definition _ (R : comNzRingType) m n p := bilinear_isBilinear.Build R [the lmodType R of 'M[R]_(m, n)] [the lmodType R of 'M[R]_(n, p)] [the zmodType of 'M[R]_(m, p)] _ _ (@mulmx R m n p) (mulmx_is_bilinear R m n p). Section BilinearForms. Variables (R : fieldType) (theta : {rmorphism R -> R}). Variables (n : nat) (M : 'M[R]_n). Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n). Definition form u v := (u *m M *m (v ^t theta)) 0 0. Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u] : ring_scope. Lemma form0l u : '[0, u] = 0. Proof. by rewrite /form !mul0mx mxE. Qed. Lemma form0r u : '[u, 0] = 0. Proof. by rewrite /form trmx0 map_mx0 mulmx0 mxE. Qed. Lemma formDl u v w : '[u + v, w] = '[u, w] + '[v, w]. Proof. by rewrite /form !mulmxDl mxE. Qed. Lemma formDr u v w : '[u, v + w] = '[u, v] + '[u, w]. Proof. by rewrite /form linearD !map_mxD !mulmxDr mxE. Qed. Lemma formZr a u v : '[u, a *: v] = theta a * '[u, v]. Proof. by rewrite /form !(linearZ, map_mxZ) /= mxE. Qed. Lemma formZl a u v : '[a *: u, v] = a * '[u, v]. Proof. by do !rewrite /form -[_ *: _ *m _]/(mulmxr _ _) linearZ /=; rewrite mxE. Qed. Lemma formNl u v : '[- u, v] = - '[u, v]. Proof. by rewrite -scaleN1r formZl mulN1r. Qed. Lemma formNr u v : '[u, - v] = - '[u, v]. Proof. by rewrite -scaleN1r formZr rmorphN1 mulN1r. Qed. Lemma formee i j : '['e_i, 'e_j] = M i j. Proof. rewrite /form -rowE -map_trmx map_delta_mx -[M in LHS]trmxK. by rewrite -tr_col -trmx_mul -rowE !mxE. Qed. Lemma form0_eq0 : M = 0 -> forall u v, '[u, v] = 0. Proof. by rewrite/form=> -> u v; rewrite mulmx0 mul0mx mxE. Qed. End BilinearForms. HB.mixin Record isHermitianSesquilinear (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) (f : U -> U -> R) := { hermitian_subproof : forall x y : U, f x y = (-1) ^+ eps * theta (f y x) }. HB.structure Definition Hermitian (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) := {f of @Bilinear R U U _ ( *%R ) (theta \; *%R) f & @isHermitianSesquilinear R U eps theta f}. Notation "{ 'hermitian' U 'for' eps & theta }" := (@Hermitian.type _ U eps theta) (format "{ 'hermitian' U 'for' eps & theta }") : ring_scope. (* duplicate to trick HB *) #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) := @GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u). #[non_forgetful_inheritance] HB.instance Definition _ (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) := @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u). (*Variables (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R). Implicit Types phU : phant U. Local Coercion GRing.Scale.op : GRing.Scale.law >-> Funclass. Definition axiom (f : U -> U -> R) := forall x y : U, f x y = (-1) ^+ eps * theta (f y x). Record class_of (f : U -> U -> R) : Prop := Class { base : Bilinear.class_of ( *%R) (theta \; *%R) f; mixin : axiom f }.*) (*Canonical additiver (u : U) := Additive (base class u). Canonical linearr (u : U) := Linear (base class u). Canonical additivel (u' : U) := @GRing.Additive.Pack _ _ (Phant (U -> R)) (applyr cF u') (Bilinear.basel (base class) u'). Canonical linearl (u' : U) := @GRing.Linear.Pack _ _ _ _ (Phant (U -> R)) (applyr cF u') (Bilinear.basel (base class) u'). Canonical bilinear := @Bilinear.Pack _ _ _ _ _ _ (Phant (U -> U -> R)) cF (base class).*) (*Module Exports. Notation "{ 'hermitian' U 'for' eps & theta }" := (map eps theta (Phant U)) (format "{ 'hermitian' U 'for' eps & theta }") : ring_scope. Coercion base : class_of >-> bilmorphism_for. Coercion apply : map >-> Funclass. Notation "[ 'hermitian' 'of' f 'as' g ]" := (@clone _ _ _ _ _ _ f g _ idfun idfun) (format "[ 'hermitian' 'of' f 'as' g ]") : form_scope. Notation "[ 'hermitian' 'of' f ]" := (@clone _ _ _ _ _ _ f f _ idfun idfun) (format "[ 'hermitian' 'of' f ]") : form_scope. Notation hermitian_for := Hermitian.axiom. Notation Hermitian fM := (pack (Phant _) fM idfun). Canonical additiver. Canonical linearr. Canonical additivel. Canonical linearl. Canonical bilinear. Notation hermapplyr := (@applyr_head _ _ _ _ tt). End Exports. End Hermitian. Include Hermitian.Exports.*) Definition orthomx {R : fieldType} (theta : R -> R) n m M (B : 'M_(m, n)) : 'M_n := kermx (M *m (B ^t theta)). Section Sesquilinear. Variables (R : fieldType) (n : nat). Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n). Section Def. Variable eps_theta : bool * {rmorphism R -> R}. Definition sesqui := [qualify M : 'M_n | M == ((-1) ^+ eps_theta.1) *: M ^t eps_theta.2]. Fact sesqui_key : pred_key sesqui. Proof. by []. Qed. Canonical sesqui_keyed := KeyedQualifier sesqui_key. End Def. Local Notation "eps_theta .-sesqui" := (sesqui eps_theta). Variables (eps : bool) (theta : {rmorphism R -> R}) (M : 'M[R]_n). Local Notation "''[' u , v ]" := (form theta M u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u] : ring_scope. Lemma sesquiE : (M \is (eps, theta).-sesqui) = (M == (-1) ^+ eps *: M ^t theta). Proof. by rewrite qualifE. Qed. Lemma sesquiP : reflect (M = (-1) ^+ eps *: M ^t theta) (M \is (eps, theta).-sesqui). Proof. by rewrite sesquiE; exact/eqP. Qed. Hypotheses (thetaK : involutive theta) (M_sesqui : M \is (eps, theta).-sesqui). Lemma trmx_sesqui : M^T = (-1) ^+ eps *: M ^ theta. Proof. rewrite [in LHS](sesquiP _) // -mul_scalar_mx trmx_mul. by rewrite tr_scalar_mx mul_mx_scalar map_trmx trmxK. Qed. Lemma maptrmx_sesqui : M^t theta = (-1) ^+ eps *: M. Proof. by rewrite trmx_sesqui map_mxZ rmorph_sign -map_mx_comp eq_map_mx_id. Qed. Lemma formC u v : '[u, v] = (-1) ^+ eps * theta '[v, u]. Proof. rewrite /form [M in LHS](sesquiP _) // -mulmxA !mxE rmorph_sum mulr_sumr. apply: eq_bigr => /= i _; rewrite !(mxE, mulr_sumr, mulr_suml, rmorph_sum). apply: eq_bigr => /= j _; rewrite !mxE !rmorphM mulrCA -!mulrA. by congr (_ * _); rewrite mulrA mulrC /= thetaK. Qed. Lemma form_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0). Proof. by rewrite formC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed. Definition ortho m (B : 'M_(m, n)) := orthomx theta M B. Local Notation "B ^_|_" := (ortho B) : ring_scope. Local Notation "A '_|_ B" := (A%MS <= B^_|_)%MS : ring_scope. Lemma normalE u v : (u '_|_ v) = ('[u, v] == 0). Proof. by rewrite (sameP sub_kermxP eqP) mulmxA [_ *m _^t _]mx11_scalar fmorph_eq0. Qed. Lemma form_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v). Proof. by rewrite normalE; apply/eqP. Qed. Lemma normalP p q (A : 'M_(p, n)) (B :'M_(q, n)) : reflect (forall (u v : 'rV_n), (u <= A)%MS -> (v <= B)%MS -> u '_|_ v) (A '_|_ B). Proof. apply: (iffP idP) => AnB. move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //. apply/sub_kermxP; have /submxP [w ->] := vB. rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA. by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx. apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP. suff: forall m (v : 'rV[R]_m), (forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0. apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //. by apply/submxP; exists 'e_i. move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)). rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE. apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK. by rewrite -(map_delta_mx theta) map_trmx Hv. Qed. Lemma normalC p q (A : 'M_(p, n)) (B : 'M_(q, n)) : (A '_|_ B) = (B '_|_ A). Proof. gen have nC : p q A B / A '_|_ B -> B '_|_ A; last by apply/idP/idP; apply/nC. move=> AnB; apply/normalP => u v ? ?; rewrite normalE. rewrite formC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=. by rewrite -normalE (normalP _ _ AnB). Qed. Lemma normal_ortho_mx p (A : 'M_(p, n)) : ((A^_|_) '_|_ A). Proof. by []. Qed. Lemma normal_mx_ortho p (A : 'M_(p, n)) : (A '_|_ (A^_|_)). Proof. by rewrite normalC. Qed. Lemma rank_normal u : (\rank (u ^_|_) >= n.-1)%N. Proof. rewrite mxrank_ker -subn1 leq_sub2l //. by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col. Qed. Definition rad := 1%:M^_|_. Lemma rad_ker : rad = kermx M. Proof. by rewrite /rad /ortho /orthomx trmx1 map_mx1 mulmx1. Qed. (* Pythagoras *) Theorem formDd u v : u '_|_ v -> '[u + v] = '[u] + '[v]. Proof. move=> uNv; rewrite formDl !formDr ['[v, u]]formC. by rewrite ['[u, v]](form_eq0P _) // rmorph0 mulr0 addr0 add0r. Qed. Lemma formZ a u : '[a *: u]= (a * theta a) * '[u]. Proof. by rewrite formZl formZr mulrA. Qed. Lemma formN u : '[- u] = '[u]. Proof. by rewrite formNr formNl opprK. Qed. Lemma form_sign m u : '[(-1) ^+ m *: u] = '[u]. Proof. by rewrite -signr_odd scaler_sign; case: odd; rewrite ?formN. Qed. Lemma formD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d). Proof. by rewrite formDl !formDr ['[v, _]]formC [_ + '[v]]addrC addrACA. Qed. Lemma formB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d). Proof. by rewrite formD formN !formNr rmorphN mulrN -opprD. Qed. Lemma formBd u v : u '_|_ v -> '[u - v] = '[u] + '[v]. Proof. by move=> uTv; rewrite formDd ?formN // normalE formNr oppr_eq0 -normalE. Qed. (* Lemma formJ u v : '[u ^ theta, v ^ theta] = (-1) ^+ eps * theta '[u, v]. *) (* Proof. *) (* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *) (* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *) (* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *) (* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *) (* Lemma formJ u : '[u ^ theta] = (-1) ^+ eps * '[u]. *) (* Proof. *) (* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *) (* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *) (* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *) (* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *) (* rewrite !map_mxM. *) (* rewrite -map_mx_comp eq_map_mx_id //. *) (* !linearZr_LR /=. linearZ. *) (* linearZl. *) (* rewrite trmx_sesqui. *) (* rewrite mapmx. *) (* rewrite map *) (* apply/matrixP. *) (* rewrite formC. *) (* Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed. *) (* Lemma cfCauchySchwarz u v : *) (* `|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free (u :: v). *) (* Proof. *) (* rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. *) (* have [-> | nz_v] /= := altP (v =P 0). *) (* by apply/lerifP; rewrite !cfdot0r normCK mul0r mulr0. *) (* without loss ou: u / '[u, v] = 0. *) (* move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v. *) (* have ou: '[u1, v] = 0. *) (* by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr. *) (* rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //. *) (* rewrite cfdotDl ou add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)). *) (* rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ou mulr0. *) (* by have:= IHo _ ou; rewrite mulrDl -lerif_subLR subrr ou normCK mul0r. *) (* rewrite ou normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0. *) (* rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_v) /=. *) (* apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ou mulr0. *) (* by rewrite cfnorm_eq0 => /eqP->; apply: rpred0. *) (* Qed. *) End Sesquilinear. Notation "eps_theta .-sesqui" := (sesqui _ eps_theta) : ring_scope. Notation symmetric_form := (false, idfun).-sesqui. Notation skew := (true, idfun).-sesqui. Notation hermitian := (false, @Num.conj_op _).-sesqui. HB.mixin Record isDotProduct (R : numDomainType) (U : lmodType R) (op : U -> U -> R) := { neq0_dnorm_gt0 : forall u, u != 0 -> 0 < op u u }. HB.structure Definition Dot (R : numDomainType) (U : lmodType R) (theta : R -> R) := {op of isDotProduct R U op & @Hermitian R U false theta op}. Notation "{ 'dot' U 'for' theta }" := (@Dot.type _ U theta) (format "{ 'dot' U 'for' theta }") : ring_scope. (* duplicate to trick HB *) #[non_forgetful_inheritance] HB.instance Definition _ (R : numDomainType) (U : lmodType R) (theta : R -> R) (f : {dot U for theta}) (u : U) := @GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u). #[non_forgetful_inheritance] HB.instance Definition _ (R : numDomainType) (U : lmodType R) (theta : R -> R) (f : {dot U for theta}) (u : U) := @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u). (*Notation "{ 'dot' U 'for' theta }" := (map theta (Phant U)) (format "{ 'dot' U 'for' theta }") : ring_scope. Coercion base : class_of >-> Hermitian.class_of. Coercion apply : map >-> Funclass. Notation "[ 'dot' 'of' f 'as' g ]" := (@clone _ _ _ _ _ f g _ idfun idfun) (format "[ 'dot' 'of' f 'as' g ]") : form_scope. Notation "[ 'dot' 'of' f ]" := (@clone _ _ _ _ _ f f _ idfun idfun) (format "[ 'dot' 'of' f ]") : form_scope. Notation Dot fM := (pack fM idfun). Notation is_dot := Dot.axiom.*) Notation "{ 'symmetric' U }" := ({hermitian U for false & idfun}) (format "{ 'symmetric' U }") : ring_scope. Notation "{ 'skew_symmetric' U }" := ({hermitian U for true & idfun}) (format "{ 'skew_symmetric' U }") : ring_scope. Notation "{ 'hermitian_sym' U 'for' theta }" := ({hermitian U for false & theta}) (format "{ 'hermitian_sym' U 'for' theta }") : ring_scope. Definition is_skew (R : nzRingType) (eps : bool) (theta : R -> R) (U : lmodType R) (form : {hermitian U for eps & theta}) := (eps = true) /\ (theta =1 id). Definition is_sym (R : nzRingType) (eps : bool) (theta : R -> R) (U : lmodType R) (form : {hermitian U for eps & theta}) := (eps = false) /\ (theta =1 id). Definition is_hermsym (R : nzRingType) (eps : bool) (theta : R -> R) (U : lmodType R) (form : {hermitian U for eps & theta}) := (eps = false). Section HermitianModuleTheory. Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}). Variables (U : lmodType R) (form : {hermitian U for eps & theta}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma hermC u v : '[u, v] = (-1) ^+ eps * theta '[v, u]. Proof. by move: form => [? [[? ? ? ?] []]] /=. Qed. Lemma hnormN u : '[- u] = '[u]. Proof. by rewrite linearNl linearNr opprK. Qed. Lemma hnorm_sign n u : '[(-1) ^+ n *: u] = '[u]. Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?hnormN. Qed. Lemma hnormD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d). Proof. by rewrite /= addrAC -hermC linearDl 2!linearDr !addrA. Qed. Lemma hnormB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d). Proof. by rewrite /= hnormD hnormN linearNr addrA rmorphN mulrN opprD addrA. Qed. Lemma hnormDd u v : '[u, v] = 0 -> '[u + v] = '[u] + '[v]. Proof. by move=> ouv; rewrite hnormD ouv rmorph0 mulr0 !addr0. Qed. Lemma hnormBd u v : '[u, v] = 0 -> '[u - v] = '[u] + '[v]. Proof. by move=> ouv; rewrite hnormDd ?hnormN// linearNr [X in - X]ouv oppr0. Qed. Local Notation "u '_|_ v" := ('[u, v] == 0) : ring_scope. Definition ortho_rec (s1 s2 : seq U) := all [pred u | all [pred v | u '_|_ v] s2] s1. Fixpoint pair_ortho_rec (s : seq U) := if s is v :: s' then ortho_rec [:: v] s' && pair_ortho_rec s' else true. (* We exclude 0 from pairwise orthogonal sets. *) Definition pairwise_orthogonal s := (0 \notin s) && pair_ortho_rec s. Definition orthogonal s1 s2 := (@ortho_rec s1 s2). Arguments orthogonal : simpl never. Lemma orthogonal_cons u us vs : orthogonal (u :: us) vs = orthogonal [:: u] vs && orthogonal us vs. Proof. by rewrite /orthogonal /= andbT. Qed. Definition orthonormal s := all [pred v | '[v] == 1] s && pair_ortho_rec s. Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S. Proof. by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= linear0r eq_sym oner_eq0. Qed. Lemma orthonormalE S : orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S. Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed. Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S. Proof. by rewrite orthonormalE => /andP[_]. Qed. End HermitianModuleTheory. Arguments orthogonal {R eps theta U} form s1 s2. Arguments pairwise_orthogonal {R eps theta U} form s. Arguments orthonormal {R eps theta U} form s. Section HermitianIsometry. Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}). Variables (U1 U2 : lmodType R) (form1 : {hermitian U1 for eps & theta}) (form2 : {hermitian U2 for eps & theta}). Local Notation "''[' u , v ]_1" := (form1 u%R v%R) : ring_scope. Local Notation "''[' u , v ]_2" := (form2 u%R v%R) : ring_scope. Local Notation "''[' u ]_1" := (form1 u%R u%R) : ring_scope. Local Notation "''[' u ]_2" := (form2 u%R u%R): ring_scope. Definition isometry tau := forall u v, form1 (tau u) (tau v) = form2 u%R v%R. Definition isometry_from_to mD tau mR := prop_in2 mD (inPhantom (isometry tau)) /\ prop_in1 mD (inPhantom (forall u, in_mem (tau u) mR)). Local Notation "{ 'in' D , 'isometry' tau , 'to' R }" := (isometry_from_to (mem D) tau (mem R)) (format "{ 'in' D , 'isometry' tau , 'to' R }") : type_scope. End HermitianIsometry. Section HermitianVectTheory. Variables (R : fieldType) (eps : bool) (theta : {rmorphism R -> R}). Variable (U : lmodType R) (form : {hermitian U for eps & theta}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma herm_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0). Proof. by rewrite hermC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed. End HermitianVectTheory. Section HermitianFinVectTheory. Variables (F : fieldType) (eps : bool) (theta : {rmorphism F -> F}). Variables (vT : vectType F) (form : {hermitian vT for eps & theta}). Let n := \dim {:vT}. Implicit Types (u v : vT) (U V : {vspace vT}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Let alpha v := (linfun (applyr form v : vT -> F^o)). Definition orthov V := (\bigcap_(i < \dim V) lker (alpha (vbasis V)`_i))%VS. Local Notation "U '_|_ V" := (U <= orthov V)%VS : vspace_scope. Lemma mem_orthovPn V u : reflect (exists2 v, v \in V & '[u, v] != 0) (u \notin orthov V). Proof. apply: (iffP idP) => [u_orthovV|[v /coord_vbasis-> uvNorthov]]; last first. apply/subv_bigcapP => uP. rewrite linear_sumr big1 ?eqxx//= in uvNorthov. move=> i _; have := uP i isT. by rewrite -memvE memv_ker lfunE/= linearZr/= => /eqP/= ->; rewrite mulr0. suff /existsP [i ui_neq0] : [exists i : 'I_(\dim V), '[u, (vbasis V)`_i] != 0]. by exists (vbasis V)`_i => //; rewrite vbasis_mem ?mem_nth ?size_tuple. apply: contraNT u_orthovV; rewrite negb_exists => /forallP ui_eq0. apply/subv_bigcapP => i _. by rewrite -memvE memv_ker lfunE /= -[_ == _]negbK. Qed. Lemma mem_orthovP V u : reflect {in V, forall v, '[u, v] = 0} (u \in orthov V). Proof. apply: (iffP idP) => [/mem_orthovPn orthovNu v vV|/(_ _ _)/eqP orthov_u]. by apply/eqP/negP=> /negP Northov_uv; apply: orthovNu; exists v. by apply/mem_orthovPn => -[v /orthov_u->]. Qed. Lemma orthov1E u : orthov <[u]> = lker (alpha u). Proof. apply/eqP; rewrite eqEsubv; apply/andP. split; apply/subvP=> v; rewrite memv_ker lfunE /=. by move=> /mem_orthovP-> //; rewrite ?memv_line. move=> vu_eq0; apply/mem_orthovP => w /vlineP[k->]. by apply/eqP; rewrite linearZ mulf_eq0 vu_eq0 orbT. Qed. Lemma orthovP U V : reflect {in U & V, forall u v, '[u, v] = 0} (U '_|_ V)%VS. Proof. apply: (iffP subvP); last by move=> H ??; apply/mem_orthovP=> ??; apply: H. by move=> /(_ _ _)/mem_orthovP; move=> H ????; apply: H. Qed. Lemma orthov_sym U V : (U '_|_ V)%VS = (V '_|_ U)%VS. Proof. by apply/orthovP/orthovP => eq0 ????; apply/eqP; rewrite herm_eq0C eq0. Qed. Lemma mem_orthov1 v u : (u \in orthov <[v]>) = ('[u, v] == 0). Proof. by rewrite orthov1E memv_ker lfunE. Qed. Lemma orthov11 u v : (<[u]> '_|_ <[v]>)%VS = ('[u, v] == 0). Proof. exact: mem_orthov1. Qed. Lemma mem_orthov1_sym v u : (u \in orthov <[v]>) = (v \in orthov <[u]>). Proof. exact: orthov_sym. Qed. Lemma orthov0 : orthov 0 = fullv. Proof. apply/eqP; rewrite eqEsubv subvf. apply/subvP => x _; rewrite mem_orthov1. by rewrite linear0r. Qed. Lemma mem_orthov_sym V u : (u \in orthov V) = (V <= orthov <[u]>)%VS. Proof. exact: orthov_sym. Qed. Lemma leq_dim_orthov1 u V : ((\dim V).-1 <= \dim (V :&: orthov <[u]>))%N. Proof. rewrite -(limg_ker_dim (alpha u) V) -orthov1E. have := dimvS (subvf (alpha u @: V)); rewrite dimvf addnC. by case: (\dim _) => [|[]] // _; rewrite leq_pred. Qed. Lemma dim_img_form_eq1 u V : u \notin orthov V -> \dim (alpha u @: V)%VS = 1%N. Proof. move=> /mem_orthovPn [v vV Northov_uv]; apply/eqP; rewrite eqn_leq /=. rewrite -[1%N as X in (_ <= X)%N](dimvf [the vectType F of F^o]) dimvS ?subvf//=. have := @dimvS _ _ <['[v, u] : F^o]> (alpha u @: V). rewrite -memvE dim_vline herm_eq0C Northov_uv; apply. by apply/memv_imgP; exists v; rewrite ?memvf// !lfunE /=. Qed. Lemma eq_dim_orthov1 u V : u \notin orthov V -> (\dim V).-1 = \dim (V :&: orthov <[u]>). Proof. rewrite -(limg_ker_dim (alpha u) V) => /dim_img_form_eq1->. by rewrite -orthov1E addn1. Qed. Lemma dim_img_form_eq0 u V : u \in orthov V -> \dim (alpha u @: V)%VS = 0%N. Proof. by move=> uV; apply/eqP; rewrite dimv_eq0 -lkerE -orthov1E orthov_sym. Qed. Lemma neq_dim_orthov1 u V : (\dim V > 0)%N -> u \in orthov V -> ((\dim V).-1 < \dim (V :&: orthov <[u]>))%N. Proof. move=> V_gt0; rewrite -(limg_ker_dim (alpha u) V) -orthov1E => u_in. rewrite dim_img_form_eq0 // addn0 (capv_idPl _) 1?orthov_sym //. by case: (\dim _) V_gt0. Qed. Lemma leqif_dim_orthov1 u V : (\dim V > 0)%N -> ((\dim V).-1 <= \dim (V :&: orthov <[u]>) ?= iff (u \notin orthov V))%N. Proof. move=> Vr_gt0; apply/leqifP. by case: (boolP (u \in _)) => /= [/neq_dim_orthov1->|/eq_dim_orthov1->]. Qed. Lemma leqif_dim_orthov1_full u : (n > 0)%N -> ((\dim {:vT}).-1 <= \dim (orthov <[u]>) ?= iff (u \notin orthov fullv))%N. Proof. by move=> n_gt0; have := @leqif_dim_orthov1 u fullv; rewrite capfv; apply. Qed. (* Link between orthov and orthovgonality of sequences *) Lemma orthogonal1P u v : reflect ('[u, v] = 0) (orthogonal form [:: u] [:: v]). Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed. Lemma orthogonalP us vs : reflect {in us & vs, forall u v, '[u, v] = 0} (orthogonal form us vs). Proof. apply: (iffP allP) => ousvs u => [v /ousvs/allP opus /opus/eqP // | /ousvs opus]. by apply/allP=> v /= /opus->. Qed. Lemma orthogonal_oppr S R : orthogonal form S (map -%R R) = orthogonal form S R. Proof. wlog suffices IH: S R / orthogonal form S R -> orthogonal form S (map -%R R). by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK. move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->]. by rewrite linearNr /= oSR ?oppr0. Qed. Lemma orthogonalE us vs : (orthogonal form us vs) = (<<us>> '_|_ <<vs>>)%VS. Proof. apply/orthogonalP/orthovP => uvsP u v; last first. by move=> uus vvs; rewrite uvsP // memv_span. rewrite -[us]in_tupleE -[vs]in_tupleE => /coord_span-> /coord_span->. rewrite linear_sumr big1 //= => i _. rewrite linear_sumlz big1 //= => j _. by rewrite linearZlr/= uvsP ?mulr0// mem_nth. Qed. Lemma orthovE U V : (U '_|_ V)%VS = orthogonal form (vbasis U) (vbasis V). Proof. by rewrite orthogonalE !(span_basis (vbasisP _)). Qed. Notation radv := (orthov fullv). Lemma orthoDv U V W : (U + V '_|_ W)%VS = (U '_|_ W)%VS && (V '_|_ W)%VS. Proof. by rewrite subv_add. Qed. Lemma orthovD U V W : (U '_|_ V + W)%VS = (U '_|_ V)%VS && (U '_|_ W)%VS. Proof. by rewrite ![(U '_|_ _)%VS]orthov_sym orthoDv. Qed. Definition nondegenerate := radv == 0%VS. Definition is_psymplectic := [/\ nondegenerate, is_skew form & 2 \in [pchar F] -> forall u, '[u, u] = 0]. Definition is_porthogonal := [/\ nondegenerate, is_sym form & 2 \in [pchar F] -> forall u, '[u, u] = 0]. Definition is_unitary := nondegenerate /\ (is_hermsym form). End HermitianFinVectTheory. #[deprecated(since="mathcomp 2.4.0", note="Use is_psymplectic instead.")] Notation is_symplectic := is_psymplectic (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use is_porthogonal instead.")] Notation is_orthogonal := is_porthogonal (only parsing). Arguments orthogonalP {F eps theta vT form us vs}. Arguments orthovP {F eps theta vT form U V}. Arguments mem_orthovPn {F eps theta vT form V u}. Arguments mem_orthovP {F eps theta vT form V u}. Section DotVectTheory. Variables (C : numClosedFieldType). Variable (U : lmodType C) (form : {dot U for conjC}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma dnorm_geiff0 u : 0 <= '[u] ?= iff (u == 0). Proof. by apply/leifP; have [->|uN0] := altP eqP; rewrite ?linear0r ?neq0_dnorm_gt0. Qed. Lemma dnorm_ge0 u : 0 <= '[u]. Proof. by rewrite dnorm_geiff0. Qed. Lemma dnorm_eq0 u : ('[u] == 0) = (u == 0). Proof. by rewrite -dnorm_geiff0 eq_sym. Qed. Lemma dnorm_gt0 u : (0 < '[u]) = (u != 0). Proof. by rewrite lt_def dnorm_eq0 dnorm_ge0 andbT. Qed. Lemma sqrt_dnorm_ge0 u : 0 <= sqrtC '[u]. Proof. by rewrite sqrtC_ge0 dnorm_ge0. Qed. Lemma sqrt_dnorm_eq0 u : (sqrtC '[u] == 0) = (u == 0). Proof. by rewrite sqrtC_eq0 dnorm_eq0. Qed. Lemma sqrt_dnorm_gt0 u : (sqrtC '[u] > 0) = (u != 0). Proof. by rewrite sqrtC_gt0 dnorm_gt0. Qed. Lemma dnormZ a u : '[a *: u]= `|a| ^+ 2 * '[u]. Proof. by rewrite linearZl_LR linearZr_LR/= mulrA normCK. Qed. Lemma dnormD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + d^*). Proof. by rewrite hnormD mul1r. Qed. Lemma dnormB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + d^*). Proof. by rewrite hnormB mul1r. Qed. End DotVectTheory. #[global] Hint Extern 0 (is_true (0 <= Dot.sort _ _ _ (* NB: This Hint is assuming ^*, a more precise pattern would be welcome *))) => apply: dnorm_ge0 : core. Section HermitianTheory. Variables (C : numClosedFieldType) (eps : bool) (theta : {rmorphism C -> C}). Variable (U : lmodType C) (form : {dot U for conjC}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma pairwise_orthogonalP S : reflect (uniq (0 :: S) /\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0}) (pairwise_orthogonal form S). Proof. rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case. elim: S notS0 => [|phi S IH] /=; first by left. rewrite inE eq_sym andbT => /norP[nz_phi {}/IH IH]. have [opS | not_opS] := allP; last first. right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=. by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp). rewrite (contra (opS _)) /= ?dnorm_eq0 //. apply: (iffP IH) => [] [uniqS oSS]; last first. by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead. split=> // psi xi; rewrite !inE => /predU1P[-> // | Spsi]. by case/predU1P=> [-> | /opS] /eqP. case/predU1P=> [-> _ | Sxi /oSS-> //]. apply/eqP; rewrite hermC. by move: (opS psi Spsi) => /= /eqP ->; rewrite rmorph0 mulr0. Qed. Lemma pairwise_orthogonal_cat R S : pairwise_orthogonal form (R ++ S) = [&& pairwise_orthogonal form R, pairwise_orthogonal form S & orthogonal form R S]. Proof. rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr. elim: R => [|phi R /= ->]; rewrite ?andbT// all_cat -!andbA /=. by do !bool_congr. Qed. Lemma orthonormal_cat R S : orthonormal form (R ++ S) = [&& orthonormal form R, orthonormal form S & orthogonal form R S]. Proof. rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA. by do !bool_congr. Qed. Lemma orthonormalP S : reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi] = (phi == psi)%:R}) (orthonormal form S). Proof. rewrite orthonormalE; have [/= normS | not_normS] := allP; last first. by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx. apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS]. split=> // [|phi psi]; first by case/andP: uniqS. by have [-> _ /normS/eqP | /oSS] := altP eqP. split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->. by rewrite /= (contra (normS _)) // linear0r eq_sym oner_eq0. Qed. Lemma sub_orthonormal S1 S2 : {subset S1 <= S2} -> uniq S1 -> orthonormal form S2 -> orthonormal form S1. Proof. move=> sS12 uniqS1 /orthonormalP[_ oS1]. by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _. Qed. Lemma orthonormal2P phi psi : reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1] (orthonormal form [:: phi; psi]). Proof. rewrite /orthonormal /= !andbT andbC. by apply: (iffP and3P) => [] []; do 3!move/eqP->. Qed. End HermitianTheory. Section DotFinVectTheory. Variable C : numClosedFieldType. Variables (U : vectType C) (form : {dot U for conjC}). Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma sub_pairwise_orthogonal S1 S2 : {subset S1 <= S2} -> uniq S1 -> pairwise_orthogonal form S2 -> pairwise_orthogonal form S1. Proof. move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2]. apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //. by split=> //; apply: sub_in2 oS2. Qed. Lemma orthogonal_free S : pairwise_orthogonal form S -> free S. Proof. case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS]. rewrite -(in_tupleE S); apply/freeP => a aS0 i. have S_i: S`_i \in S by apply: mem_nth. have /eqP: '[S`_i, 0] = 0 := linear0r _ _. rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first. by rewrite linearZ /= oSS ?mulr0 ?mem_nth // eq_sym nth_uniq. rewrite addr0 linearZ mulf_eq0 conjC_eq0 dnorm_eq0. by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0. Qed. Lemma filter_pairwise_orthogonal S p : pairwise_orthogonal form S -> pairwise_orthogonal form (filter p S). Proof. move=> orthoS; apply: sub_pairwise_orthogonal (orthoS). exact: mem_subseq (filter_subseq p S). exact/filter_uniq/free_uniq/orthogonal_free. Qed. Lemma orthonormal_free S : orthonormal form S -> free S. Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed. Theorem CauchySchwarz (u v : U) : `|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free [:: u; v]. Proof. rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. have [-> | nz_v] /= := altP (v =P 0). by apply/leifP; rewrite /= !linear0r normCK mul0r mulr0. without loss ou: u / '[u, v] = 0. move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v. have ou: '[u1, v] = 0. rewrite linearBl/=. rewrite linearZl_LR. by rewrite divfK ?dnorm_eq0 ?subrr. rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //. rewrite linearDl /= ou add0r. rewrite linearZl_LR/= normrM (ger0_norm (dnorm_ge0 _ _)). rewrite exprMn mulrA -dnormZ hnormDd/=; last by rewrite linearZr_LR/= ou mulr0. have:= IHo _ ou. by rewrite mulrDl -leifBLR subrr ou normCK mul0r. rewrite ou normCK mul0r; split; first by rewrite mulr_ge0. rewrite eq_sym mulf_eq0 orbC dnorm_eq0 (negPf nz_v) /=. apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite linearZr_LR/= ou mulr0. by rewrite dnorm_eq0 => /eqP->; apply: rpred0. Qed. Lemma CauchySchwarz_sqrt u v : `|'[u, v]| <= sqrtC '[u] * sqrtC '[v] ?= iff ~~ free [:: u; v]. Proof. rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?nnegrE//. rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM//= ?nnegrE//=. exact: CauchySchwarz. Qed. Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal form [:: phi] [:: psi]). Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed. Lemma orthoPl phi S : reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal form [:: phi] S). Proof. by rewrite [orthogonal form _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP. Qed. Arguments orthoPl {phi S}. Lemma orthogonal_sym : symmetric (orthogonal form). Proof. apply: symmetric_from_pre => R S /orthogonalP oRS. by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite hermC /= oRS ?rmorph0 ?mulr0. Qed. Lemma orthoPr S psi : reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal form S [:: psi]). Proof. rewrite orthogonal_sym. by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite hermC /= oSpsi //= conjC0 mulr0. Qed. Lemma orthogonal_catl R1 R2 S : orthogonal form (R1 ++ R2) S = orthogonal form R1 S && orthogonal form R2 S. Proof. exact: all_cat. Qed. Lemma orthogonal_catr R S1 S2 : orthogonal form R (S1 ++ S2) = orthogonal form R S1 && orthogonal form R S2. Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed. Lemma eq_pairwise_orthogonal R S : perm_eq R S -> pairwise_orthogonal form R = pairwise_orthogonal form S. Proof. apply: catCA_perm_subst R S => R S S'. rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA. by do !bool_congr. Qed. Lemma eq_orthonormal S0 S : perm_eq S0 S -> orthonormal form S0 = orthonormal form S. Proof. move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)). by rewrite (eq_pairwise_orthogonal eqRS). Qed. Lemma orthogonal_oppl S R : orthogonal form (map -%R S) R = orthogonal form S R. Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed. Lemma triangle_lerif u v : sqrtC '[u + v] <= sqrtC '[u] + sqrtC '[v] ?= iff ~~ free [:: u; v] && (0 <= coord [tuple v] 0 u). Proof. rewrite -(mono_in_leif ler_sqr) ?rpredD ?nnegrE ?sqrtC_ge0//. rewrite andbC sqrrD !sqrtCK addrAC dnormD (mono_leif (lerD2l _))/=. rewrite -mulr_natr -[_ + _](divfK (negbT (pnatr_eq0 C 2))) -/('Re _). rewrite (mono_leif (ler_pM2r _)) ?ltr0n//. have := leif_trans (leif_Re_Creal '[u, v]) (CauchySchwarz_sqrt u v). rewrite ReE; congr (_ <= _ ?= iff _); apply: andb_id2r. rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. have [-> | nz_v] := altP (v =P 0); first by rewrite linear0 coord0. case/vlineP=> [x ->]; rewrite linearZl linearZ/= pmulr_lge0 ?dnorm_gt0 //=. by rewrite (coord_free 0) ?seq1_free // eqxx mulr1. Qed. Lemma span_orthogonal S1 S2 phi1 phi2 : orthogonal form S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS -> '[phi1, phi2] = 0. Proof. move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->. rewrite linear_sumlz big1 // => i _; rewrite linear_sumr big1 // => j _. by rewrite linearZlr/= oS12 ?mem_nth ?mulr0. Qed. Lemma orthogonal_split S beta : {X : U & X \in <<S>>%VS & {Y :U | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal form [:: Y] S]}}. Proof. suffices [X S_X [Y -> oYS]]: {X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal form [:: Y] S}}. - exists X => //; exists Y. by rewrite hermC /= (span_orthogonal oYS) ?memv_span1 ?conjC0 // mulr0. elim: S beta => [|phi S IHS] beta. by exists 0; last exists beta; rewrite ?mem0v ?add0r. have [[UU S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta). pose Z := '[Y, V] / '[V] *: V; exists (X + Z). rewrite /Z -{4}(addKr UU V) scalerDr scalerN addrA addrC span_cons. by rewrite memv_add ?memvB ?memvZ ?memv_line. exists (Y - Z); first by rewrite addrCA !addrA addrK addrC. apply/orthoPl=> psi; rewrite !inE => /predU1P[-> | Spsi]; last first. by rewrite linearBl linearZl_LR /= (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS). rewrite linearBl !linearDr /= (span_orthogonal oYS) // ?memv_span ?mem_head //. rewrite !linearZl_LR /= (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //. have [-> | nzV] := eqVneq V 0; first by rewrite linear0r !mul0r subrr. by rewrite divfK ?dnorm_eq0 ?subrr. Qed. End DotFinVectTheory. Arguments orthoP {C U form phi psi}. Arguments pairwise_orthogonalP {C U form S}. Arguments orthonormalP {C U form S}. Arguments orthoPl {C U form phi S}. Arguments orthoPr {C U form S psi}. Section BuildIsometries. Variables (C : numClosedFieldType) (U U1 U2 : vectType C). Variables (form : {dot U for conjC}) (form1 : {dot U1 for conjC}) (form2 : {dot U2 for conjC}). Definition normf1 := fun u => form1 u u. Definition normf2 := fun u => form2 u u. Lemma isometry_of_dnorm S tauS : pairwise_orthogonal form1 S -> pairwise_orthogonal form2 tauS -> map normf2 tauS = map normf1 S -> {tau : {linear U1 -> U2} | map tau S = tauS & {in <<S>>%VS &, isometry form2 form1 tau}}. Proof. move=> oS oT eq_nST; have freeS := orthogonal_free oS. have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map. have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)). exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=. apply: eq_bigr => i _ /=; rewrite !linearZ/= !linear_sumlz; congr (_ * _). apply: eq_bigr => j _ /=; rewrite linearZ !linearZl; congr (_ * _). rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i. by rewrite /= -[RHS](nth_map 0 0 normf1) -?[LHS](nth_map 0 0 normf2) ?eq_sz // eq_nST. have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS. have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT. by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz. Qed. Lemma isometry_of_free S f : free S -> {in S &, isometry form2 form1 f} -> {tau : {linear U1 -> U2} | {in S, tau =1 f} & {in <<S>>%VS &, isometry form2 form1 tau}}. Proof. move=> freeS If; have defS := free_span freeS. have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S). have {}Dtau: {in S, tau =1 f}. by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau. exists tau => // _ _ /defS[a -> _] /defS[b -> _] /=. rewrite 2!{1}linear_sum /= !{1}linear_sumlz /=; apply/eq_big_seq=> xi1 Sxi1. rewrite !{1}linear_sumr; apply/eq_big_seq=> xi2 Sxi2 /=. by rewrite !linearZ /= !linearZl !Dtau //= If. Qed. Lemma isometry_raddf_inj (tau : {additive U1 -> U2}) : {in U1 &, isometry form2 form1 tau} -> {in U1 &, forall u v, u - v \in U1} -> {in U1 &, injective tau}. Proof. move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB. by rewrite -(dnorm_eq0 form2) Itau ?linU // dnorm_eq0 subr_eq0 => /eqP. Qed. End BuildIsometries. Section MatrixForms. Variables (R : fieldType) (n : nat). Implicit Types (a b : R) (u v : 'rV[R]_n) (M N P Q : 'M[R]_n). Section Def. Variable theta : R -> R. Definition form_of_matrix m M (U V : 'M_(m, n)) := \tr (U *m M *m (V ^t theta)). Definition matrix_of_form (form : 'rV[R]_n -> 'rV[R]_n -> R) : 'M[R]_n := \matrix_(i, j) form 'e_i 'e_j. Implicit Type form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}. Lemma matrix_of_formE form i j : matrix_of_form form i j = form 'e_i 'e_j. Proof. by rewrite mxE. Qed. End Def. Section FormOfMatrix. Variables (m : nat) (M : 'M[R]_n). Implicit Types (U V : 'M[R]_(m, n)). Variables (theta : {rmorphism R -> R}). Local Notation "''[' U , V ]" := (form_of_matrix theta M U%R V%R) : ring_scope. Local Notation "''[' U ]" := '[U, U]%R : ring_scope. Let form_of_matrix_is_linear U : linear_for (theta \; *%R) (form_of_matrix theta M U). Proof. rewrite /form_of_matrix => k v w; rewrite -linearP/=. by rewrite linearP map_mxD map_mxZ !mulmxDr !scalemxAr. Qed. HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _ (form_of_matrix theta M U) (form_of_matrix_is_linear U). Definition form_of_matrixr U := (form_of_matrix theta M)^~U. Let form_of_matrixr_is_linear U : linear_for *%R (form_of_matrixr U). Proof. rewrite /form_of_matrixr /form_of_matrix => k v w. by rewrite -linearP /= !mulmxDl -!scalemxAl. Qed. HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _ (form_of_matrixr U) (form_of_matrixr_is_linear U). (* TODO Canonical form_of_matrixr_rev := [revop form_of_matrixr of form_of_matrix theta M]. *) Lemma form_of_matrix_is_bilinear : bilinear_for (GRing.Scale.Law.clone _ _ ( *%R ) _) (GRing.Scale.Law.clone _ _ (theta \; *%R ) _) (@form_of_matrix theta m M). Proof. split=> [u'|u] a x y /=. - by rewrite /form_of_matrix !mulmxDl linearD/= -!scalemxAl linearZ. - rewrite /form_of_matrix -linearZ/= -linearD/= [in LHS]linearD/= map_mxD. rewrite mulmxDr; congr (\tr (_ + _)). rewrite scalemxAr; congr (_ *m _). by rewrite linearZ/= map_mxZ. Qed. HB.instance Definition _ := bilinear_isBilinear.Build R _ _ _ (GRing.Scale.Law.clone _ _ ( *%R ) _) (GRing.Scale.Law.clone _ _ (theta \; *%R ) _) (@form_of_matrix theta m M) form_of_matrix_is_bilinear. (*Canonical form_of_matrix_is_bilinear := [the @bilinear _ _ _ _ of form_of_matrix theta M].*) End FormOfMatrix. Section FormOfMatrix1. Variables (M : 'M[R]_n). Variables (theta : {rmorphism R -> R}). Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Lemma rV_formee i j : '['e_i :'rV__, 'e_j] = M i j. Proof. rewrite /form_of_matrix -rowE -map_trmx map_delta_mx -[M in LHS]trmxK. by rewrite -tr_col -trmx_mul -rowE trace_mx11 !mxE. Qed. Lemma form_of_matrixK : matrix_of_form (form_of_matrix theta M) = M. Proof. by apply/matrixP => i j; rewrite !mxE rV_formee. Qed. Lemma rV_form0_eq0 : M = 0 -> forall u v, '[u, v] = 0. Proof. by rewrite /form_of_matrix => -> u v; rewrite mulmx0 mul0mx trace_mx11 mxE. Qed. End FormOfMatrix1. Section MatrixOfForm. Variable (theta : {rmorphism R -> R}). Variable form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}. Lemma matrix_of_formK : form_of_matrix theta (matrix_of_form form) =2 form. Proof. set f := (X in X =2 _); have f_eq i j : f 'e_i 'e_j = form 'e_i 'e_j. by rewrite /f rV_formee mxE. move=> u v; rewrite [u]row_sum_delta [v]row_sum_delta /f. rewrite !linear_sum/=; apply: eq_bigr => j _. rewrite !linear_sumlz/=; apply: eq_bigr => i _. by rewrite !linearZlr/= -f_eq. Qed. End MatrixOfForm. Section HermitianMx. Variable eps : bool. Section HermitianMxDef. Variable theta : R -> R. Definition hermitianmx := [qualify M : 'M_n | M == ((-1) ^+ eps) *: M ^t theta]. Fact hermitianmx_key : pred_key hermitianmx. Proof. by []. Qed. Canonical hermitianmx_keyed := KeyedQualifier hermitianmx_key. Structure hermitian_matrix := HermitianMx { mx_of_hermitian :> 'M[R]_n; _ : mx_of_hermitian \is hermitianmx }. Lemma is_hermitianmxE M : (M \is hermitianmx) = (M == (-1) ^+ eps *: M ^t theta). Proof. by rewrite qualifE. Qed. Lemma is_hermitianmxP M : reflect (M = (-1) ^+ eps *: M ^t theta) (M \is hermitianmx). Proof. by rewrite is_hermitianmxE; apply/eqP. Qed. Lemma hermitianmxE (M : hermitian_matrix) : M = ((-1) ^+ eps) *: M ^t theta :> 'M__. Proof. by apply/eqP; case: M. Qed. Lemma trmx_hermitian (M : hermitian_matrix) : M^T = ((-1) ^+ eps) *: M ^ theta :> 'M__. Proof. by rewrite {1}hermitianmxE linearZ /= map_trmx trmxK. Qed. End HermitianMxDef. Section HermitianMxTheory. Variables (theta : involutive_rmorphism R) (M : hermitian_matrix theta). Lemma maptrmx_hermitian : M^t theta = (-1) ^+ eps *: (M : 'M__). Proof. rewrite trmx_hermitian map_mxZ rmorph_sign -map_mx_comp. by rewrite (map_mx_id (rmorphK _)). Qed. Lemma form_of_matrix_is_hermitian m x y : (@form_of_matrix theta m M) x y = (-1) ^+ eps * theta ((@form_of_matrix theta m M) y x). Proof. rewrite {1}hermitianmxE /form_of_matrix. rewrite -!(scalemxAr, scalemxAl) linearZ/=; congr (_ * _). rewrite -mxtrace_tr -trace_map_mx !(trmx_mul, map_mxM, map_trmx, trmxK). by rewrite -mulmxA -!map_mx_comp !(map_mx_id (rmorphK _)). Qed. HB.instance Definition _ m := @isHermitianSesquilinear.Build _ _ _ _ _ (@form_of_matrix_is_hermitian m). Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope. Local Notation "''[' u ]" := '[u, u]%R : ring_scope. Local Notation "B ^!" := (orthomx theta M B) : matrix_set_scope. Local Notation "A '_|_ B" := (A%MS <= B%MS^!)%MS : matrix_set_scope. Lemma orthomxE u v : (u '_|_ v)%MS = ('[u, v] == 0). Proof. rewrite (sameP sub_kermxP eqP) mulmxA. by rewrite [_ *m _^t _]mx11_scalar -trace_mx11 fmorph_eq0. Qed. Lemma hermmx_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v)%MS. Proof. by rewrite orthomxE; apply/eqP. Qed. Lemma orthomxP p q (A : 'M_(p, n)) (B :'M_(q, n)) : reflect (forall (u v : 'rV_n), u <= A -> v <= B -> u '_|_ v)%MS (A '_|_ B)%MS. Proof. apply: (iffP idP) => AnB. move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //. apply/sub_kermxP; have /submxP [w ->] := vB. rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA. by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx. apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP. suff: forall m (v : 'rV[R]_m), (forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0. apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //. by apply/submxP; exists 'e_i. move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)). rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE. apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK. by rewrite -(map_delta_mx theta) map_trmx Hv. Qed. Lemma orthomx_sym p q (A : 'M_(p, n)) (B :'M_(q, n)) : (A '_|_ B)%MS = (B '_|_ A)%MS. Proof. gen have nC : p q A B / (A '_|_ B -> B '_|_ A)%MS; last by apply/idP/idP; apply/nC. move=> AnB; apply/orthomxP => u v ? ?; rewrite orthomxE. rewrite hermC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=. by rewrite -orthomxE (orthomxP _ _ AnB). Qed. Lemma ortho_ortho_mx p (A : 'M_(p, n)) : (A^! '_|_ A)%MS. Proof. by []. Qed. Lemma ortho_mx_ortho p (A : 'M_(p, n)) : (A '_|_ A^!)%MS. Proof. by rewrite orthomx_sym. Qed. Lemma rank_orthomx u : (\rank (u ^!) >= n.-1)%N. Proof. rewrite mxrank_ker -subn1 leq_sub2l //. by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col. Qed. Local Notation radmx := (1%:M^!)%MS. Lemma radmxE : radmx = kermx M. Proof. by rewrite /orthomx /orthomx trmx1 map_mx1 mulmx1. Qed. Lemma orthoNmx k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) : ((- A) '_|_ B)%MS = (A '_|_ B)%MS. Proof. by rewrite eqmx_opp. Qed. Lemma orthomxN k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) : (A '_|_ (- B))%MS = (A '_|_ B)%MS. Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoNmx. Qed. Lemma orthoDmx k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) : (A + B '_|_ C)%MS = (A '_|_ C)%MS && (B '_|_ C)%MS. Proof. by rewrite addsmxE !(sameP sub_kermxP eqP) mul_col_mx col_mx_eq0. Qed. Lemma orthomxD k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) : (A '_|_ B + C)%MS = (A '_|_ B)%MS && (A '_|_ C)%MS. Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoDmx. Qed. Lemma orthoZmx p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 -> (a *: A '_|_ B)%MS = (A '_|_ B)%MS. Proof. by move=> a_neq0; rewrite eqmx_scale. Qed. Lemma orthomxZ p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 -> (A '_|_ (a *: B))%MS = (A '_|_ B)%MS. Proof. by move=> a_neq0; rewrite ![(A '_|_ _)%MS]orthomx_sym orthoZmx. Qed. Lemma eqmx_ortho p m (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : (A :=: B)%MS -> (A^! :=: B^!)%MS. Proof. move=> eqAB; apply/eqmxP. by rewrite orthomx_sym -eqAB ortho_mx_ortho orthomx_sym eqAB ortho_mx_ortho. Qed. Lemma genmx_ortho p (A : 'M[R]_(p, n)) : (<<A>>^! :=: A^!)%MS. Proof. exact: (eqmx_ortho (genmxE _)). Qed. End HermitianMxTheory. End HermitianMx. End MatrixForms. Notation symmetricmx := (hermitianmx _ false idfun). Notation skewmx := (hermitianmx _ true idfun). Notation hermsymmx := (hermitianmx _ false conjC). Lemma hermitian1mx_subproof {C : numClosedFieldType} n : (1%:M : 'M[C]_n) \is hermsymmx. Proof. by rewrite qualifE /= expr0 scale1r tr_scalar_mx map_scalar_mx conjC1. Qed. Canonical hermitian1mx {C : numClosedFieldType} n := HermitianMx (@hermitian1mx_subproof C n).
Density.lean
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym import Mathlib.MeasureTheory.Measure.Haar.OfBasis import Mathlib.Probability.Independence.Basic /-! # Probability density function This file defines the probability density function of random variables, by which we mean measurable functions taking values in a Borel space. The probability density function is defined as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f` is said to the probability density function of a random variable `X` if for all measurable sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing the distribution of a random variable, and are useful for calculating probabilities and finding moments (although the latter is better achieved with moment generating functions). This file also defines the continuous uniform distribution and proves some properties about random variables with this distribution. ## Main definitions * `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`. * `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. * `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform distribution if it has a constant probability density function with a compact, non-null support. ## Main results * `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician, i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for all measurable `g : E → F`. * `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with pdf `f` has expectation `∫ x, x * f x dx`. * `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ` is the Lebesgue measure. ## TODO Ultimately, we would also like to define characteristic functions to describe distributions as it exists for all random variables. However, to define this, we will need Fourier transforms which we currently do not have. -/ open scoped MeasureTheory NNReal ENNReal open TopologicalSpace MeasureTheory.Measure noncomputable section namespace MeasureTheory variable {Ω E : Type*} [MeasurableSpace E] /-- A random variable `X : Ω → E` is said to have a probability density function (`HasPDF`) with respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ` and they have a Lebesgue decomposition (`HaveLebesgueDecomposition`). -/ class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Prop where protected aemeasurable' : AEMeasurable X ℙ protected haveLebesgueDecomposition' : (map X ℙ).HaveLebesgueDecomposition μ protected absolutelyContinuous' : map X ℙ ≪ μ section HasPDF variable {_ : MeasurableSpace Ω} {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E} theorem hasPDF_iff : HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := ⟨fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩, fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩⟩ theorem hasPDF_iff_of_aemeasurable (hX : AEMeasurable X ℙ) : HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by rw [hasPDF_iff] simp only [hX, true_and] variable (X ℙ μ) in @[measurability] theorem HasPDF.aemeasurable [HasPDF X ℙ μ] : AEMeasurable X ℙ := HasPDF.aemeasurable' μ instance HasPDF.haveLebesgueDecomposition [HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ := HasPDF.haveLebesgueDecomposition' theorem HasPDF.absolutelyContinuous [HasPDF X ℙ μ] : map X ℙ ≪ μ := HasPDF.absolutelyContinuous' /-- A random variable that `HasPDF` is quasi-measure preserving. -/ theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E) [HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ := { measurable := h absolutelyContinuous := HasPDF.absolutelyContinuous .. } theorem HasPDF.congr (hXY : X =ᵐ[ℙ] Y) [hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ := ⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition, ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩ theorem HasPDF.congr_iff (hXY : X =ᵐ[ℙ] Y) : HasPDF X ℙ μ ↔ HasPDF Y ℙ μ := ⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩ /-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/ theorem hasPDF_of_map_eq_withDensity (hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ) (h : map X ℙ = μ.withDensity f) : HasPDF X ℙ μ := by refine ⟨hX, ?_, ?_⟩ <;> rw [h] · rw [withDensity_congr_ae hf.ae_eq_mk] exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk · exact withDensity_absolutelyContinuous μ f end HasPDF /-- If `X` is a random variable, then `pdf X ℙ μ` is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. -/ def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : E → ℝ≥0∞ := (map X ℙ).rnDeriv μ theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} : pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by rw [pdf_def, map_of_not_aemeasurable hX] exact rnDeriv_zero μ theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 := rnDeriv_of_not_haveLebesgueDecomposition h theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} (X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by contrapose! h exact pdf_of_not_aemeasurable h theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} (hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by refine ⟨?_, ?_, hac⟩ · exact aemeasurable_of_pdf_ne_zero X hpdf · contrapose! hpdf have := pdf_of_not_haveLebesgueDecomposition hpdf filter_upwards using congrFun this @[measurability] theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by exact measurable_rnDeriv _ _ theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ := withDensity_rnDeriv_le _ _ theorem setLIntegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) (s : Set E) : ∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by apply (withDensity_apply_le _ s).trans exact withDensity_pdf_le_map _ _ _ s theorem map_eq_withDensity_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] : map X ℙ = μ.withDensity (pdf X ℙ μ) := by rw [pdf_def, withDensity_rnDeriv_eq _ _ hX.absolutelyContinuous] theorem map_eq_setLIntegral_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] {s : Set E} (hs : MeasurableSet s) : map X ℙ s = ∫⁻ x in s, pdf X ℙ μ x ∂μ := by rw [← withDensity_apply _ hs, map_eq_withDensity_pdf X ℙ μ] namespace pdf variable {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} protected theorem congr {X Y : Ω → E} (hXY : X =ᵐ[ℙ] Y) : pdf X ℙ μ = pdf Y ℙ μ := by rw [pdf_def, pdf_def, map_congr hXY] theorem lintegral_eq_measure_univ {X : Ω → E} [HasPDF X ℙ μ] : ∫⁻ x, pdf X ℙ μ x ∂μ = ℙ Set.univ := by rw [← setLIntegral_univ, ← map_eq_setLIntegral_pdf X ℙ μ MeasurableSet.univ, map_apply_of_aemeasurable (HasPDF.aemeasurable X ℙ μ) MeasurableSet.univ, Set.preimage_univ] theorem eq_of_map_eq_withDensity [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞) (hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := by rw [map_eq_withDensity_pdf X ℙ μ] apply withDensity_eq_iff (measurable_pdf X ℙ μ).aemeasurable hmf rw [lintegral_eq_measure_univ] exact measure_ne_top _ _ theorem eq_of_map_eq_withDensity' [SigmaFinite μ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞) (hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := map_eq_withDensity_pdf X ℙ μ ▸ withDensity_eq_iff_of_sigmaFinite (measurable_pdf X ℙ μ).aemeasurable hmf nonrec theorem ae_lt_top [IsFiniteMeasure ℙ] {μ : Measure E} {X : Ω → E} : ∀ᵐ x ∂μ, pdf X ℙ μ x < ∞ := rnDeriv_lt_top (map X ℙ) μ nonrec theorem ofReal_toReal_ae_eq [IsFiniteMeasure ℙ] {X : Ω → E} : (fun x => ENNReal.ofReal (pdf X ℙ μ x).toReal) =ᵐ[μ] pdf X ℙ μ := ofReal_toReal_ae_eq ae_lt_top section IntegralPDFMul /-- **The Law of the Unconscious Statistician** for nonnegative random variables. -/ theorem lintegral_pdf_mul {X : Ω → E} [HasPDF X ℙ μ] {f : E → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ x, pdf X ℙ μ x * f x ∂μ = ∫⁻ x, f (X x) ∂ℙ := by rw [pdf_def, ← lintegral_map' (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ), lintegral_rnDeriv_mul HasPDF.absolutelyContinuous hf] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] theorem integrable_pdf_smul_iff [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F} (hf : AEStronglyMeasurable f μ) : Integrable (fun x => (pdf X ℙ μ x).toReal • f x) μ ↔ Integrable (fun x => f (X x)) ℙ := by rw [← Function.comp_def, ← integrable_map_measure (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ), map_eq_withDensity_pdf X ℙ μ, pdf_def, integrable_rnDeriv_smul_iff HasPDF.absolutelyContinuous] rw [withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous] /-- **The Law of the Unconscious Statistician**: Given a random variable `X` and a measurable function `f`, `f ∘ X` is a random variable with expectation `∫ x, pdf X x • f x ∂μ` where `μ` is a measure on the codomain of `X`. -/ theorem integral_pdf_smul [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F} (hf : AEStronglyMeasurable f μ) : ∫ x, (pdf X ℙ μ x).toReal • f x ∂μ = ∫ x, f (X x) ∂ℙ := by rw [← integral_map (HasPDF.aemeasurable X ℙ μ) (hf.mono_ac HasPDF.absolutelyContinuous), map_eq_withDensity_pdf X ℙ μ, pdf_def, integral_rnDeriv_smul HasPDF.absolutelyContinuous, withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous] end IntegralPDFMul section variable {F : Type*} [MeasurableSpace F] {ν : Measure F} (X : Ω → E) [HasPDF X ℙ μ] {g : E → F} /-- A random variable that `HasPDF` transformed under a `QuasiMeasurePreserving` map also `HasPDF` if `(map g (map X ℙ)).HaveLebesgueDecomposition μ`. `quasiMeasurePreserving_hasPDF` is more useful in the case we are working with a probability measure and a real-valued random variable. -/ theorem quasiMeasurePreserving_hasPDF (hg : QuasiMeasurePreserving g μ ν) (hmap : (map g (map X ℙ)).HaveLebesgueDecomposition ν) : HasPDF (g ∘ X) ℙ ν := by have hgm : AEMeasurable g (map X ℙ) := hg.aemeasurable.mono_ac HasPDF.absolutelyContinuous rw [hasPDF_iff, ← AEMeasurable.map_map_of_aemeasurable hgm (HasPDF.aemeasurable X ℙ μ)] refine ⟨hg.measurable.comp_aemeasurable (HasPDF.aemeasurable _ _ μ), hmap, ?_⟩ exact (HasPDF.absolutelyContinuous.map hg.1).trans hg.2 theorem quasiMeasurePreserving_hasPDF' [SFinite ℙ] [SigmaFinite ν] (hg : QuasiMeasurePreserving g μ ν) : HasPDF (g ∘ X) ℙ ν := quasiMeasurePreserving_hasPDF X hg inferInstance end section Real variable {X : Ω → ℝ} nonrec theorem _root_.Real.hasPDF_iff [SFinite ℙ] : HasPDF X ℙ ↔ AEMeasurable X ℙ ∧ map X ℙ ≪ volume := by rw [hasPDF_iff, and_iff_right (inferInstance : HaveLebesgueDecomposition _ _)] /-- A real-valued random variable `X` `HasPDF X ℙ λ` (where `λ` is the Lebesgue measure) if and only if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `λ`. -/ nonrec theorem _root_.Real.hasPDF_iff_of_aemeasurable [SFinite ℙ] (hX : AEMeasurable X ℙ) : HasPDF X ℙ ↔ map X ℙ ≪ volume := by rw [Real.hasPDF_iff, and_iff_right hX] variable [IsFiniteMeasure ℙ] /-- If `X` is a real-valued random variable that has pdf `f`, then the expectation of `X` equals `∫ x, x * f x ∂λ` where `λ` is the Lebesgue measure. -/ theorem integral_mul_eq_integral [HasPDF X ℙ] : ∫ x, x * (pdf X ℙ volume x).toReal = ∫ x, X x ∂ℙ := calc _ = ∫ x, (pdf X ℙ volume x).toReal * x := by congr with x; exact mul_comm _ _ _ = _ := integral_pdf_smul measurable_id.aestronglyMeasurable theorem hasFiniteIntegral_mul {f : ℝ → ℝ} {g : ℝ → ℝ≥0∞} (hg : pdf X ℙ =ᵐ[volume] g) (hgi : ∫⁻ x, ‖f x‖ₑ * g x ≠ ∞) : HasFiniteIntegral fun x => f x * (pdf X ℙ volume x).toReal := by rw [hasFiniteIntegral_iff_enorm] have : (fun x => ‖f x‖ₑ * g x) =ᵐ[volume] fun x => ‖f x * (pdf X ℙ volume x).toReal‖ₑ := by refine ae_eq_trans ((ae_eq_refl _).fun_mul (ae_eq_trans hg.symm ofReal_toReal_ae_eq.symm)) ?_ simp_rw [← smul_eq_mul, enorm_smul, smul_eq_mul] refine .fun_mul (ae_eq_refl _) ?_ simp only [Real.enorm_eq_ofReal ENNReal.toReal_nonneg, ae_eq_refl] rwa [lt_top_iff_ne_top, ← lintegral_congr_ae this] end Real section TwoVariables open ProbabilityTheory variable {F : Type*} [MeasurableSpace F] {ν : Measure F} {X : Ω → E} {Y : Ω → F} /-- Random variables are independent iff their joint density is a product of marginal densities. -/ theorem indepFun_iff_pdf_prod_eq_pdf_mul_pdf [IsFiniteMeasure ℙ] [SigmaFinite μ] [SigmaFinite ν] [HasPDF (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν)] : IndepFun X Y ℙ ↔ pdf (fun ω ↦ (X ω, Y ω)) ℙ (μ.prod ν) =ᵐ[μ.prod ν] fun z ↦ pdf X ℙ μ z.1 * pdf Y ℙ ν z.2 := by have : HasPDF X ℙ μ := quasiMeasurePreserving_hasPDF' (μ := μ.prod ν) (fun ω ↦ (X ω, Y ω)) quasiMeasurePreserving_fst have : HasPDF Y ℙ ν := quasiMeasurePreserving_hasPDF' (μ := μ.prod ν) (fun ω ↦ (X ω, Y ω)) quasiMeasurePreserving_snd have h₀ : (ℙ.map X).prod (ℙ.map Y) = (μ.prod ν).withDensity fun z ↦ pdf X ℙ μ z.1 * pdf Y ℙ ν z.2 := prod_eq fun s t hs ht ↦ by rw [withDensity_apply _ (hs.prod ht), ← prod_restrict, lintegral_prod_mul (measurable_pdf X ℙ μ).aemeasurable (measurable_pdf Y ℙ ν).aemeasurable, map_eq_setLIntegral_pdf X ℙ μ hs, map_eq_setLIntegral_pdf Y ℙ ν ht] rw [indepFun_iff_map_prod_eq_prod_map_map (HasPDF.aemeasurable X ℙ μ) (HasPDF.aemeasurable Y ℙ ν), ← eq_of_map_eq_withDensity, h₀] exact (((measurable_pdf X ℙ μ).comp measurable_fst).mul ((measurable_pdf Y ℙ ν).comp measurable_snd)).aemeasurable end TwoVariables end pdf end MeasureTheory
ZeroLimit.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.LinearAlgebra.LinearIndependent.Basic import Mathlib.Topology.Category.Profinite.Nobeling.Basic /-! # The zero and limit cases in the induction for Nöbeling's theorem This file proves the zero and limit cases of the ordinal induction used in the proof of Nöbeling's theorem. See the section docstrings for more information. For the overall proof outline see `Mathlib/Topology/Category/Profinite/Nobeling/Basic.lean`. ## References - [scholze2019condensed], Theorem 5.4. -/ universe u namespace Profinite.NobelingProof variable {I : Type u} (C : Set (I → Bool)) [LinearOrder I] section Zero /-! ## The zero case of the induction In this case, we have `contained C 0` which means that `C` is either empty or a singleton. -/ instance : Subsingleton (LocallyConstant (∅ : Set (I → Bool)) ℤ) := subsingleton_iff.mpr (fun _ _ ↦ LocallyConstant.ext isEmptyElim) instance : IsEmpty { l // Products.isGood (∅ : Set (I → Bool)) l } := isEmpty_iff.mpr fun ⟨l, hl⟩ ↦ hl <| by rw [subsingleton_iff.mp inferInstance (Products.eval ∅ l) 0] exact Submodule.zero_mem _ theorem GoodProducts.linearIndependentEmpty {I} [LinearOrder I] : LinearIndependent ℤ (eval (∅ : Set (I → Bool))) := linearIndependent_empty_type /-- The empty list as a `Products` -/ def Products.nil : Products I := ⟨[], by simp only [List.chain'_nil]⟩ theorem Products.lt_nil_empty {I} [LinearOrder I] : { m : Products I | m < Products.nil } = ∅ := by ext ⟨m, hm⟩ refine ⟨fun h ↦ ?_, by tauto⟩ simp only [Set.mem_setOf_eq, lt_iff_lex_lt, nil, List.not_lex_nil] at h instance {α : Type*} [TopologicalSpace α] [Nonempty α] : Nontrivial (LocallyConstant α ℤ) := ⟨0, 1, ne_of_apply_ne DFunLike.coe <| (Function.const_injective (β := ℤ)).ne zero_ne_one⟩ theorem Products.isGood_nil {I} [LinearOrder I] : Products.isGood ({fun _ ↦ false} : Set (I → Bool)) Products.nil := by intro h simp [Products.eval, Products.nil] at h theorem Products.span_nil_eq_top {I} [LinearOrder I] : Submodule.span ℤ (eval ({fun _ ↦ false} : Set (I → Bool)) '' {nil}) = ⊤ := by rw [Set.image_singleton, eq_top_iff] intro f _ rw [Submodule.mem_span_singleton] refine ⟨f default, ?_⟩ simp only [eval, List.map, List.prod_nil, zsmul_eq_mul, mul_one, Products.nil] ext x obtain rfl : x = default := by simp only [Set.default_coe_singleton, eq_iff_true_of_subsingleton] rfl /-- There is a unique `GoodProducts` for the singleton `{fun _ ↦ false}`. -/ noncomputable instance : Unique { l // Products.isGood ({fun _ ↦ false} : Set (I → Bool)) l } where default := ⟨Products.nil, Products.isGood_nil⟩ uniq := by intro ⟨⟨l, hl⟩, hll⟩ ext apply Subtype.ext apply (List.lex_nil_or_eq_nil l (r := (· < ·))).resolve_left intro _ apply hll have he : {Products.nil} ⊆ {m | m < ⟨l,hl⟩} := by simpa only [Products.nil, Products.lt_iff_lex_lt, Set.singleton_subset_iff, Set.mem_setOf_eq] grw [← he] rw [Products.span_nil_eq_top] exact Submodule.mem_top instance (α : Type*) [TopologicalSpace α] : NoZeroSMulDivisors ℤ (LocallyConstant α ℤ) := by constructor intro c f h rw [or_iff_not_imp_left] intro hc ext x apply mul_right_injective₀ hc simp [LocallyConstant.ext_iff] at h simpa [LocallyConstant.ext_iff] using h x theorem GoodProducts.linearIndependentSingleton {I} [LinearOrder I] : LinearIndependent ℤ (eval ({fun _ ↦ false} : Set (I → Bool))) := by refine linearIndependent_unique (eval ({fun _ ↦ false} : Set (I → Bool))) ?_ simp [eval, Products.eval, Products.nil, default] end Zero variable [WellFoundedLT I] section Limit /-! ## The limit case of the induction We relate linear independence in `LocallyConstant (π C (ord I · < o')) ℤ` with linear independence in `LocallyConstant C ℤ`, where `contained C o` and `o' < o`. When `o` is a limit ordinal, we prove that the good products in `LocallyConstant C ℤ` are linearly independent if and only if a certain directed union is linearly independent. Each term in this directed union is in bijection with the good products w.r.t. `π C (ord I · < o')` for an ordinal `o' < o`, and these are linearly independent by the inductive hypothesis. ### Main definitions * `GoodProducts.smaller` is the image of good products coming from a smaller ordinal. * `GoodProducts.range_equiv`: The image of the `GoodProducts` in `C` is equivalent to the union of `smaller C o'` over all ordinals `o' < o`. ### Main results * `Products.limitOrdinal`: for `o` a limit ordinal such that `contained C o`, a product `l` is good w.r.t. `C` iff it there exists an ordinal `o' < o` such that `l` is good w.r.t. `π C (ord I · < o')`. * `GoodProducts.linearIndependent_iff_union_smaller` is the result mentioned above, that the good products are linearly independent iff a directed union is. -/ namespace GoodProducts /-- The image of the `GoodProducts` for `π C (ord I · < o)` in `LocallyConstant C ℤ`. The name `smaller` refers to the setting in which we will use this, when we are mapping in `GoodProducts` from a smaller set, i.e. when `o` is a smaller ordinal than the one `C` is "contained" in. -/ def smaller (o : Ordinal) : Set (LocallyConstant C ℤ) := (πs C o) '' (range (π C (ord I · < o))) /-- The map from the image of the `GoodProducts` in `LocallyConstant (π C (ord I · < o)) ℤ` to `smaller C o` -/ noncomputable def range_equiv_smaller_toFun (o : Ordinal) (x : range (π C (ord I · < o))) : smaller C o := ⟨πs C o ↑x, x.val, x.property, rfl⟩ theorem range_equiv_smaller_toFun_bijective (o : Ordinal) : Function.Bijective (range_equiv_smaller_toFun C o) := by dsimp +unfoldPartialApp [range_equiv_smaller_toFun] refine ⟨fun a b hab ↦ ?_, fun ⟨a, b, hb⟩ ↦ ?_⟩ · ext1 simp only [Subtype.mk.injEq] at hab exact injective_πs C o hab · use ⟨b, hb.1⟩ simpa only [Subtype.mk.injEq] using hb.2 /-- The equivalence from the image of the `GoodProducts` in `LocallyConstant (π C (ord I · < o)) ℤ` to `smaller C o` -/ noncomputable def range_equiv_smaller (o : Ordinal) : range (π C (ord I · < o)) ≃ smaller C o := Equiv.ofBijective (range_equiv_smaller_toFun C o) (range_equiv_smaller_toFun_bijective C o) theorem smaller_factorization (o : Ordinal) : (fun (p : smaller C o) ↦ p.1) ∘ (range_equiv_smaller C o).toFun = (πs C o) ∘ (fun (p : range (π C (ord I · < o))) ↦ p.1) := by rfl theorem linearIndependent_iff_smaller (o : Ordinal) : LinearIndependent ℤ (GoodProducts.eval (π C (ord I · < o))) ↔ LinearIndependent ℤ (fun (p : smaller C o) ↦ p.1) := by rw [GoodProducts.linearIndependent_iff_range, ← LinearMap.linearIndependent_iff (πs C o) (LinearMap.ker_eq_bot_of_injective (injective_πs _ _)), ← smaller_factorization C o] exact linearIndependent_equiv _ theorem smaller_mono {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) : smaller C o₁ ⊆ smaller C o₂ := by rintro f ⟨g, hg, rfl⟩ simp only [smaller, Set.mem_image] use πs' C h g obtain ⟨⟨l, gl⟩, rfl⟩ := hg refine ⟨?_, ?_⟩ · use ⟨l, Products.isGood_mono C h gl⟩ ext x rw [eval, ← Products.eval_πs' _ h (Products.prop_of_isGood C _ gl), eval] · rw [← LocallyConstant.coe_inj, coe_πs C o₂, ← LocallyConstant.toFun_eq_coe, coe_πs', Function.comp_assoc, projRestricts_comp_projRestrict C _, coe_πs] rfl end GoodProducts variable {o : Ordinal} (ho : Order.IsSuccLimit o) include ho theorem Products.limitOrdinal (l : Products I) : l.isGood (π C (ord I · < o)) ↔ ∃ (o' : Ordinal), o' < o ∧ l.isGood (π C (ord I · < o')) := by refine ⟨fun h ↦ ?_, fun ⟨o', ⟨ho', hl⟩⟩ ↦ isGood_mono C (le_of_lt ho') hl⟩ use Finset.sup l.val.toFinset (fun a ↦ Order.succ (ord I a)) have hslt : Finset.sup l.val.toFinset (fun a ↦ Order.succ (ord I a)) < o := by simp only [Finset.sup_lt_iff ho.bot_lt, List.mem_toFinset] exact fun b hb ↦ ho.succ_lt (prop_of_isGood C (ord I · < o) h b hb) refine ⟨hslt, fun he ↦ h ?_⟩ have hlt : ∀ i ∈ l.val, ord I i < Finset.sup l.val.toFinset (fun a ↦ Order.succ (ord I a)) := by intro i hi simp only [Finset.lt_sup_iff, List.mem_toFinset, Order.lt_succ_iff] exact ⟨i, hi, le_rfl⟩ rwa [eval_πs_image' C (le_of_lt hslt) hlt, ← eval_πs' C (le_of_lt hslt) hlt, Submodule.apply_mem_span_image_iff_mem_span (injective_πs' C _)] variable (hsC : contained C o) include hsC theorem GoodProducts.union : range C = ⋃ (e : {o' // o' < o}), (smaller C e.val) := by ext p simp only [smaller, range, Set.mem_iUnion, Set.mem_image, Set.mem_range, Subtype.exists] refine ⟨fun hp ↦ ?_, fun hp ↦ ?_⟩ · obtain ⟨l, hl, rfl⟩ := hp rw [contained_eq_proj C o hsC, Products.limitOrdinal C ho] at hl obtain ⟨o', ho'⟩ := hl refine ⟨o', ho'.1, eval (π C (ord I · < o')) ⟨l, ho'.2⟩, ⟨l, ho'.2, rfl⟩, ?_⟩ exact Products.eval_πs C (Products.prop_of_isGood C _ ho'.2) · obtain ⟨o', h, _, ⟨l, hl, rfl⟩, rfl⟩ := hp refine ⟨l, ?_, (Products.eval_πs C (Products.prop_of_isGood C _ hl)).symm⟩ rw [contained_eq_proj C o hsC] exact Products.isGood_mono C (le_of_lt h) hl /-- The image of the `GoodProducts` in `C` is equivalent to the union of `smaller C o'` over all ordinals `o' < o`. -/ def GoodProducts.range_equiv : range C ≃ ⋃ (e : {o' // o' < o}), (smaller C e.val) := Equiv.setCongr (union C ho hsC) theorem GoodProducts.range_equiv_factorization : (fun (p : ⋃ (e : {o' // o' < o}), (smaller C e.val)) ↦ p.1) ∘ (range_equiv C ho hsC).toFun = (fun (p : range C) ↦ (p.1 : LocallyConstant C ℤ)) := rfl theorem GoodProducts.linearIndependent_iff_union_smaller : LinearIndependent ℤ (GoodProducts.eval C) ↔ LinearIndependent ℤ (fun (p : ⋃ (e : {o' // o' < o}), (smaller C e.val)) ↦ p.1) := by rw [GoodProducts.linearIndependent_iff_range, ← range_equiv_factorization C ho hsC] exact linearIndependent_equiv (range_equiv C ho hsC) end Limit end Profinite.NobelingProof
nilpotent.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import fintype div bigop prime finset fingroup morphism. From mathcomp Require Import automorphism quotient commutator gproduct. From mathcomp Require Import perm gfunctor center gseries cyclic. From mathcomp Require finfun. (******************************************************************************) (* This file defines nilpotent and solvable groups, and give some of their *) (* elementary properties; more will be added later (e.g., the nilpotence of *) (* p-groups in sylow.v, or the fact that minimal normal subgroups of solvable *) (* groups are elementary abelian in maximal.v). This file defines: *) (* nilpotent G == G is nilpotent, i.e., [~: H, G] is a proper subgroup of H *) (* for all nontrivial H <| G. *) (* solvable G == G is solvable, i.e., H^`(1) is a proper subgroup of H for *) (* all nontrivial subgroups H of G. *) (* 'L_n(G) == the nth term of the lower central series, namely *) (* [~: G, ..., G] (n Gs) if n > 0, with 'L_0(G) = G. *) (* G is nilpotent iff 'L_n(G) = 1 for some n. *) (* 'Z_n(G) == the nth term of the upper central series, i.e., *) (* with 'Z_0(G) = 1, 'Z_n.+1(G) / 'Z_n(G) = 'Z(G / 'Z_n(G)). *) (* nil_class G == the nilpotence class of G, i.e., the least n such that *) (* 'L_n.+1(G) = 1 (or, equivalently, 'Z_n(G) = G), if G is *) (* nilpotent; we take nil_class G = #|G| when G is not *) (* nilpotent, so nil_class G < #|G| iff G is nilpotent. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section SeriesDefs. Variables (n : nat) (gT : finGroupType) (A : {set gT}). (* By convention, the lower central series starts at 1 while the upper series *) (* starts at 0 (sic). *) Definition lower_central_at := iter n.-1 (fun B => [~: B, A]) A. Definition upper_central_at := iter n (fun B => coset B @*^-1 'Z(A / B)) 1. End SeriesDefs. Arguments lower_central_at n%_N {gT} A%_g. Arguments upper_central_at n%_N {gT} A%_g : simpl never. Notation "''L_' n ( G )" := (lower_central_at n G) (n at level 2, format "''L_' n ( G )") : group_scope. Notation "''Z_' n ( G )" := (upper_central_at n G) (n at level 2, format "''Z_' n ( G )") : group_scope. Section PropertiesDefs. Variables (gT : finGroupType) (A : {set gT}). Definition nilpotent := [forall (G : {group gT} | G \subset A :&: [~: G, A]), G :==: 1]. Definition nil_class := index 1 (mkseq (fun n => 'L_n.+1(A)) #|A|). Definition solvable := [forall (G : {group gT} | G \subset A :&: [~: G, G]), G :==: 1]. End PropertiesDefs. Arguments nilpotent {gT} A%_g. Arguments nil_class {gT} A%_g. Arguments solvable {gT} A%_g. Section NilpotentProps. Variable gT: finGroupType. Implicit Types (A B : {set gT}) (G H : {group gT}). Lemma nilpotent1 : nilpotent [1 gT]. Proof. by apply/forall_inP=> H; rewrite commG1 setIid -subG1. Qed. Lemma nilpotentS A B : B \subset A -> nilpotent A -> nilpotent B. Proof. move=> sBA nilA; apply/forall_inP=> H sHR. have:= forallP nilA H; rewrite (subset_trans sHR) //. by apply: subset_trans (setIS _ _) (setSI _ _); rewrite ?commgS. Qed. Lemma nil_comm_properl G H A : nilpotent G -> H \subset G -> H :!=: 1 -> A \subset 'N_G(H) -> [~: H, A] \proper H. Proof. move=> nilG sHG ntH; rewrite subsetI properE; case/andP=> sAG nHA. rewrite (subset_trans (commgS H (subset_gen A))) ?commg_subl ?gen_subG //. apply: contra ntH => sHR; have:= forallP nilG H; rewrite subsetI sHG. by rewrite (subset_trans sHR) ?commgS. Qed. Lemma nil_comm_properr G A H : nilpotent G -> H \subset G -> H :!=: 1 -> A \subset 'N_G(H) -> [~: A, H] \proper H. Proof. by rewrite commGC; apply: nil_comm_properl. Qed. Lemma centrals_nil (s : seq {group gT}) G : G.-central.-series 1%G s -> last 1%G s = G -> nilpotent G. Proof. move=> cGs defG; apply/forall_inP=> H /subsetIP[sHG sHR]. move: sHG; rewrite -{}defG -subG1 -[1]/(gval 1%G). elim: s 1%G cGs => //= L s IHs K /andP[/and3P[sRK sKL sLG] /IHs sHL] sHs. exact: subset_trans sHR (subset_trans (commSg _ (sHL sHs)) sRK). Qed. End NilpotentProps. Section LowerCentral. Variable gT : finGroupType. Implicit Types (A B : {set gT}) (G H : {group gT}). Lemma lcn0 A : 'L_0(A) = A. Proof. by []. Qed. Lemma lcn1 A : 'L_1(A) = A. Proof. by []. Qed. Lemma lcnSn n A : 'L_n.+2(A) = [~: 'L_n.+1(A), A]. Proof. by []. Qed. Lemma lcnSnS n G : [~: 'L_n(G), G] \subset 'L_n.+1(G). Proof. by case: n => //; apply: der1_subG. Qed. Lemma lcnE n A : 'L_n.+1(A) = iter n (fun B => [~: B, A]) A. Proof. by []. Qed. Lemma lcn2 A : 'L_2(A) = A^`(1). Proof. by []. Qed. Lemma lcn_group_set n G : group_set 'L_n(G). Proof. by case: n => [|[|n]]; apply: groupP. Qed. Canonical lower_central_at_group n G := Group (lcn_group_set n G). Lemma lcn_char n G : 'L_n(G) \char G. Proof. by case: n; last elim=> [|n IHn]; rewrite ?char_refl ?lcnSn ?charR. Qed. Lemma lcn_normal n G : 'L_n(G) <| G. Proof. exact/char_normal/lcn_char. Qed. Lemma lcn_sub n G : 'L_n(G) \subset G. Proof. exact/char_sub/lcn_char. Qed. Lemma lcn_norm n G : G \subset 'N('L_n(G)). Proof. exact/char_norm/lcn_char. Qed. Lemma lcn_subS n G : 'L_n.+1(G) \subset 'L_n(G). Proof. case: n => // n; rewrite lcnSn commGC commg_subr. by case/andP: (lcn_normal n.+1 G). Qed. Lemma lcn_normalS n G : 'L_n.+1(G) <| 'L_n(G). Proof. by apply: normalS (lcn_normal _ _); rewrite (lcn_subS, lcn_sub). Qed. Lemma lcn_central n G : 'L_n(G) / 'L_n.+1(G) \subset 'Z(G / 'L_n.+1(G)). Proof. case: n => [|n]; first by rewrite trivg_quotient sub1G. by rewrite subsetI quotientS ?lcn_sub ?quotient_cents2r. Qed. Lemma lcn_sub_leq m n G : n <= m -> 'L_m(G) \subset 'L_n(G). Proof. by move/subnK <-; elim: {m}(m - n) => // m; apply: subset_trans (lcn_subS _ _). Qed. Lemma lcnS n A B : A \subset B -> 'L_n(A) \subset 'L_n(B). Proof. by case: n => // n sAB; elim: n => // n IHn; rewrite !lcnSn genS ?imset2S. Qed. Lemma lcn_cprod n A B G : A \* B = G -> 'L_n(A) \* 'L_n(B) = 'L_n(G). Proof. case: n => // n /cprodP[[H K -> ->{A B}] defG cHK]. have sL := subset_trans (lcn_sub _ _); rewrite cprodE ?(centSS _ _ cHK) ?sL //. symmetry; elim: n => // n; rewrite lcnSn => ->; rewrite commMG /=; last first. by apply: subset_trans (commg_normr _ _); rewrite sL // -defG mulG_subr. rewrite -!(commGC G) -defG -{1}(centC cHK). rewrite !commMG ?normsR ?lcn_norm ?cents_norm // 1?centsC //. by rewrite -!(commGC 'L__(_)) -!lcnSn !(commG1P _) ?mul1g ?sL // centsC. Qed. Lemma lcn_dprod n A B G : A \x B = G -> 'L_n(A) \x 'L_n(B) = 'L_n(G). Proof. move=> defG; have [[K H defA defB] _ _ tiAB] := dprodP defG. rewrite !dprodEcp // in defG *; first exact: lcn_cprod. by rewrite defA defB; apply/trivgP; rewrite -tiAB defA defB setISS ?lcn_sub. Qed. Lemma der_cprod n A B G : A \* B = G -> A^`(n) \* B^`(n) = G^`(n). Proof. by move=> defG; elim: n => {defG}// n; apply: (lcn_cprod 2). Qed. Lemma der_dprod n A B G : A \x B = G -> A^`(n) \x B^`(n) = G^`(n). Proof. by move=> defG; elim: n => {defG}// n; apply: (lcn_dprod 2). Qed. Lemma lcn_bigcprod n I r P (F : I -> {set gT}) G : \big[cprod/1]_(i <- r | P i) F i = G -> \big[cprod/1]_(i <- r | P i) 'L_n(F i) = 'L_n(G). Proof. elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first exact/esym/trivgP/lcn_sub. by rewrite -(lcn_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H). Qed. Lemma lcn_bigdprod n I r P (F : I -> {set gT}) G : \big[dprod/1]_(i <- r | P i) F i = G -> \big[dprod/1]_(i <- r | P i) 'L_n(F i) = 'L_n(G). Proof. elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first exact/esym/trivgP/lcn_sub. by rewrite -(lcn_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H). Qed. Lemma der_bigcprod n I r P (F : I -> {set gT}) G : \big[cprod/1]_(i <- r | P i) F i = G -> \big[cprod/1]_(i <- r | P i) (F i)^`(n) = G^`(n). Proof. elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1. by rewrite -(der_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H). Qed. Lemma der_bigdprod n I r P (F : I -> {set gT}) G : \big[dprod/1]_(i <- r | P i) F i = G -> \big[dprod/1]_(i <- r | P i) (F i)^`(n) = G^`(n). Proof. elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1. by rewrite -(der_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H). Qed. Lemma nilpotent_class G : nilpotent G = (nil_class G < #|G|). Proof. rewrite /nil_class; set s := mkseq _ _. transitivity (1 \in s); last by rewrite -index_mem size_mkseq. apply/idP/mapP=> {s}/= [nilG | [n _ Ln1]]; last first. apply/forall_inP=> H /subsetIP[sHG sHR]. rewrite -subG1 {}Ln1; elim: n => // n IHn. by rewrite (subset_trans sHR) ?commSg. pose m := #|G|.-1; exists m; first by rewrite mem_iota /= prednK. set n := m; rewrite ['L__(G)]card_le1_trivg //= -(subnn m) -[m in _ - m]/n. elim: n => [|n]; [by rewrite subn0 prednK | rewrite lcnSn subnS]. case: (eqsVneq 'L_n.+1(G) 1) => [-> | ntLn]; first by rewrite comm1G cards1. case: (m - n) => [|m' /= IHn]; first by rewrite leqNgt cardG_gt1 ntLn. rewrite -ltnS (leq_trans (proper_card _) IHn) //. by rewrite (nil_comm_properl nilG) ?lcn_sub // subsetI subxx lcn_norm. Qed. Lemma lcn_nil_classP n G : nilpotent G -> reflect ('L_n.+1(G) = 1) (nil_class G <= n). Proof. rewrite nilpotent_class /nil_class; set s := mkseq _ _. set c := index 1 s => lt_c_G; case: leqP => [le_c_n | lt_n_c]. have Lc1: nth 1 s c = 1 by rewrite nth_index // -index_mem size_mkseq. by left; apply/trivgP; rewrite -Lc1 nth_mkseq ?lcn_sub_leq. right; apply/eqP/negPf; rewrite -(before_find 1 lt_n_c) nth_mkseq //. exact: ltn_trans lt_n_c lt_c_G. Qed. Lemma lcnP G : reflect (exists n, 'L_n.+1(G) = 1) (nilpotent G). Proof. apply: (iffP idP) => [nilG | [n Ln1]]. by exists (nil_class G); apply/lcn_nil_classP. apply/forall_inP=> H /subsetIP[sHG sHR]; rewrite -subG1 -{}Ln1. by elim: n => // n IHn; rewrite (subset_trans sHR) ?commSg. Qed. Lemma abelian_nil G : abelian G -> nilpotent G. Proof. by move=> abG; apply/lcnP; exists 1%N; apply/commG1P. Qed. Lemma nil_class0 G : (nil_class G == 0) = (G :==: 1). Proof. apply/idP/eqP=> [nilG | ->]. by apply/(lcn_nil_classP 0); rewrite ?nilpotent_class (eqP nilG) ?cardG_gt0. by rewrite -leqn0; apply/(lcn_nil_classP 0); rewrite ?nilpotent1. Qed. Lemma nil_class1 G : (nil_class G <= 1) = abelian G. Proof. have [-> | ntG] := eqsVneq G 1. by rewrite abelian1 leq_eqVlt ltnS leqn0 nil_class0 eqxx orbT. apply/idP/idP=> cGG. apply/commG1P; apply/(lcn_nil_classP 1); rewrite // nilpotent_class. by rewrite (leq_ltn_trans cGG) // cardG_gt1. by apply/(lcn_nil_classP 1); rewrite ?abelian_nil //; apply/commG1P. Qed. Lemma cprod_nil A B G : A \* B = G -> nilpotent G = nilpotent A && nilpotent B. Proof. move=> defG; case/cprodP: defG (defG) => [[H K -> ->{A B}] defG _] defGc. apply/idP/andP=> [nilG | [/lcnP[m LmH1] /lcnP[n LnK1]]]. by rewrite !(nilpotentS _ nilG) // -defG (mulG_subr, mulG_subl). apply/lcnP; exists (m + n.+1); apply/trivgP. case/cprodP: (lcn_cprod (m.+1 + n.+1) defGc) => _ <- _. by rewrite mulG_subG /= -{1}LmH1 -LnK1 !lcn_sub_leq ?leq_addl ?leq_addr. Qed. Lemma mulg_nil G H : H \subset 'C(G) -> nilpotent (G * H) = nilpotent G && nilpotent H. Proof. by move=> cGH; rewrite -(cprod_nil (cprodEY cGH)) /= cent_joinEr. Qed. Lemma dprod_nil A B G : A \x B = G -> nilpotent G = nilpotent A && nilpotent B. Proof. by case/dprodP=> [[H K -> ->] <- cHK _]; rewrite mulg_nil. Qed. Lemma bigdprod_nil I r (P : pred I) (A_ : I -> {set gT}) G : \big[dprod/1]_(i <- r | P i) A_ i = G -> (forall i, P i -> nilpotent (A_ i)) -> nilpotent G. Proof. move=> defG nilA; elim/big_rec: _ => [|i B Pi nilB] in G defG *. by rewrite -defG nilpotent1. have [[_ H _ defB] _ _ _] := dprodP defG. by rewrite (dprod_nil defG) nilA //= defB nilB. Qed. End LowerCentral. Notation "''L_' n ( G )" := (lower_central_at_group n G) : Group_scope. Lemma lcn_cont n : GFunctor.continuous (@lower_central_at n). Proof. case: n => //; elim=> // n IHn g0T h0T H phi. by rewrite !lcnSn morphimR ?lcn_sub // commSg ?IHn. Qed. Canonical lcn_igFun n := [igFun by lcn_sub^~ n & lcn_cont n]. Canonical lcn_gFun n := [gFun by lcn_cont n]. Canonical lcn_mgFun n := [mgFun by fun _ G H => @lcnS _ n G H]. Section UpperCentralFunctor. Variable n : nat. Implicit Type gT : finGroupType. Lemma ucn_pmap : exists hZ : GFunctor.pmap, @upper_central_at n = hZ. Proof. elim: n => [|n' [hZ defZ]]; first by exists trivGfun_pgFun. by exists [pgFun of @center %% hZ]; rewrite /= -defZ. Qed. (* Now extract all the intermediate facts of the last proof. *) Lemma ucn_group_set gT (G : {group gT}) : group_set 'Z_n(G). Proof. by have [hZ ->] := ucn_pmap; apply: groupP. Qed. Canonical upper_central_at_group gT G := Group (@ucn_group_set gT G). Lemma ucn_sub gT (G : {group gT}) : 'Z_n(G) \subset G. Proof. by have [hZ ->] := ucn_pmap; apply: gFsub. Qed. Lemma morphim_ucn : GFunctor.pcontinuous (@upper_central_at n). Proof. by have [hZ ->] := ucn_pmap; apply: pmorphimF. Qed. Canonical ucn_igFun := [igFun by ucn_sub & morphim_ucn]. Canonical ucn_gFun := [gFun by morphim_ucn]. Canonical ucn_pgFun := [pgFun by morphim_ucn]. Variable (gT : finGroupType) (G : {group gT}). Lemma ucn_char : 'Z_n(G) \char G. Proof. exact: gFchar. Qed. Lemma ucn_norm : G \subset 'N('Z_n(G)). Proof. exact: gFnorm. Qed. Lemma ucn_normal : 'Z_n(G) <| G. Proof. exact: gFnormal. Qed. End UpperCentralFunctor. Notation "''Z_' n ( G )" := (upper_central_at_group n G) : Group_scope. Section UpperCentral. Variable gT : finGroupType. Implicit Types (A B : {set gT}) (G H : {group gT}). Lemma ucn0 A : 'Z_0(A) = 1. Proof. by []. Qed. Lemma ucnSn n A : 'Z_n.+1(A) = coset 'Z_n(A) @*^-1 'Z(A / 'Z_n(A)). Proof. by []. Qed. Lemma ucnE n A : 'Z_n(A) = iter n (fun B => coset B @*^-1 'Z(A / B)) 1. Proof. by []. Qed. Lemma ucn_subS n G : 'Z_n(G) \subset 'Z_n.+1(G). Proof. by rewrite -{1}['Z_n(G)]ker_coset morphpreS ?sub1G. Qed. Lemma ucn_sub_geq m n G : n >= m -> 'Z_m(G) \subset 'Z_n(G). Proof. move/subnK <-; elim: {n}(n - m) => // n IHn. exact: subset_trans (ucn_subS _ _). Qed. Lemma ucn_central n G : 'Z_n.+1(G) / 'Z_n(G) = 'Z(G / 'Z_n(G)). Proof. by rewrite ucnSn cosetpreK. Qed. Lemma ucn_normalS n G : 'Z_n(G) <| 'Z_n.+1(G). Proof. by rewrite (normalS _ _ (ucn_normal n G)) ?ucn_subS ?ucn_sub. Qed. Lemma ucn_comm n G : [~: 'Z_n.+1(G), G] \subset 'Z_n(G). Proof. rewrite -quotient_cents2 ?normal_norm ?ucn_normal ?ucn_normalS //. by rewrite ucn_central subsetIr. Qed. Lemma ucn1 G : 'Z_1(G) = 'Z(G). Proof. apply: (quotient_inj (normal1 _) (normal1 _)). by rewrite /= (ucn_central 0) -injmF ?norms1 ?coset1_injm. Qed. Lemma ucnSnR n G : 'Z_n.+1(G) = [set x in G | [~: [set x], G] \subset 'Z_n(G)]. Proof. (* apply/setP=> x; rewrite inE -(setIidPr (ucn_sub n.+1 G)) inE ucnSn. *) (* FIXME: before, we got a `rewrite inE` right after the apply/setP=> x. * * However, this rewrite unfolds termes to strange internal HB names. * * We fixed the issue by applying the inE more carefully, but the problem * * needs to be investigated. *) apply/setP=> x; rewrite -(setIidPr (ucn_sub n.+1 G)) [LHS]inE [RHS]inE ucnSn. case Gx: (x \in G) => //=; have nZG := ucn_norm n G. rewrite -sub1set -sub_quotient_pre -?quotient_cents2 ?sub1set ?(subsetP nZG) //. by rewrite subsetI quotientS ?sub1set. Qed. Lemma ucn_cprod n A B G : A \* B = G -> 'Z_n(A) \* 'Z_n(B) = 'Z_n(G). Proof. case/cprodP=> [[H K -> ->{A B}] mulHK cHK]. elim: n => [|n /cprodP[_ /= defZ cZn]]; first exact: cprod1g. set Z := 'Z_n(G) in defZ cZn; rewrite (ucnSn n G) /= -/Z. have /mulGsubP[nZH nZK]: H * K \subset 'N(Z) by rewrite mulHK gFnorm. have <-: 'Z(H / Z) * 'Z(K / Z) = 'Z(G / Z). by rewrite -mulHK quotientMl // center_prod ?quotient_cents. have ZquoZ (B A : {group gT}): B \subset 'C(A) -> 'Z_n(A) * 'Z_n(B) = Z -> 'Z(A / Z) = 'Z_n.+1(A) / Z. - move=> cAB {}defZ; have cAZnB: 'Z_n(B) \subset 'C(A) := gFsub_trans _ cAB. have /second_isom[/=]: A \subset 'N(Z). by rewrite -defZ normsM ?gFnorm ?cents_norm // centsC. suffices ->: Z :&: A = 'Z_n(A). by move=> f inj_f im_f; rewrite -!im_f ?gFsub // ucn_central injm_center. rewrite -defZ -group_modl ?gFsub //; apply/mulGidPl. have [-> | n_gt0] := posnP n; first exact: subsetIl. by apply: subset_trans (ucn_sub_geq A n_gt0); rewrite /= setIC ucn1 setIS. rewrite (ZquoZ H K) 1?centsC 1?(centC cZn) // {ZquoZ}(ZquoZ K H) //. have cZn1: 'Z_n.+1(K) \subset 'C('Z_n.+1(H)) by apply: centSS cHK; apply: gFsub. rewrite -quotientMl ?quotientK ?mul_subG ?gFsub_trans //=. rewrite cprodE // -cent_joinEr ?mulSGid //= cent_joinEr //= -/Z. by rewrite -defZ mulgSS ?ucn_subS. Qed. Lemma ucn_dprod n A B G : A \x B = G -> 'Z_n(A) \x 'Z_n(B) = 'Z_n(G). Proof. move=> defG; have [[K H defA defB] _ _ tiAB] := dprodP defG. rewrite !dprodEcp // in defG *; first exact: ucn_cprod. by rewrite defA defB; apply/trivgP; rewrite -tiAB defA defB setISS ?ucn_sub. Qed. Lemma ucn_bigcprod n I r P (F : I -> {set gT}) G : \big[cprod/1]_(i <- r | P i) F i = G -> \big[cprod/1]_(i <- r | P i) 'Z_n(F i) = 'Z_n(G). Proof. elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1. by rewrite -(ucn_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H). Qed. Lemma ucn_bigdprod n I r P (F : I -> {set gT}) G : \big[dprod/1]_(i <- r | P i) F i = G -> \big[dprod/1]_(i <- r | P i) 'Z_n(F i) = 'Z_n(G). Proof. elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1. by rewrite -(ucn_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H). Qed. Lemma ucn_lcnP n G : ('L_n.+1(G) == 1) = ('Z_n(G) == G). Proof. rewrite !eqEsubset sub1G ucn_sub /= andbT -(ucn0 G); set i := (n in LHS). have: i + 0 = n by [rewrite addn0]; elim: i 0 => [j <- //|i IHi j]. rewrite addSnnS => /IHi <- {IHi}; rewrite ucnSn lcnSn. rewrite -sub_morphim_pre ?gFsub_trans ?gFnorm_trans // subsetI. by rewrite morphimS ?gFsub // quotient_cents2 ?gFsub_trans ?gFnorm_trans. Qed. Lemma ucnP G : reflect (exists n, 'Z_n(G) = G) (nilpotent G). Proof. apply: (iffP (lcnP G)) => -[n /eqP-clGn]; by exists n; apply/eqP; rewrite ucn_lcnP in clGn *. Qed. Lemma ucn_nil_classP n G : nilpotent G -> reflect ('Z_n(G) = G) (nil_class G <= n). Proof. move=> nilG; rewrite (sameP (lcn_nil_classP n nilG) eqP) ucn_lcnP; apply: eqP. Qed. Lemma ucn_id n G : 'Z_n('Z_n(G)) = 'Z_n(G). Proof. exact: gFid. Qed. Lemma ucn_nilpotent n G : nilpotent 'Z_n(G). Proof. by apply/ucnP; exists n; rewrite ucn_id. Qed. Lemma nil_class_ucn n G : nil_class 'Z_n(G) <= n. Proof. by apply/ucn_nil_classP; rewrite ?ucn_nilpotent // ucn_id. Qed. End UpperCentral. Section MorphNil. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Implicit Type G : {group aT}. Lemma morphim_lcn n G : G \subset D -> f @* 'L_n(G) = 'L_n(f @* G). Proof. move=> sHG; case: n => //; elim=> // n IHn. by rewrite !lcnSn -IHn morphimR // (subset_trans _ sHG) // lcn_sub. Qed. Lemma injm_ucn n G : 'injm f -> G \subset D -> f @* 'Z_n(G) = 'Z_n(f @* G). Proof. exact: injmF. Qed. Lemma morphim_nil G : nilpotent G -> nilpotent (f @* G). Proof. case/ucnP=> n ZnG; apply/ucnP; exists n; apply/eqP. by rewrite eqEsubset ucn_sub /= -{1}ZnG morphim_ucn. Qed. Lemma injm_nil G : 'injm f -> G \subset D -> nilpotent (f @* G) = nilpotent G. Proof. move=> injf sGD; apply/idP/idP; last exact: morphim_nil. case/ucnP=> n; rewrite -injm_ucn // => /injm_morphim_inj defZ. by apply/ucnP; exists n; rewrite defZ ?gFsub_trans. Qed. Lemma nil_class_morphim G : nilpotent G -> nil_class (f @* G) <= nil_class G. Proof. move=> nilG; rewrite (sameP (ucn_nil_classP _ (morphim_nil nilG)) eqP) /=. by rewrite eqEsubset ucn_sub -{1}(ucn_nil_classP _ nilG (leqnn _)) morphim_ucn. Qed. Lemma nil_class_injm G : 'injm f -> G \subset D -> nil_class (f @* G) = nil_class G. Proof. move=> injf sGD; case nilG: (nilpotent G). apply/eqP; rewrite eqn_leq nil_class_morphim //. rewrite (sameP (lcn_nil_classP _ nilG) eqP) -subG1. rewrite -(injmSK injf) ?gFsub_trans // morphim1. by rewrite morphim_lcn // (lcn_nil_classP _ _ (leqnn _)) //= injm_nil. transitivity #|G|; apply/eqP; rewrite eqn_leq. rewrite -(card_injm injf sGD) (leq_trans (index_size _ _)) ?size_mkseq //. by rewrite leqNgt -nilpotent_class injm_nil ?nilG. rewrite (leq_trans (index_size _ _)) ?size_mkseq // leqNgt -nilpotent_class. by rewrite nilG. Qed. End MorphNil. Section QuotientNil. Variables gT : finGroupType. Implicit Types (rT : finGroupType) (G H : {group gT}). Lemma quotient_ucn_add m n G : 'Z_(m + n)(G) / 'Z_n(G) = 'Z_m(G / 'Z_n(G)). Proof. elim: m => [|m IHm]; first exact: trivg_quotient. apply/setP=> Zx; have [x Nx ->{Zx}] := cosetP Zx. have [sZG nZG] := andP (ucn_normal n G). rewrite (ucnSnR m) inE -!sub1set -morphim_set1 //= -quotientR ?sub1set // -IHm. rewrite !quotientSGK ?(ucn_sub_geq, leq_addl, comm_subG _ nZG, sub1set) //=. by rewrite addSn /= ucnSnR inE. Qed. Lemma isog_nil rT G (L : {group rT}) : G \isog L -> nilpotent G = nilpotent L. Proof. by case/isogP=> f injf <-; rewrite injm_nil. Qed. Lemma isog_nil_class rT G (L : {group rT}) : G \isog L -> nil_class G = nil_class L. Proof. by case/isogP=> f injf <-; rewrite nil_class_injm. Qed. Lemma quotient_nil G H : nilpotent G -> nilpotent (G / H). Proof. exact: morphim_nil. Qed. Lemma quotient_center_nil G : nilpotent (G / 'Z(G)) = nilpotent G. Proof. rewrite -ucn1; apply/idP/idP; last exact: quotient_nil. case/ucnP=> c nilGq; apply/ucnP; exists c.+1; have nsZ1G := ucn_normal 1 G. apply: (quotient_inj _ nsZ1G); last by rewrite /= -(addn1 c) quotient_ucn_add. by rewrite (normalS _ _ nsZ1G) ?ucn_sub ?ucn_sub_geq. Qed. Lemma nil_class_quotient_center G : nilpotent (G) -> nil_class (G / 'Z(G)) = (nil_class G).-1. Proof. move=> nilG; have nsZ1G := ucn_normal 1 G. apply/eqP; rewrite -ucn1 eqn_leq; apply/andP; split. apply/ucn_nil_classP; rewrite ?quotient_nil //= -quotient_ucn_add ucn1. by rewrite (ucn_nil_classP _ _ _) ?addn1 ?leqSpred. rewrite -subn1 leq_subLR addnC; apply/ucn_nil_classP => //=. apply: (quotient_inj _ nsZ1G) => /=. by apply: normalS (ucn_sub _ _) nsZ1G; rewrite /= addnS ucn_sub_geq. by rewrite quotient_ucn_add; apply/ucn_nil_classP; rewrite //= quotient_nil. Qed. Lemma nilpotent_sub_norm G H : nilpotent G -> H \subset G -> 'N_G(H) \subset H -> G :=: H. Proof. move=> nilG sHG sNH; apply/eqP; rewrite eqEsubset sHG andbT; apply/negP=> nsGH. have{nsGH} [i sZH []]: exists2 i, 'Z_i(G) \subset H & ~ 'Z_i.+1(G) \subset H. case/ucnP: nilG => n ZnG; rewrite -{}ZnG in nsGH. elim: n => [|i IHi] in nsGH *; first by rewrite sub1G in nsGH. by case sZH: ('Z_i(G) \subset H); [exists i | apply: IHi; rewrite sZH]. apply: subset_trans sNH; rewrite subsetI ucn_sub -commg_subr. by apply: subset_trans sZH; apply: subset_trans (ucn_comm i G); apply: commgS. Qed. Lemma nilpotent_proper_norm G H : nilpotent G -> H \proper G -> H \proper 'N_G(H). Proof. move=> nilG; rewrite properEneq properE subsetI normG => /andP[neHG sHG]. by rewrite sHG; apply: contra neHG => /(nilpotent_sub_norm nilG)->. Qed. Lemma nilpotent_subnormal G H : nilpotent G -> H \subset G -> H <|<| G. Proof. move=> nilG; have [m] := ubnP (#|G| - #|H|). elim: m H => // m IHm H /ltnSE-leGHm sHG. have [->|] := eqVproper sHG; first exact: subnormal_refl. move/(nilpotent_proper_norm nilG); set K := 'N_G(H) => prHK. have snHK: H <|<| K by rewrite normal_subnormal ?normalSG. have sKG: K \subset G by rewrite subsetIl. apply: subnormal_trans snHK (IHm _ (leq_trans _ leGHm) sKG). by rewrite ltn_sub2l ?proper_card ?(proper_sub_trans prHK). Qed. Lemma TI_center_nil G H : nilpotent G -> H <| G -> H :&: 'Z(G) = 1 -> H :=: 1. Proof. move=> nilG /andP[sHG nHG] tiHZ. rewrite -{1}(setIidPl sHG); have{nilG} /ucnP[n <-] := nilG. elim: n => [|n IHn]; apply/trivgP; rewrite ?subsetIr // -tiHZ. rewrite [H :&: 'Z(G)]setIA subsetI setIS ?ucn_sub //= (sameP commG1P trivgP). rewrite -commg_subr commGC in nHG. rewrite -IHn subsetI (subset_trans _ nHG) ?commSg ?subsetIl //=. by rewrite (subset_trans _ (ucn_comm n G)) ?commSg ?subsetIr. Qed. Lemma meet_center_nil G H : nilpotent G -> H <| G -> H :!=: 1 -> H :&: 'Z(G) != 1. Proof. by move=> nilG nsHG; apply: contraNneq => /TI_center_nil->. Qed. Lemma center_nil_eq1 G : nilpotent G -> ('Z(G) == 1) = (G :==: 1). Proof. move=> nilG; apply/eqP/eqP=> [Z1 | ->]; last exact: center1. by rewrite (TI_center_nil nilG) // (setIidPr (center_sub G)). Qed. Lemma cyclic_nilpotent_quo_der1_cyclic G : nilpotent G -> cyclic (G / G^`(1)) -> cyclic G. Proof. move=> nG; rewrite (isog_cyclic (quotient1_isog G)). have [-> // | ntG' cGG'] := (eqVneq G^`(1) 1)%g. suffices: 'L_2(G) \subset G :&: 'L_3(G) by move/(eqfun_inP nG)=> <-. rewrite subsetI lcn_sub /= -quotient_cents2 ?lcn_norm //. apply: cyclic_factor_abelian (lcn_central 2 G) _. by rewrite (isog_cyclic (third_isog _ _ _)) ?lcn_normal // lcn_subS. Qed. End QuotientNil. Section Solvable. Variable gT : finGroupType. Implicit Types G H : {group gT}. Lemma nilpotent_sol G : nilpotent G -> solvable G. Proof. move=> nilG; apply/forall_inP=> H /subsetIP[sHG sHH']. by rewrite (forall_inP nilG) // subsetI sHG (subset_trans sHH') ?commgS. Qed. Lemma abelian_sol G : abelian G -> solvable G. Proof. by move/abelian_nil/nilpotent_sol. Qed. Lemma solvable1 : solvable [1 gT]. Proof. exact: abelian_sol (abelian1 gT). Qed. Lemma solvableS G H : H \subset G -> solvable G -> solvable H. Proof. move=> sHG solG; apply/forall_inP=> K /subsetIP[sKH sKK']. by rewrite (forall_inP solG) // subsetI (subset_trans sKH). Qed. Lemma sol_der1_proper G H : solvable G -> H \subset G -> H :!=: 1 -> H^`(1) \proper H. Proof. move=> solG sHG ntH; rewrite properE comm_subG //; apply: implyP ntH. by have:= forallP solG H; rewrite subsetI sHG implybNN. Qed. Lemma derivedP G : reflect (exists n, G^`(n) = 1) (solvable G). Proof. apply: (iffP idP) => [solG | [n solGn]]; last first. apply/forall_inP=> H /subsetIP[sHG sHH']. rewrite -subG1 -{}solGn; elim: n => // n IHn. exact: subset_trans sHH' (commgSS _ _). suffices IHn n: #|G^`(n)| <= (#|G|.-1 - n).+1. by exists #|G|.-1; rewrite [G^`(_)]card_le1_trivg ?(leq_trans (IHn _)) ?subnn. elim: n => [|n IHn]; first by rewrite subn0 prednK. rewrite dergSn subnS -ltnS. have [-> | ntGn] := eqVneq G^`(n) 1; first by rewrite commG1 cards1. case: (_ - _) IHn => [|n']; first by rewrite leqNgt cardG_gt1 ntGn. by apply: leq_trans (proper_card _); apply: sol_der1_proper (der_sub _ _) _. Qed. End Solvable. Section MorphSol. Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}). Variable G : {group gT}. Lemma morphim_sol : solvable G -> solvable (f @* G). Proof. move/(solvableS (subsetIr D G)); case/derivedP=> n Gn1; apply/derivedP. by exists n; rewrite /= -morphimIdom -morphim_der ?subsetIl // Gn1 morphim1. Qed. Lemma injm_sol : 'injm f -> G \subset D -> solvable (f @* G) = solvable G. Proof. move=> injf sGD; apply/idP/idP; last exact: morphim_sol. case/derivedP=> n Gn1; apply/derivedP; exists n; apply/trivgP. by rewrite -(injmSK injf) ?gFsub_trans ?morphim_der // Gn1 morphim1. Qed. End MorphSol. Section QuotientSol. Variables gT rT : finGroupType. Implicit Types G H K : {group gT}. Lemma isog_sol G (L : {group rT}) : G \isog L -> solvable G = solvable L. Proof. by case/isogP=> f injf <-; rewrite injm_sol. Qed. Lemma quotient_sol G H : solvable G -> solvable (G / H). Proof. exact: morphim_sol. Qed. Lemma series_sol G H : H <| G -> solvable G = solvable H && solvable (G / H). Proof. case/andP=> sHG nHG; apply/idP/andP=> [solG | [solH solGH]]. by rewrite quotient_sol // (solvableS sHG). apply/forall_inP=> K /subsetIP[sKG sK'K]. suffices sKH: K \subset H by rewrite (forall_inP solH) // subsetI sKH. have nHK := subset_trans sKG nHG. rewrite -quotient_sub1 // subG1 (forall_inP solGH) //. by rewrite subsetI -morphimR ?morphimS. Qed. Lemma metacyclic_sol G : metacyclic G -> solvable G. Proof. case/metacyclicP=> K [cycK nsKG cycGq]. by rewrite (series_sol nsKG) !abelian_sol ?cyclic_abelian. Qed. End QuotientSol. Section setXn. Import finfun. Lemma setXn_sol n (gT : 'I_n -> finGroupType) (G : forall i, {group gT i}) : (forall i, solvable (G i)) -> solvable (setXn G). Proof. elim: n => [|n IHn] in gT G * => solG; first by rewrite groupX0 solvable1. pose gT' (i : 'I_n) := gT (lift ord0 i). pose prod_group_gT := [the finGroupType of {dffun forall i, gT i}]. pose prod_group_gT' := [the finGroupType of {dffun forall i, gT' i}]. pose f (x : prod_group_gT) : prod_group_gT' := [ffun i => x (lift ord0 i)]. have fm : morphic (setXn G) f. apply/'forall_implyP => -[a b]; rewrite !inE/=. by move=> /andP[/forallP aG /forallP bG]; apply/eqP/ffunP => i; rewrite !ffunE. rewrite (@series_sol _ [group of setXn G] ('ker (morphm fm))) ?ker_normal//=. rewrite (isog_sol (first_isog _))/=. have -> : (morphm fm @* setXn G)%g = setXn (fun i => G (lift ord0 i)). apply/setP => v; rewrite !inE morphimEdom; apply/idP/forallP => /=. move=> /imsetP[/=x]; rewrite inE => /forallP/= xG ->. by move=> i; rewrite morphmE ffunE xG. move=> vG; apply/imsetP. pose w := [ffun i : 'I_n.+1 => match unliftP ord0 i return (gT i) : Type with | UnliftSome j i_eq => ecast i (gT i) (esym i_eq) (v j) | UnliftNone i0 => 1%g end]. have wl i : w (lift ord0 i) = v i. rewrite ffunE; case: unliftP => //= j elij. have eij : i = j by case: elij; apply/val_inj. by rewrite [elij](eq_irrelevance _ (congr1 _ eij)); case: _ / eij. have w0 : w ord0 = 1%g by rewrite ffunE; case: unliftP. exists w; last by apply/ffunP => i; rewrite morphmE ffunE/= wl. apply/setXnP => i. case: (unliftP ord0 i) => [j|]->; rewrite ?wl ?w0 ?vG//. rewrite IHn ?andbT//; last by move=> i; apply: solG. pose k (x : gT ord0) : prod_group_gT := [ffun i : 'I_n.+1 => match (ord0 =P i) return (gT i) : Type with | ReflectT P => ecast i (gT i) P x | _ => 1%g end]. have km : morphic (G ord0) k. apply/'forall_implyP => -[a b]; rewrite !inE/= => /andP[aG bG]. apply/eqP/ffunP => i; rewrite !ffunE; case: eqP => //; rewrite ?mulg1//. by case: _ /. suff -> : ('ker (morphm fm) = morphm km @* G ord0)%g by rewrite morphim_sol. apply/setP => x; rewrite morphimEdom; apply/idP/imsetP => [xker|]. exists (x ord0). by have := dom_ker xker; rewrite inE => /forallP/(_ ord0). rewrite /= morphmE; apply/ffunP => i; rewrite ffunE; case: eqP => //=. by case: _ /. move/eqP; rewrite eq_sym; have /mker/= := xker; rewrite morphmE => /ffunP. by case: (@unliftP _ ord0 i) => [j|] ->//= /(_ j); rewrite !ffunE. move=> [x0 xG0 -> /=]; rewrite morphmE; apply/kerP; rewrite ?inE. by apply/forallP => i; rewrite ffunE; case: eqP => //=; case: _ /. by rewrite /= morphmE; apply/ffunP => i; rewrite !ffunE; case: eqP. Qed. End setXn.
archimedean.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype bigop order ssralg poly ssrnum ssrint. (******************************************************************************) (* Archimedean structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines some numeric structures extended with the Archimedean *) (* axiom. To use this file, insert "Import Num.Theory." and optionally *) (* "Import Num.Def." before your scripts as in the ssrnum library. *) (* The modules provided by this library subsume those from ssrnum. *) (* *) (* This file defines the following structures: *) (* *) (* archiNumDomainType == numDomainType with the Archimedean axiom *) (* The HB class is called ArchiNumDomain. *) (* archiNumFieldType == numFieldType with the Archimedean axiom *) (* The HB class is called ArchiNumField. *) (* archiClosedFieldType == closedFieldType with the Archimedean axiom *) (* The HB class is called ArchiClosedField. *) (* archiRealDomainType == realDomainType with the Archimedean axiom *) (* The HB class is called ArchiRealDomain. *) (* archiRealFieldType == realFieldType with the Archimedean axiom *) (* The HB class is called ArchiRealField. *) (* archiRcfType == rcfType with the Archimedean axiom *) (* The HB class is called ArchiRealClosedField. *) (* *) (* Over these structures, we have the following operations: *) (* x \is a Num.int <=> x is an integer, i.e., x = m%:~R for some m : int *) (* x \is a Num.nat <=> x is a natural number, i.e., x = m%:R for some m : nat*) (* Num.floor x == the m : int such that m%:~R <= x < (m + 1)%:~R *) (* when x \is a Num.real, otherwise 0%Z *) (* Num.ceil x == the m : int such that (m - 1)%:~R < x <= m%:~R *) (* when x \is a Num.real, otherwise 0%Z *) (* Num.truncn x == the n : nat such that n%:R <= x < n.+1%:R *) (* when 0 <= n, otherwise 0%N *) (* Num.bound x == an upper bound for x, i.e., an n such that `|x| < n%:R *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import Order.TTheory GRing.Theory Num.Theory. Module Num. Import Num.Def. HB.mixin Record NumDomain_hasFloorCeilTruncn R of Num.NumDomain R := { floor : R -> int; ceil : R -> int; truncn : R -> nat; int_num_subdef : pred R; nat_num_subdef : pred R; floor_subproof : forall x, if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0; ceil_subproof : forall x, ceil x = - floor (- x); truncn_subproof : forall x, truncn x = if floor x is Posz n then n else 0; int_num_subproof : forall x, reflect (exists n, x = n%:~R) (int_num_subdef x); nat_num_subproof : forall x, reflect (exists n, x = n%:R) (nat_num_subdef x); }. #[short(type="archiNumDomainType")] HB.structure Definition ArchiNumDomain := { R of NumDomain_hasFloorCeilTruncn R & Num.NumDomain R }. Module ArchiNumDomainExports. Bind Scope ring_scope with ArchiNumDomain.sort. End ArchiNumDomainExports. HB.export ArchiNumDomainExports. #[short(type="archiNumFieldType")] HB.structure Definition ArchiNumField := { R of NumDomain_hasFloorCeilTruncn R & Num.NumField R }. Module ArchiNumFieldExports. Bind Scope ring_scope with ArchiNumField.sort. End ArchiNumFieldExports. HB.export ArchiNumFieldExports. #[short(type="archiClosedFieldType")] HB.structure Definition ArchiClosedField := { R of NumDomain_hasFloorCeilTruncn R & Num.ClosedField R }. Module ArchiClosedFieldExports. Bind Scope ring_scope with ArchiClosedField.sort. End ArchiClosedFieldExports. HB.export ArchiClosedFieldExports. #[short(type="archiRealDomainType")] HB.structure Definition ArchiRealDomain := { R of NumDomain_hasFloorCeilTruncn R & Num.RealDomain R }. Module ArchiRealDomainExports. Bind Scope ring_scope with ArchiRealDomain.sort. End ArchiRealDomainExports. HB.export ArchiRealDomainExports. #[short(type="archiRealFieldType")] HB.structure Definition ArchiRealField := { R of NumDomain_hasFloorCeilTruncn R & Num.RealField R }. Module ArchiRealFieldExports. Bind Scope ring_scope with ArchiRealField.sort. End ArchiRealFieldExports. HB.export ArchiRealFieldExports. #[short(type="archiRcfType")] HB.structure Definition ArchiRealClosedField := { R of NumDomain_hasFloorCeilTruncn R & Num.RealClosedField R }. Module ArchiRealClosedFieldExports. Bind Scope ring_scope with ArchiRealClosedField.sort. End ArchiRealClosedFieldExports. HB.export ArchiRealClosedFieldExports. Section Def. Context {R : archiNumDomainType}. Definition nat_num : qualifier 1 R := [qualify a x : R | nat_num_subdef x]. Definition int_num : qualifier 1 R := [qualify a x : R | int_num_subdef x]. Definition bound (x : R) := (truncn `|x|).+1. End Def. Arguments floor {R} : rename, simpl never. Arguments ceil {R} : rename, simpl never. Arguments truncn {R} : rename, simpl never. Arguments nat_num {R} : simpl never. Arguments int_num {R} : simpl never. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")] Notation trunc := truncn. Module Def. Export ssrnum.Num.Def. Notation truncn := truncn. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")] Notation trunc := truncn. Notation floor := floor. Notation ceil := ceil. Notation nat_num := nat_num. Notation int_num := int_num. Notation archi_bound := bound. End Def. Module intArchimedean. Section intArchimedean. Implicit Types n : int. Lemma floorP n : if n \is Rreal then n%:~R <= n < (n + 1)%:~R else n == 0. Proof. by rewrite num_real !intz ltzD1 lexx. Qed. Lemma intrP n : reflect (exists m, n = m%:~R) true. Proof. by apply: ReflectT; exists n; rewrite intz. Qed. Lemma natrP n : reflect (exists m, n = m%:R) (0 <= n). Proof. apply: (iffP idP); last by case=> m ->; rewrite ler0n. by case: n => // n _; exists n; rewrite natz. Qed. End intArchimedean. End intArchimedean. #[export] HB.instance Definition _ := @NumDomain_hasFloorCeilTruncn.Build int id id _ xpredT Rnneg_pred intArchimedean.floorP (fun=> esym (opprK _)) (fun=> erefl) intArchimedean.intrP intArchimedean.natrP. Module Import Theory. Export ssrnum.Num.Theory. Section ArchiNumDomainTheory. Variable R : archiNumDomainType. Implicit Types x y z : R. Local Notation truncn := (@truncn R). Local Notation floor := (@floor R). Local Notation ceil := (@ceil R). Local Notation nat_num := (@Def.nat_num R). Local Notation int_num := (@Def.int_num R). Local Lemma floorP x : if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0. Proof. exact: floor_subproof. Qed. Lemma floorNceil x : floor x = - ceil (- x). Proof. by rewrite ceil_subproof !opprK. Qed. Lemma ceilNfloor x : ceil x = - floor (- x). Proof. exact: ceil_subproof. Qed. Lemma truncEfloor x : truncn x = if floor x is Posz n then n else 0. Proof. exact: truncn_subproof. Qed. Lemma natrP x : reflect (exists n, x = n%:R) (x \is a nat_num). Proof. exact: nat_num_subproof. Qed. Lemma intrP x : reflect (exists m, x = m%:~R) (x \is a int_num). Proof. exact: int_num_subproof. Qed. (* int_num and nat_num *) Lemma intr_int m : m%:~R \is a int_num. Proof. by apply/intrP; exists m. Qed. Lemma natr_nat n : n%:R \is a nat_num. Proof. by apply/natrP; exists n. Qed. #[local] Hint Resolve intr_int natr_nat : core. Lemma rpred_int_num (S : subringClosed R) x : x \is a int_num -> x \in S. Proof. by move=> /intrP[n ->]; rewrite rpred_int. Qed. Lemma rpred_nat_num (S : semiringClosed R) x : x \is a nat_num -> x \in S. Proof. by move=> /natrP[n ->]; apply: rpred_nat. Qed. Lemma int_num0 : 0 \is a int_num. Proof. exact: (intr_int 0). Qed. Lemma int_num1 : 1 \is a int_num. Proof. exact: (intr_int 1). Qed. Lemma nat_num0 : 0 \is a nat_num. Proof. exact: (natr_nat 0). Qed. Lemma nat_num1 : 1 \is a nat_num. Proof. exact: (natr_nat 1). Qed. #[local] Hint Resolve int_num0 int_num1 nat_num0 nat_num1 : core. Fact int_num_subring : subring_closed int_num. Proof. by split=> // _ _ /intrP[n ->] /intrP[m ->]; rewrite -(intrB, intrM). Qed. #[export] HB.instance Definition _ := GRing.isSubringClosed.Build R int_num_subdef int_num_subring. Fact nat_num_semiring : semiring_closed nat_num. Proof. by do 2![split] => //= _ _ /natrP[n ->] /natrP[m ->]; rewrite -(natrD, natrM). Qed. #[export] HB.instance Definition _ := GRing.isSemiringClosed.Build R nat_num_subdef nat_num_semiring. Lemma Rreal_nat : {subset nat_num <= Rreal}. Proof. exact: rpred_nat_num. Qed. Lemma intr_nat : {subset nat_num <= int_num}. Proof. by move=> _ /natrP[n ->]; rewrite pmulrn intr_int. Qed. Lemma Rreal_int : {subset int_num <= Rreal}. Proof. exact: rpred_int_num. Qed. Lemma intrE x : (x \is a int_num) = (x \is a nat_num) || (- x \is a nat_num). Proof. apply/idP/orP => [/intrP[[n|n] ->]|[]/intr_nat]; rewrite ?rpredN //. by left; apply/natrP; exists n. by rewrite NegzE intrN opprK; right; apply/natrP; exists n.+1. Qed. Lemma intr_normK x : x \is a int_num -> `|x| ^+ 2 = x ^+ 2. Proof. by move/Rreal_int/real_normK. Qed. Lemma natr_normK x : x \is a nat_num -> `|x| ^+ 2 = x ^+ 2. Proof. by move/Rreal_nat/real_normK. Qed. Lemma natr_norm_int x : x \is a int_num -> `|x| \is a nat_num. Proof. by move=> /intrP[m ->]; rewrite -intr_norm rpred_nat_num ?natr_nat. Qed. Lemma natr_ge0 x : x \is a nat_num -> 0 <= x. Proof. by move=> /natrP[n ->]; apply: ler0n. Qed. Lemma natr_gt0 x : x \is a nat_num -> (0 < x) = (x != 0). Proof. by move/natr_ge0; case: comparableP. Qed. Lemma natrEint x : (x \is a nat_num) = (x \is a int_num) && (0 <= x). Proof. apply/idP/andP=> [Nx | [Zx x_ge0]]; first by rewrite intr_nat ?natr_ge0. by rewrite -(ger0_norm x_ge0) natr_norm_int. Qed. Lemma intrEge0 x : 0 <= x -> (x \is a int_num) = (x \is a nat_num). Proof. by rewrite natrEint andbC => ->. Qed. Lemma intrEsign x : x \is a int_num -> x = (-1) ^+ (x < 0)%R * `|x|. Proof. by move/Rreal_int/realEsign. Qed. Lemma norm_natr x : x \is a nat_num -> `|x| = x. Proof. by move/natr_ge0/ger0_norm. Qed. Lemma natr_exp_even x n : ~~ odd n -> x \is a int_num -> x ^+ n \is a nat_num. Proof. move=> n_oddF x_intr. by rewrite natrEint rpredX //= real_exprn_even_ge0 // Rreal_int. Qed. Lemma norm_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= `|x|. Proof. rewrite -normr_eq0 => /natr_norm_int/natrP[n ->]. by rewrite pnatr_eq0 ler1n lt0n. Qed. Lemma sqr_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= x ^+ 2. Proof. by move=> Zx nz_x; rewrite -intr_normK // expr_ge1 ?normr_ge0 ?norm_intr_ge1. Qed. Lemma intr_ler_sqr x : x \is a int_num -> x <= x ^+ 2. Proof. move=> Zx; have [-> | nz_x] := eqVneq x 0; first by rewrite expr0n. apply: le_trans (_ : `|x| <= _); first by rewrite real_ler_norm ?Rreal_int. by rewrite -intr_normK // ler_eXnr // norm_intr_ge1. Qed. (* floor and int_num *) Lemma real_floor_itv x : x \is Rreal -> (floor x)%:~R <= x < (floor x + 1)%:~R. Proof. by case: ifP (floorP x). Qed. Lemma real_floor_le x : x \is Rreal -> (floor x)%:~R <= x. Proof. by case/real_floor_itv/andP. Qed. Lemma real_floorD1_gt x : x \is Rreal -> x < (floor x + 1)%:~R. Proof. by case/real_floor_itv/andP. Qed. Lemma floor_def x m : m%:~R <= x < (m + 1)%:~R -> floor x = m. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eq_le -!ltzD1. move: (ger_real lemx); rewrite realz => /real_floor_itv/andP[lefx ltxf1]. by rewrite -!(ltr_int R) 2?(@le_lt_trans _ _ x). Qed. (* TODO: rename to real_floor_ge_int, once the currently deprecated one has been removed *) Lemma real_floor_ge_int_tmp x n : x \is Rreal -> (n <= floor x) = (n%:~R <= x). Proof. move=> /real_floor_itv /andP[lefx ltxf1]; apply/idP/idP => lenx. by apply: le_trans lefx; rewrite ler_int. by rewrite -ltzD1 -(ltr_int R); apply: le_lt_trans ltxf1. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use real_floor_ge_int_tmp instead.")] Lemma real_floor_ge_int x n : x \is Rreal -> (n%:~R <= x) = (n <= floor x). Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed. Lemma real_floor_lt_int x n : x \is Rreal -> (floor x < n) = (x < n%:~R). Proof. by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_floor_ge_int_tmp -?ltNge. Qed. Lemma real_floor_eq x n : x \is Rreal -> (floor x == n) = (n%:~R <= x < (n + 1)%:~R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: real_floor_itv|exact: floor_def]. Qed. Lemma le_floor : {homo floor : x y / x <= y}. Proof. move=> x y lexy; move: (floorP x) (floorP y); rewrite (ger_real lexy). case: ifP => [_ /andP[lefx _] /andP[_] | _ /eqP-> /eqP-> //]. by move=> /(le_lt_trans lexy) /(le_lt_trans lefx); rewrite ltr_int ltzD1. Qed. Lemma intrKfloor : cancel intr floor. Proof. by move=> m; apply: floor_def; rewrite lexx rmorphD ltrDl ltr01. Qed. Lemma natr_int n : n%:R \is a int_num. Proof. by rewrite intrE natr_nat. Qed. #[local] Hint Resolve natr_int : core. Lemma intrEfloor x : x \is a int_num = ((floor x)%:~R == x). Proof. by apply/intrP/eqP => [[n ->] | <-]; [rewrite intrKfloor | exists (floor x)]. Qed. Lemma floorK : {in int_num, cancel floor intr}. Proof. by move=> z; rewrite intrEfloor => /eqP. Qed. Lemma floor0 : floor 0 = 0. Proof. exact: intrKfloor 0. Qed. Lemma floor1 : floor 1 = 1. Proof. exact: intrKfloor 1. Qed. #[local] Hint Resolve floor0 floor1 : core. Lemma real_floorDzr : {in int_num & Rreal, {morph floor : x y / x + y}}. Proof. move=> _ y /intrP[m ->] Ry; apply: floor_def. by rewrite -addrA 2!rmorphD /= intrKfloor lerD2l ltrD2l real_floor_itv. Qed. Lemma real_floorDrz : {in Rreal & int_num, {morph floor : x y / x + y}}. Proof. by move=> x y xr yz; rewrite addrC real_floorDzr // addrC. Qed. Lemma floorN : {in int_num, {morph floor : x / - x}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphN !intrKfloor. Qed. Lemma floorM : {in int_num &, {morph floor : x y / x * y}}. Proof. by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKfloor. Qed. Lemma floorX n : {in int_num, {morph floor : x / x ^+ n}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKfloor. Qed. Lemma real_floor_ge0 x : x \is Rreal -> (0 <= floor x) = (0 <= x). Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed. Lemma floor_lt0 x : (floor x < 0) = (x < 0). Proof. case: ifP (floorP x) => [xr _ | xr /eqP <-]; first by rewrite real_floor_lt_int. by rewrite ltxx; apply/esym/(contraFF _ xr)/ltr0_real. Qed. Lemma real_floor_le0 x : x \is Rreal -> (floor x <= 0) = (x < 1). Proof. by move=> ?; rewrite -ltzD1 add0r real_floor_lt_int. Qed. Lemma floor_gt0 x : (floor x > 0) = (x >= 1). Proof. case: ifP (floorP x) => [xr _ | xr /eqP->]. by rewrite gtz0_ge1 real_floor_ge_int_tmp. by rewrite ltxx; apply/esym/(contraFF _ xr)/ger1_real. Qed. Lemma floor_neq0 x : (floor x != 0) = (x < 0) || (x >= 1). Proof. case: ifP (floorP x) => [xr _ | xr /eqP->]; rewrite ?eqxx/=. by rewrite neq_lt floor_lt0 floor_gt0. by apply/esym/(contraFF _ xr) => /orP[/ltr0_real|/ger1_real]. Qed. Lemma floorpK : {in polyOver int_num, cancel (map_poly floor) (map_poly intr)}. Proof. move=> p /(all_nthP 0) Zp; apply/polyP=> i. rewrite coef_map coef_map_id0 //= -[p]coefK coef_poly. by case: ifP => [/Zp/floorK // | _]; rewrite floor0. Qed. Lemma floorpP (p : {poly R}) : p \is a polyOver int_num -> {q | p = map_poly intr q}. Proof. by exists (map_poly floor p); rewrite floorpK. Qed. (* ceil and int_num *) Lemma real_ceil_itv x : x \is Rreal -> (ceil x - 1)%:~R < x <= (ceil x)%:~R. Proof. rewrite ceilNfloor -opprD !intrN ltrNl lerNr andbC -realN. exact: real_floor_itv. Qed. Lemma real_ceilB1_lt x : x \is Rreal -> (ceil x - 1)%:~R < x. Proof. by case/real_ceil_itv/andP. Qed. Lemma real_ceil_ge x : x \is Rreal -> x <= (ceil x)%:~R. Proof. by case/real_ceil_itv/andP. Qed. Lemma ceil_def x m : (m - 1)%:~R < x <= m%:~R -> ceil x = m. Proof. rewrite -ltrN2 -lerN2 andbC -!intrN opprD opprK ceilNfloor. by move=> /floor_def ->; rewrite opprK. Qed. (* TODO: rename to real_ceil_le_int, once the currently deprecated one has been removed *) Lemma real_ceil_le_int_tmp x n : x \is Rreal -> (ceil x <= n) = (x <= n%:~R). Proof. rewrite ceilNfloor lerNl -realN => /real_floor_ge_int_tmp ->. by rewrite intrN lerN2. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use real_ceil_le_int_tmp instead.")] Lemma real_ceil_le_int x n : x \is Rreal -> x <= n%:~R = (ceil x <= n). Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed. Lemma real_ceil_gt_int x n : x \is Rreal -> (n < ceil x) = (n%:~R < x). Proof. by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_ceil_le_int_tmp ?ltNge. Qed. Lemma real_ceil_eq x n : x \is Rreal -> (ceil x == n) = ((n - 1)%:~R < x <= n%:~R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: real_ceil_itv|exact: ceil_def]. Qed. (* TODO: rename to le_ceil, once the currently deprecated one has been removed *) Lemma le_ceil_tmp : {homo ceil : x y / x <= y}. Proof. by move=> x y lexy; rewrite !ceilNfloor lerN2 le_floor ?lerN2. Qed. Lemma intrKceil : cancel intr ceil. Proof. by move=> m; rewrite ceilNfloor -intrN intrKfloor opprK. Qed. Lemma intrEceil x : x \is a int_num = ((ceil x)%:~R == x). Proof. by rewrite -rpredN intrEfloor -eqr_oppLR -intrN -ceilNfloor. Qed. Lemma ceilK : {in int_num, cancel ceil intr}. Proof. by move=> z; rewrite intrEceil => /eqP. Qed. Lemma ceil0 : ceil 0 = 0. Proof. exact: intrKceil 0. Qed. Lemma ceil1 : ceil 1 = 1. Proof. exact: intrKceil 1. Qed. #[local] Hint Resolve ceil0 ceil1 : core. Lemma real_ceilDzr : {in int_num & Rreal, {morph ceil : x y / x + y}}. Proof. move=> x y x_int y_real. by rewrite ceilNfloor opprD real_floorDzr ?rpredN // opprD -!ceilNfloor. Qed. Lemma real_ceilDrz : {in Rreal & int_num, {morph ceil : x y / x + y}}. Proof. by move=> x y xr yz; rewrite addrC real_ceilDzr // addrC. Qed. Lemma ceilN : {in int_num, {morph ceil : x / - x}}. Proof. by move=> ? ?; rewrite !ceilNfloor !opprK floorN. Qed. Lemma ceilM : {in int_num &, {morph ceil : x y / x * y}}. Proof. by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKceil. Qed. Lemma ceilX n : {in int_num, {morph ceil : x / x ^+ n}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKceil. Qed. Lemma real_ceil_ge0 x : x \is Rreal -> (0 <= ceil x) = (-1 < x). Proof. by move=> ?; rewrite ceilNfloor oppr_ge0 real_floor_le0 ?realN 1?ltrNl. Qed. Lemma ceil_lt0 x : (ceil x < 0) = (x <= -1). Proof. by rewrite ceilNfloor oppr_lt0 floor_gt0 lerNr. Qed. Lemma real_ceil_le0 x : x \is Rreal -> (ceil x <= 0) = (x <= 0). Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed. Lemma ceil_gt0 x : (ceil x > 0) = (x > 0). Proof. by rewrite ceilNfloor oppr_gt0 floor_lt0 oppr_lt0. Qed. Lemma ceil_neq0 x : (ceil x != 0) = (x <= -1) || (x > 0). Proof. by rewrite ceilNfloor oppr_eq0 floor_neq0 oppr_lt0 lerNr orbC. Qed. Lemma real_ceil_floor x : x \is Rreal -> ceil x = floor x + (x \isn't a int_num). Proof. case Ix: (x \is a int_num) => Rx /=. by apply/eqP; rewrite addr0 ceilNfloor eqr_oppLR floorN. apply/ceil_def; rewrite addrK; move: (real_floor_itv Rx). by rewrite le_eqVlt -intrEfloor Ix /= => /andP[-> /ltW]. Qed. (* Relating Cnat and oldCnat. *) Lemma truncn_floor x : truncn x = if 0 <= x then `|floor x|%N else 0%N. Proof. move: (floorP x); rewrite truncEfloor realE. have [/le_floor|_]/= := boolP (0 <= x); first by rewrite floor0; case: floor. by case: ifP => [/le_floor|_ /eqP->//]; rewrite floor0; case: floor => [[]|]. Qed. (* trunc and nat_num *) Local Lemma truncnP x : if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N. Proof. rewrite truncn_floor. case: (boolP (0 <= x)) => //= /[dup] /le_floor + /ger0_real/real_floor_itv. by rewrite floor0; case: (floor x) => // n _; rewrite absz_nat addrC -intS. Qed. Lemma truncn_itv x : 0 <= x -> (truncn x)%:R <= x < (truncn x).+1%:R. Proof. by move=> x_ge0; move: (truncnP x); rewrite x_ge0. Qed. Lemma truncn_le x : (truncn x)%:R <= x = (0 <= x). Proof. by case: ifP (truncnP x) => [+ /andP[] | + /eqP->//]. Qed. Lemma real_truncnS_gt x : x \is Rreal -> x < (truncn x).+1%:R. Proof. by move/real_ge0P => [/truncn_itv/andP[]|/lt_le_trans->]. Qed. Lemma truncn_def x n : n%:R <= x < n.+1%:R -> truncn x = n. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS. have/truncn_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n. by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x). Qed. Lemma truncn_ge_nat x n : 0 <= x -> (n <= truncn x)%N = (n%:R <= x). Proof. move=> /truncn_itv /andP[letx ltxt1]; apply/idP/idP => lenx. by apply: le_trans letx; rewrite ler_nat. by rewrite -ltnS -(ltr_nat R); apply: le_lt_trans ltxt1. Qed. Lemma truncn_gt_nat x n : (n < truncn x)%N = (n.+1%:R <= x). Proof. case: ifP (truncnP x) => [x0 _ | x0 /eqP->]; first by rewrite truncn_ge_nat. by rewrite ltn0; apply/esym/(contraFF _ x0)/le_trans. Qed. Lemma truncn_lt_nat x n : 0 <= x -> (truncn x < n)%N = (x < n%:R). Proof. by move=> ?; rewrite real_ltNge ?ger0_real// ltnNge truncn_ge_nat. Qed. Lemma real_truncn_le_nat x n : x \is Rreal -> (truncn x <= n)%N = (x < n.+1%:R). Proof. by move=> ?; rewrite real_ltNge// leqNgt truncn_gt_nat. Qed. Lemma truncn_eq x n : 0 <= x -> (truncn x == n) = (n%:R <= x < n.+1%:R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: truncn_itv|exact: truncn_def]. Qed. Lemma le_truncn : {homo truncn : x y / x <= y >-> (x <= y)%N}. Proof. move=> x y lexy; move: (truncnP x) (truncnP y). case: ifP => [x0 /andP[letx _] | x0 /eqP->//]. case: ifP => [y0 /andP[_] | y0 /eqP->]; [|by rewrite (le_trans x0 lexy) in y0]. by move=> /(le_lt_trans lexy) /(le_lt_trans letx); rewrite ltr_nat ltnS. Qed. Lemma natrK : cancel (GRing.natmul 1) truncn. Proof. by move=> m; apply: truncn_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed. Lemma natrEtruncn x : (x \is a nat_num) = ((truncn x)%:R == x). Proof. by apply/natrP/eqP => [[n ->]|<-]; [rewrite natrK | exists (truncn x)]. Qed. Lemma archi_boundP x : 0 <= x -> x < (bound x)%:R. Proof. move=> x_ge0; case/truncn_itv/andP: (normr_ge0 x) => _. exact/le_lt_trans/real_ler_norm/ger0_real. Qed. Lemma truncnK : {in nat_num, cancel truncn (GRing.natmul 1)}. Proof. by move=> x; rewrite natrEtruncn => /eqP. Qed. Lemma truncn0 : truncn 0 = 0%N. Proof. exact: natrK 0%N. Qed. Lemma truncn1 : truncn 1 = 1%N. Proof. exact: natrK 1%N. Qed. #[local] Hint Resolve truncn0 truncn1 : core. Lemma truncnD : {in nat_num & Rnneg, {morph truncn : x y / x + y >-> (x + y)%N}}. Proof. move=> _ y /natrP[n ->] y_ge0; apply: truncn_def. by rewrite -addnS !natrD !natrK lerD2l ltrD2l truncn_itv. Qed. Lemma truncnM : {in nat_num &, {morph truncn : x y / x * y >-> (x * y)%N}}. Proof. by move=> _ _ /natrP[n1 ->] /natrP[n2 ->]; rewrite -natrM !natrK. Qed. Lemma truncnX n : {in nat_num, {morph truncn : x / x ^+ n >-> (x ^ n)%N}}. Proof. by move=> _ /natrP[n1 ->]; rewrite -natrX !natrK. Qed. Lemma truncn_gt0 x : (0 < truncn x)%N = (1 <= x). Proof. case: ifP (truncnP x) => [x0 | x0 /eqP<-]; first by rewrite truncn_ge_nat. by rewrite ltnn; apply/esym/(contraFF _ x0)/le_trans. Qed. Lemma truncn0Pn x : reflect (truncn x = 0%N) (~~ (1 <= x)). Proof. by rewrite -truncn_gt0 -eqn0Ngt; apply: eqP. Qed. Lemma sum_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) -> (\sum_(i <- r | P i) truncn (F i))%:R = \sum_(i <- r | P i) F i. Proof. by rewrite natr_sum => natr; apply: eq_bigr => i /natr /truncnK. Qed. Lemma prod_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) -> (\prod_(i <- r | P i) truncn (F i))%:R = \prod_(i <- r | P i) F i. Proof. by rewrite natr_prod => natr; apply: eq_bigr => i /natr /truncnK. Qed. Lemma natr_sum_eq1 (I : finType) (P : pred I) (F : I -> R) : (forall i, P i -> F i \is a nat_num) -> \sum_(i | P i) F i = 1 -> {i : I | [/\ P i, F i = 1 & forall j, j != i -> P j -> F j = 0]}. Proof. move=> natF /eqP; rewrite -sum_truncnK// -[1]/1%:R eqr_nat => /sum_nat_eq1 exi. have [i /and3P[Pi /eqP f1 /forallP a]] : {i : I | [&& P i, truncn (F i) == 1 & [forall j : I, ((j != i) ==> P j ==> (truncn (F j) == 0))]]}. apply/sigW; have [i [Pi /eqP f1 a]] := exi; exists i; apply/and3P; split=> //. by apply/forallP => j; apply/implyP => ji; apply/implyP => Pj; apply/eqP/a. exists i; split=> [//||j ji Pj]; rewrite -[LHS]truncnK ?natF ?f1//; apply/eqP. by rewrite -[0]/0%:R eqr_nat; apply: implyP Pj; apply: implyP ji; apply: a. Qed. Lemma natr_mul_eq1 x y : x \is a nat_num -> y \is a nat_num -> (x * y == 1) = (x == 1) && (y == 1). Proof. by do 2!move/truncnK <-; rewrite -natrM !pnatr_eq1 muln_eq1. Qed. Lemma natr_prod_eq1 (I : finType) (P : pred I) (F : I -> R) : (forall i, P i -> F i \is a nat_num) -> \prod_(i | P i) F i = 1 -> forall i, P i -> F i = 1. Proof. move=> natF /eqP; rewrite -prod_truncnK// -[1]/1%:R eqr_nat prod_nat_seq_eq1. move/allP => a i Pi; apply/eqP; rewrite -[F i]truncnK ?natF// eqr_nat. by apply: implyP Pi; apply: a; apply: mem_index_enum. Qed. (* predCmod *) Variables (U V : lmodType R) (f : {additive U -> V}). Lemma raddfZ_nat a u : a \is a nat_num -> f (a *: u) = a *: f u. Proof. by move=> /natrP[n ->]; apply: raddfZnat. Qed. Lemma rpredZ_nat (S : addrClosed V) : {in nat_num & S, forall z u, z *: u \in S}. Proof. by move=> _ u /natrP[n ->]; apply: rpredZnat. Qed. Lemma raddfZ_int a u : a \is a int_num -> f (a *: u) = a *: f u. Proof. by move=> /intrP[m ->]; rewrite !scaler_int raddfMz. Qed. Lemma rpredZ_int (S : zmodClosed V) : {in int_num & S, forall z u, z *: u \in S}. Proof. by move=> _ u /intrP[m ->] ?; rewrite scaler_int rpredMz. Qed. (* autC *) Implicit Type nu : {rmorphism R -> R}. Lemma aut_natr nu : {in nat_num, nu =1 id}. Proof. by move=> _ /natrP[n ->]; apply: rmorph_nat. Qed. Lemma aut_intr nu : {in int_num, nu =1 id}. Proof. by move=> _ /intrP[m ->]; apply: rmorph_int. Qed. End ArchiNumDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_itv.")] Notation trunc_itv := truncn_itv. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_def.")] Notation trunc_def := truncn_def. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnK.")] Notation truncK := truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0.")] Notation trunc0 := truncn0. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn1.")] Notation trunc1 := truncn1. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnD.")] Notation truncD := truncnD. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnM.")] Notation truncM := truncnM. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnX.")] Notation truncX := truncnX. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_gt0.")] Notation trunc_gt0 := truncn_gt0. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0Pn.")] Notation trunc0Pn := truncn0Pn. #[deprecated(since="mathcomp 2.4.0", note="Renamed to sum_truncnK.")] Notation sum_truncK := sum_truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to prod_truncnK.")] Notation prod_truncK := prod_truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_floor.")] Notation trunc_floor := truncn_floor. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floor_le.")] Notation real_ge_floor := real_floor_le. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floorD1_gt.")] Notation real_lt_succ_floor := real_floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceilB1_lt.")] Notation real_gt_pred_ceil := real_floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceil_ge.")] Notation real_le_ceil := real_ceil_ge. #[deprecated(since="mathcomp 2.4.0", note="Renamed to le_floor.")] Notation floor_le := le_floor. #[deprecated(since="mathcomp 2.4.0", note="Renamed to le_ceil.")] Notation ceil_le := le_ceil_tmp. #[deprecated(since="mathcomp 2.4.0", note="Renamed to natrEtruncn.")] Notation natrE := natrEtruncn. Arguments natrK {R} _%_N. Arguments intrKfloor {R}. Arguments intrKceil {R}. Arguments natrP {R x}. Arguments intrP {R x}. #[global] Hint Resolve truncn0 truncn1 : core. #[global] Hint Resolve floor0 floor1 : core. #[global] Hint Resolve ceil0 ceil1 : core. #[global] Hint Extern 0 (is_true (_%:R \is a nat_num)) => apply: natr_nat : core. #[global] Hint Extern 0 (is_true (_%:R \in nat_num_subdef)) => apply: natr_nat : core. #[global] Hint Extern 0 (is_true (_%:~R \is a int_num)) => apply: intr_int : core. #[global] Hint Extern 0 (is_true (_%:~R \in int_num_subdef)) => apply: intr_int : core. #[global] Hint Extern 0 (is_true (_%:R \is a int_num)) => apply: natr_int : core. #[global] Hint Extern 0 (is_true (_%:R \in int_num_subdef)) => apply: natr_int : core. #[global] Hint Extern 0 (is_true (0 \is a nat_num)) => apply: nat_num0 : core. #[global] Hint Extern 0 (is_true (0 \in nat_num_subdef)) => apply: nat_num0 : core. #[global] Hint Extern 0 (is_true (1 \is a nat_num)) => apply: nat_num1 : core. #[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: nat_num1 : core. #[global] Hint Extern 0 (is_true (0 \is a int_num)) => apply: int_num0 : core. #[global] Hint Extern 0 (is_true (0 \in int_num_subdef)) => apply: int_num0 : core. #[global] Hint Extern 0 (is_true (1 \is a int_num)) => apply: int_num1 : core. #[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: int_num1 : core. Section ArchiRealDomainTheory. Variables (R : archiRealDomainType). Implicit Type x : R. Lemma upper_nthrootP x i : (bound x <= i)%N -> x < 2%:R ^+ i. Proof. case/truncn_itv/andP: (normr_ge0 x) => _ /ltr_normlW xlt le_b_i. by rewrite (lt_le_trans xlt) // -natrX ler_nat (ltn_trans le_b_i) // ltn_expl. Qed. Lemma truncnS_gt x : x < (truncn x).+1%:R. Proof. exact: real_truncnS_gt. Qed. Lemma truncn_le_nat x n : (truncn x <= n)%N = (x < n.+1%:R). Proof. exact: real_truncn_le_nat. Qed. Lemma floor_itv x : (floor x)%:~R <= x < (floor x + 1)%:~R. Proof. exact: real_floor_itv. Qed. (* TODO: rename to floor_le, once the deprecated one has been removed *) Lemma floor_le_tmp x : (floor x)%:~R <= x. Proof. exact: real_floor_le. Qed. Lemma floorD1_gt x : x < (floor x + 1)%:~R. Proof. exact: real_floorD1_gt. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use floor_ge_int_tmp instead.")] Lemma floor_ge_int x n : n%:~R <= x = (n <= floor x). Proof. by rewrite real_floor_ge_int_tmp. Qed. (* TODO: rename to floor_ge_int, once the currently deprecated one has been removed *) Lemma floor_ge_int_tmp x n : (n <= floor x) = (n%:~R <= x). Proof. exact: real_floor_ge_int_tmp. Qed. Lemma floor_lt_int x n : (floor x < n) = (x < n%:~R). Proof. exact: real_floor_lt_int. Qed. Lemma floor_eq x n : (floor x == n) = (n%:~R <= x < (n + 1)%:~R). Proof. exact: real_floor_eq. Qed. Lemma floorDzr : {in @int_num R, {morph floor : x y / x + y}}. Proof. by move=> x xz y; apply/real_floorDzr/num_real. Qed. Lemma floorDrz x y : y \is a int_num -> floor (x + y) = floor x + floor y. Proof. by move=> yz; apply/real_floorDrz/yz/num_real. Qed. Lemma floor_ge0 x : (0 <= floor x) = (0 <= x). Proof. exact: real_floor_ge0. Qed. Lemma floor_le0 x : (floor x <= 0) = (x < 1). Proof. exact: real_floor_le0. Qed. Lemma ceil_itv x : (ceil x - 1)%:~R < x <= (ceil x)%:~R. Proof. exact: real_ceil_itv. Qed. Lemma ceilB1_lt x : (ceil x - 1)%:~R < x. Proof. exact: real_ceilB1_lt. Qed. Lemma ceil_ge x : x <= (ceil x)%:~R. Proof. exact: real_ceil_ge. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use ceil_le_int_tmp instead.")] Lemma ceil_le_int x n : x <= n%:~R = (ceil x <= n). Proof. by rewrite real_ceil_le_int_tmp. Qed. (* TODO: rename to ceil_le_int, once the currently deprecated one has been removed *) Lemma ceil_le_int_tmp x n : (ceil x <= n) = (x <= n%:~R). Proof. exact: real_ceil_le_int_tmp. Qed. Lemma ceil_gt_int x n : (n < ceil x) = (n%:~R < x). Proof. exact: real_ceil_gt_int. Qed. Lemma ceil_eq x n : (ceil x == n) = ((n - 1)%:~R < x <= n%:~R). Proof. exact: real_ceil_eq. Qed. Lemma ceilDzr : {in @int_num R, {morph ceil : x y / x + y}}. Proof. by move=> x xz y; apply/real_ceilDzr/num_real. Qed. Lemma ceilDrz x y : y \is a int_num -> ceil (x + y) = ceil x + ceil y. Proof. by move=> yz; apply/real_ceilDrz/yz/num_real. Qed. Lemma ceil_ge0 x : (0 <= ceil x) = (-1 < x). Proof. exact: real_ceil_ge0. Qed. Lemma ceil_le0 x : (ceil x <= 0) = (x <= 0). Proof. exact: real_ceil_le0. Qed. Lemma ceil_floor x : ceil x = floor x + (x \isn't a int_num). Proof. exact: real_ceil_floor. Qed. End ArchiRealDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Renamed to floor_le_tmp.")] Notation ge_floor := floor_le_tmp. #[deprecated(since="mathcomp 2.4.0", note="Renamed to floorD1_gt.")] Notation lt_succ_floor := floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to ceilB1_lt.")] Notation gt_pred_ceil := ceilB1_lt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to ceil_ge.")] Notation le_ceil := ceil_ge. Section ArchiNumFieldTheory. (* autLmodC *) Variables (R : archiNumFieldType) (nu : {rmorphism R -> R}). Lemma natr_aut x : (nu x \is a nat_num) = (x \is a nat_num). Proof. by apply/idP/idP=> /[dup] ? /(aut_natr nu) => [/fmorph_inj <-| ->]. Qed. Lemma intr_aut x : (nu x \is a int_num) = (x \is a int_num). Proof. by rewrite !intrE -rmorphN !natr_aut. Qed. End ArchiNumFieldTheory. Section ArchiClosedFieldTheory. Variable R : archiClosedFieldType. Implicit Type x : R. Lemma conj_natr x : x \is a nat_num -> x^* = x. Proof. by move/Rreal_nat/CrealP. Qed. Lemma conj_intr x : x \is a int_num -> x^* = x. Proof. by move/Rreal_int/CrealP. Qed. End ArchiClosedFieldTheory. Section ZnatPred. Lemma Znat_def (n : int) : (n \is a nat_num) = (0 <= n). Proof. by []. Qed. Lemma ZnatP (m : int) : reflect (exists n : nat, m = n) (m \is a nat_num). Proof. by case: m => m; constructor; [exists m | case]. Qed. End ZnatPred. End Theory. (* Factories *) HB.factory Record NumDomain_hasTruncn R of Num.NumDomain R := { trunc : R -> nat; nat_num : pred R; int_num : pred R; truncP : forall x, if 0 <= x then (trunc x)%:R <= x < (trunc x).+1%:R else trunc x == 0; natrE : forall x, nat_num x = ((trunc x)%:R == x); intrE : forall x, int_num x = nat_num x || nat_num (- x); }. #[deprecated(since="mathcomp 2.4.0", note="Use NumDomain_hasTruncn instead.")] Notation NumDomain_isArchimedean R := (NumDomain_hasTruncn R) (only parsing). Module NumDomain_isArchimedean. #[deprecated(since="mathcomp 2.4.0", note="Use NumDomain_hasTruncn.Build instead.")] Notation Build T U := (NumDomain_hasTruncn.Build T U) (only parsing). End NumDomain_isArchimedean. HB.builders Context R of NumDomain_hasTruncn R. Fact trunc_itv x : 0 <= x -> (trunc x)%:R <= x < (trunc x).+1%:R. Proof. by move=> x_ge0; move: (truncP x); rewrite x_ge0. Qed. Definition floor (x : R) : int := if 0 <= x then Posz (trunc x) else if x < 0 then - Posz (trunc (- x) + ~~ int_num x) else 0. Fact floorP x : if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0. Proof. rewrite /floor intrE !natrE negb_or realE. case: (comparableP x 0) (@trunc_itv x) => //=; try by rewrite -PoszD addn1 -pmulrn => _ ->. move=> x_lt0 _; move: (truncP x); rewrite lt_geF // => /eqP ->. rewrite gt_eqF //=; move: x_lt0. rewrite [_ + 1]addrC -opprB !intrN lerNl ltrNr andbC -oppr_gt0. move: {x}(- x) => x x_gt0; rewrite PoszD -addrA -PoszD. have ->: Posz ((trunc x)%:R != x) - 1 = - Posz ((trunc x)%:R == x) by case: eqP. have := trunc_itv (ltW x_gt0); rewrite le_eqVlt. case: eqVneq => /=; last first. by rewrite subr0 addn1 -!pmulrn => _ /andP[-> /ltW ->]. by rewrite intrB mulr1z addn0 -!pmulrn => -> _; rewrite gtrBl lexx andbT. Qed. Fact truncE x : trunc x = if floor x is Posz n then n else 0. Proof. rewrite /floor. case: (comparableP x 0) (truncP x) => [+ /eqP ->| |_ /eqP ->|] //=. by case: (_ + _)%N. Qed. Fact trunc_def x n : n%:R <= x < n.+1%:R -> trunc x = n. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS. have/trunc_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n. by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x). Qed. Fact natrK : cancel (GRing.natmul 1) trunc. Proof. by move=> m; apply: trunc_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed. Fact intrP x : reflect (exists n, x = n%:~R) (int_num x). Proof. rewrite intrE !natrE; apply: (iffP idP) => [|[n ->]]; last first. by case: n => n; rewrite ?NegzE ?opprK natrK eqxx // orbT. rewrite -eqr_oppLR !pmulrn -intrN. by move=> /orP[] /eqP<-; [exists (trunc x) | exists (- Posz (trunc (- x)))]. Qed. Fact natrP x : reflect (exists n, x = n%:R) (nat_num x). Proof. rewrite natrE. by apply: (iffP eqP) => [<-|[n ->]]; [exists (trunc x) | rewrite natrK]. Qed. HB.instance Definition _ := @NumDomain_hasFloorCeilTruncn.Build R floor _ trunc int_num nat_num floorP (fun=> erefl) truncE intrP natrP. HB.end. HB.factory Record NumDomain_bounded_isArchimedean R of Num.NumDomain R := { archi_bound_subproof : Num.archimedean_axiom R }. HB.builders Context R of NumDomain_bounded_isArchimedean R. Implicit Type x : R. Definition bound x := sval (sigW (archi_bound_subproof x)). Lemma boundP x : 0 <= x -> x < (bound x)%:R. Proof. by move/ger0_norm=> {1}<-; rewrite /bound; case: (sigW _). Qed. Fact truncn_subproof x : {m | 0 <= x -> m%:R <= x < m.+1%:R }. Proof. have [Rx | _] := boolP (0 <= x); last by exists 0%N. have/ex_minnP[n lt_x_n1 min_n]: exists n, x < n.+1%:R. by exists (bound x); rewrite (lt_trans (boundP Rx)) ?ltr_nat. exists n => _; rewrite {}lt_x_n1 andbT; case: n min_n => //= n min_n. rewrite real_leNgt ?rpred_nat ?ger0_real //; apply/negP => /min_n. by rewrite ltnn. Qed. Definition truncn x := if 0 <= x then sval (truncn_subproof x) else 0%N. Lemma truncnP x : if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N. Proof. rewrite /truncn; case: truncn_subproof => // n hn. by case: ifP => x_ge0; rewrite ?(ifT _ _ x_ge0) ?(ifF _ _ x_ge0) // hn. Qed. HB.instance Definition _ := NumDomain_hasTruncn.Build R truncnP (fun => erefl) (fun => erefl). HB.end. Module Exports. HB.reexport. End Exports. (* Not to pollute the local namespace, we define Num.nat and Num.int here. *) Notation nat := nat_num. Notation int := int_num. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain instead.")] Notation ArchiDomain T := (ArchiRealDomain T). Module ArchiDomain. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.type instead.")] Notation type := ArchiRealDomain.type. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.copy instead.")] Notation copy T C := (ArchiRealDomain.copy T C). #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.on instead.")] Notation on T := (ArchiRealDomain.on T). End ArchiDomain. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField instead.")] Notation ArchiField T := (ArchiRealField T). Module ArchiField. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.type instead.")] Notation type := ArchiRealField.type. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.copy instead.")] Notation copy T C := (ArchiRealField.copy T C). #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.on instead.")] Notation on T := (ArchiRealField.on T). End ArchiField. #[deprecated(since="mathcomp 2.3.0", note="Use real_floorDzr instead.")] Notation floorD := real_floorDzr. #[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")] Notation ceilD := real_ceilDzr. #[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")] Notation real_ceilD := real_ceilDzr. End Num. Export Num.Exports. #[deprecated(since="mathcomp 2.3.0", note="Use archiRealDomainType instead.")] Notation archiDomainType := archiRealDomainType (only parsing). #[deprecated(since="mathcomp 2.3.0", note="Use archiRealFieldType instead.")] Notation archiFieldType := archiRealFieldType (only parsing).
UnivLE.lean
/- Copyright (c) 2023 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Logic.UnivLE import Mathlib.CategoryTheory.EssentialImage import Mathlib.CategoryTheory.Types /-! # Universe inequalities and essential surjectivity of `uliftFunctor`. We show `UnivLE.{max u v, v} ↔ EssSurj (uliftFunctor.{u, v} : Type v ⥤ Type max u v)`. -/ open CategoryTheory universe u v noncomputable section theorem UnivLE.ofEssSurj (w : (uliftFunctor.{u, v} : Type v ⥤ Type max u v).EssSurj) : UnivLE.{max u v, v} where small α := by obtain ⟨a', ⟨m⟩⟩ := w.mem_essImage α exact ⟨a', ⟨(Iso.toEquiv m).symm.trans Equiv.ulift⟩⟩ instance EssSurj.ofUnivLE [UnivLE.{max u v, v}] : (uliftFunctor.{u, v} : Type v ⥤ Type max u v).EssSurj where mem_essImage α := ⟨Shrink α, ⟨Equiv.toIso (Equiv.ulift.trans (equivShrink α).symm)⟩⟩ theorem UnivLE_iff_essSurj : UnivLE.{max u v, v} ↔ (uliftFunctor.{u, v} : Type v ⥤ Type max u v).EssSurj := ⟨fun _ => inferInstance, fun w => UnivLE.ofEssSurj w⟩ instance [UnivLE.{max u v, v}] : uliftFunctor.{u, v}.IsEquivalence where def UnivLE.witness [UnivLE.{max u v, v}] : Type u ⥤ Type v := uliftFunctor.{v, u} ⋙ (uliftFunctor.{u, v}).inv instance [UnivLE.{max u v, v}] : UnivLE.witness.{u, v}.Faithful := inferInstanceAs <| Functor.Faithful (_ ⋙ _) instance [UnivLE.{max u v, v}] : UnivLE.witness.{u, v}.Full := inferInstanceAs <| Functor.Full (_ ⋙ _)
Span.lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.LinearAlgebra.Finsupp.Defs import Mathlib.LinearAlgebra.Span.Basic /-! # Finitely supported functions and spans ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] @[simp] theorem ker_lsingle (a : α) : ker (lsingle a : M →ₗ[R] α →₀ M) = ⊥ := ker_eq_bot_of_injective (single_injective a) theorem lsingle_range_le_ker_lapply (s t : Set α) (h : Disjoint s t) : ⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) ≤ ⨅ a ∈ t, ker (lapply a : (α →₀ M) →ₗ[R] M) := by refine iSup_le fun a₁ => iSup_le fun h₁ => range_le_iff_comap.2 ?_ simp only [(ker_comp _ _).symm, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf] intro b _ a₂ h₂ have : a₁ ≠ a₂ := fun eq => h.le_bot ⟨h₁, eq.symm ▸ h₂⟩ exact single_eq_of_ne this theorem iInf_ker_lapply_le_bot : ⨅ a, ker (lapply a : (α →₀ M) →ₗ[R] M) ≤ ⊥ := by simp only [SetLike.le_def, mem_iInf, mem_ker, mem_bot, lapply_apply] exact fun a h => Finsupp.ext h theorem iSup_lsingle_range : ⨆ a, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) = ⊤ := by refine eq_top_iff.2 <| SetLike.le_def.2 fun f _ => ?_ rw [← sum_single f] exact sum_mem fun a _ => Submodule.mem_iSup_of_mem a ⟨_, rfl⟩ theorem disjoint_lsingle_lsingle (s t : Set α) (hs : Disjoint s t) : Disjoint (⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) (⨆ a ∈ t, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) := by refine (Disjoint.mono (lsingle_range_le_ker_lapply s sᶜ disjoint_compl_right) (lsingle_range_le_ker_lapply t tᶜ disjoint_compl_right)) ?_ rw [disjoint_iff_inf_le] refine le_trans (le_iInf fun i => ?_) iInf_ker_lapply_le_bot classical by_cases his : i ∈ s · by_cases hit : i ∈ t · exact (hs.le_bot ⟨his, hit⟩).elim exact inf_le_of_right_le (iInf_le_of_le i <| iInf_le _ hit) exact inf_le_of_left_le (iInf_le_of_le i <| iInf_le _ his) theorem span_single_image (s : Set M) (a : α) : Submodule.span R (single a '' s) = (Submodule.span R s).map (lsingle a : M →ₗ[R] α →₀ M) := by rw [← span_image]; rfl end Finsupp variable {R : Type*} {M : Type*} {N : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] open Finsupp theorem Submodule.exists_finset_of_mem_iSup {ι : Sort _} (p : ι → Submodule R M) {m : M} (hm : m ∈ ⨆ i, p i) : ∃ s : Finset ι, m ∈ ⨆ i ∈ s, p i := by have := CompleteLattice.IsCompactElement.exists_finset_of_le_iSup (Submodule R M) (Submodule.singleton_span_isCompactElement m) p simp only [Submodule.span_singleton_le_iff_mem] at this exact this hm /-- `Submodule.exists_finset_of_mem_iSup` as an `iff` -/ theorem Submodule.mem_iSup_iff_exists_finset {ι : Sort _} {p : ι → Submodule R M} {m : M} : (m ∈ ⨆ i, p i) ↔ ∃ s : Finset ι, m ∈ ⨆ i ∈ s, p i := ⟨Submodule.exists_finset_of_mem_iSup p, fun ⟨_, hs⟩ => iSup_mono (fun i => (iSup_const_le : _ ≤ p i)) hs⟩ theorem Submodule.mem_sSup_iff_exists_finset {S : Set (Submodule R M)} {m : M} : m ∈ sSup S ↔ ∃ s : Finset (Submodule R M), ↑s ⊆ S ∧ m ∈ ⨆ i ∈ s, i := by rw [sSup_eq_iSup, iSup_subtype', Submodule.mem_iSup_iff_exists_finset] refine ⟨fun ⟨s, hs⟩ ↦ ⟨s.map (Function.Embedding.subtype S), ?_, ?_⟩, fun ⟨s, hsS, hs⟩ ↦ ⟨s.preimage (↑) Subtype.coe_injective.injOn, ?_⟩⟩ · simpa using fun x _ ↦ x.property · suffices m ∈ ⨆ (i) (hi : i ∈ S) (_ : ⟨i, hi⟩ ∈ s), i by simpa rwa [iSup_subtype'] · have : ⨆ (i) (_ : i ∈ S ∧ i ∈ s), i = ⨆ (i) (_ : i ∈ s), i := by convert rfl; aesop simpa only [Finset.mem_preimage, iSup_subtype, iSup_and', this]
fingraph.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat. From mathcomp Require Import seq path fintype. (******************************************************************************) (* This file develops the theory of finite graphs represented by an "edge" *) (* relation over a finType T; this mainly amounts to the theory of the *) (* transitive closure of such relations. *) (* For g : T -> seq T, e : rel T and f : T -> T we define: *) (* grel g == the adjacency relation y \in g x of the graph g. *) (* rgraph e == the graph (x |-> enum (e x)) of the relation e. *) (* dfs g n v x == the list of points traversed by a depth-first search of *) (* the g, at depth n, starting from x, and avoiding v. *) (* dfs_path g v x y <-> there is a path from x to y in g \ v. *) (* connect e == the reflexive transitive closure of e (computed by dfs). *) (* connect_sym e <-> connect e is symmetric, hence an equivalence relation. *) (* root e x == a representative of connect e x, which is the component *) (* of x in the transitive closure of e. *) (* roots e == the codomain predicate of root e. *) (* n_comp e a == the number of e-connected components of a, when a is *) (* e-closed and connect e is symmetric. *) (* equivalence classes of connect e if connect_sym e holds. *) (* closed e a == the collective predicate a is e-invariant. *) (* closure e a == the e-closure of a (the image of a under connect e). *) (* rel_adjunction h e e' a <-> in the e-closed domain a, h is the left part *) (* of an adjunction from e to another relation e'. *) (* fconnect f == connect (frel f), i.e., "connected under f iteration". *) (* froot f x == root (frel f) x, the root of the orbit of x under f. *) (* froots f == roots (frel f) == orbit representatives for f. *) (* orbit f x == lists the f-orbit of x. *) (* findex f x y == index of y in the f-orbit of x. *) (* order f x == size (cardinal) of the f-orbit of x. *) (* order_set f n == elements of f-order n. *) (* finv f == the inverse of f, if f is injective. *) (* := finv f x := iter (order x).-1 f x. *) (* fcard f a == number of orbits of f in a, provided a is f-invariant *) (* f is one-to-one. *) (* fclosed f a == the collective predicate a is f-invariant. *) (* fclosure f a == the closure of a under f iteration. *) (* fun_adjunction == rel_adjunction (frel f). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Definition grel (T : eqType) (g : T -> seq T) := [rel x y | y \in g x]. (* Decidable connectivity in finite types. *) Section Connect. Variable T : finType. Section Dfs. Variable g : T -> seq T. Implicit Type v w a : seq T. Fixpoint dfs n v x := if x \in v then v else if n is n'.+1 then foldl (dfs n') (x :: v) (g x) else v. Lemma subset_dfs n v a : v \subset foldl (dfs n) v a. Proof. elim: n a v => [|n IHn]; first by elim=> //= *; rewrite if_same. elim=> //= x a IHa v; apply: subset_trans {IHa}(IHa _); case: ifP => // _. by apply: subset_trans (IHn _ _); apply/subsetP=> y; apply: predU1r. Qed. Inductive dfs_path v x y : Prop := DfsPath p of path (grel g) x p & y = last x p & [disjoint x :: p & v]. Lemma dfs_pathP n x y v : #|T| <= #|v| + n -> y \notin v -> reflect (dfs_path v x y) (y \in dfs n v x). Proof. have dfs_id w z: z \notin w -> dfs_path w z z. by exists [::]; rewrite ?disjoint_has //= orbF. elim: n => [|n IHn] /= in x y v * => le_v'_n not_vy. rewrite addn0 (geq_leqif (subset_leqif_card (subset_predT _))) in le_v'_n. by rewrite predT_subset in not_vy. have [v_x | not_vx] := ifPn. by rewrite (negPf not_vy); right=> [] [p _ _]; rewrite disjoint_has /= v_x. set v1 := x :: v; set a := g x; have sub_dfs := subsetP (subset_dfs n _ _). have [-> | neq_yx] := eqVneq y x. by rewrite sub_dfs ?mem_head //; left; apply: dfs_id. apply: (@equivP (exists2 x1, x1 \in a & dfs_path v1 x1 y)); last first. split=> {IHn} [[x1 a_x1 [p g_p p_y]] | [p /shortenP[]]]. rewrite disjoint_has has_sym /= has_sym /= => /norP[_ not_pv]. by exists (x1 :: p); rewrite /= ?a_x1 // disjoint_has negb_or not_vx. case=> [_ _ _ eq_yx | x1 p1 /=]; first by case/eqP: neq_yx. case/andP=> a_x1 g_p1 /andP[not_p1x _] /subsetP p_p1 p1y not_pv. exists x1 => //; exists p1 => //. rewrite disjoint_sym disjoint_cons not_p1x disjoint_sym. by move: not_pv; rewrite disjoint_cons => /andP[_ /disjointWl->]. have{neq_yx not_vy}: y \notin v1 by apply/norP. have{le_v'_n not_vx}: #|T| <= #|v1| + n by rewrite cardU1 not_vx addSnnS. elim: {x v}a v1 => [|x a IHa] v /= le_v'_n not_vy. by rewrite (negPf not_vy); right=> [] []. set v2 := dfs n v x; have v2v: v \subset v2 := subset_dfs n v [:: x]. have [v2y | not_v2y] := boolP (y \in v2). by rewrite sub_dfs //; left; exists x; [apply: mem_head | apply: IHn]. apply: {IHa}(equivP (IHa _ _ not_v2y)). by rewrite (leq_trans le_v'_n) // leq_add2r subset_leq_card. split=> [] [x1 a_x1 [p g_p p_y not_pv]]. exists x1; [exact: predU1r | exists p => //]. by rewrite disjoint_sym (disjointWl v2v) // disjoint_sym. suffices not_p1v2: [disjoint x1 :: p & v2]. case/predU1P: a_x1 => [def_x1 | ]; last by exists x1; last exists p. case/pred0Pn: not_p1v2; exists x; rewrite /= def_x1 mem_head /=. suffices not_vx: x \notin v by apply/IHn; last apply: dfs_id. by move: not_pv; rewrite disjoint_cons def_x1 => /andP[]. apply: contraR not_v2y => /pred0Pn[x2 /andP[/= p_x2 v2x2]]. case/splitPl: p_x2 p_y g_p not_pv => p0 p2 p0x2. rewrite last_cat cat_path -cat_cons lastI cat_rcons {}p0x2 => p2y /andP[_ g_p2]. rewrite disjoint_cat disjoint_cons => /and3P[{p0}_ not_vx2 not_p2v]. have{not_vx2 v2x2} [p1 g_p1 p1_x2 not_p1v] := IHn _ _ v le_v'_n not_vx2 v2x2. apply/IHn=> //; exists (p1 ++ p2); rewrite ?cat_path ?last_cat -?p1_x2 ?g_p1 //. by rewrite -cat_cons disjoint_cat not_p1v. Qed. Lemma dfsP x y : reflect (exists2 p, path (grel g) x p & y = last x p) (y \in dfs #|T| [::] x). Proof. apply: (iffP (dfs_pathP _ _ _)); rewrite ?card0 // => [] [p]; exists p => //. by rewrite disjoint_sym disjoint0. Qed. End Dfs. Variable e : rel T. Definition rgraph x := enum (e x). Lemma rgraphK : grel rgraph =2 e. Proof. by move=> x y; rewrite /= mem_enum. Qed. Definition connect : rel T := [rel x y | y \in dfs rgraph #|T| [::] x]. Canonical connect_app_pred x := ApplicativePred (connect x). Lemma connectP x y : reflect (exists2 p, path e x p & y = last x p) (connect x y). Proof. apply: (equivP (dfsP _ x y)). by split=> [] [p e_p ->]; exists p => //; rewrite (eq_path rgraphK) in e_p *. Qed. Lemma connect_trans : transitive connect. Proof. move=> x y z /connectP[p e_p ->] /connectP[q e_q ->]; apply/connectP. by exists (p ++ q); rewrite ?cat_path ?e_p ?last_cat. Qed. Lemma connect0 x : connect x x. Proof. by apply/connectP; exists [::]. Qed. Lemma eq_connect0 x y : x = y -> connect x y. Proof. by move->; apply: connect0. Qed. Lemma connect1 x y : e x y -> connect x y. Proof. by move=> e_xy; apply/connectP; exists [:: y]; rewrite /= ?e_xy. Qed. Lemma path_connect x p : path e x p -> subpred [in x :: p] (connect x). Proof. move=> e_p y p_y; case/splitPl: p / p_y e_p => p q <-. by rewrite cat_path => /andP[e_p _]; apply/connectP; exists p. Qed. Lemma connect_cycle p : cycle e p -> {in p &, forall x y, connect x y}. Proof. move=> e_p x y /rot_to[i q rip]; rewrite -(mem_rot i) rip => yqx. have /= : cycle e (x :: q) by rewrite -rip rot_cycle. case/splitPl: yqx => r s lxr; rewrite rcons_cat cat_path => /andP[xr _]. by apply/connectP; exists r. Qed. Definition root x := odflt x (pick (connect x)). Definition roots : pred T := fun x => root x == x. Canonical roots_pred := ApplicativePred roots. Definition n_comp_mem (m_a : mem_pred T) := #|predI roots m_a|. Lemma connect_root x : connect x (root x). Proof. by rewrite /root; case: pickP; rewrite ?connect0. Qed. Definition connect_sym := symmetric connect. Hypothesis sym_e : connect_sym. Lemma same_connect : left_transitive connect. Proof. exact: sym_left_transitive connect_trans. Qed. Lemma same_connect_r : right_transitive connect. Proof. exact: sym_right_transitive connect_trans. Qed. Lemma same_connect1 x y : e x y -> connect x =1 connect y. Proof. by move/connect1; apply: same_connect. Qed. Lemma same_connect1r x y : e x y -> connect^~ x =1 connect^~ y. Proof. by move/connect1; apply: same_connect_r. Qed. Lemma rootP x y : reflect (root x = root y) (connect x y). Proof. apply: (iffP idP) => e_xy. by rewrite /root -(eq_pick (same_connect e_xy)); case: pickP e_xy => // ->. by apply: (connect_trans (connect_root x)); rewrite e_xy sym_e connect_root. Qed. Lemma root_root x : root (root x) = root x. Proof. exact/esym/rootP/connect_root. Qed. Lemma roots_root x : roots (root x). Proof. exact/eqP/root_root. Qed. Lemma root_connect x y : (root x == root y) = connect x y. Proof. exact: sameP eqP (rootP x y). Qed. Definition closed_mem m_a := forall x y, e x y -> in_mem x m_a = in_mem y m_a. Definition closure_mem m_a : pred T := fun x => ~~ disjoint (mem (connect x)) m_a. End Connect. Arguments rgraphK [T]. #[global] Hint Resolve connect0 : core. Notation n_comp e a := (n_comp_mem e (mem a)). Notation closed e a := (closed_mem e (mem a)). Notation closure e a := (closure_mem e (mem a)). Prenex Implicits connect root roots. Arguments dfsP {T g x y}. Arguments connectP {T e x y}. Arguments rootP [T e] _ {x y}. Notation fconnect f := (connect (coerced_frel f)). Notation froot f := (root (coerced_frel f)). Notation froots f := (roots (coerced_frel f)). Notation fcard_mem f := (n_comp_mem (coerced_frel f)). Notation fcard f a := (fcard_mem f (mem a)). Notation fclosed f a := (closed (coerced_frel f) a). Notation fclosure f a := (closure (coerced_frel f) a). Section EqConnect. Variable T : finType. Implicit Types (e : rel T) (a : {pred T}). Lemma connect_sub e e' : subrel e (connect e') -> subrel (connect e) (connect e'). Proof. move=> e'e x _ /connectP[p e_p ->]; elim: p x e_p => //= y p IHp x /andP[exy]. by move/IHp; apply: connect_trans; apply: e'e. Qed. Lemma relU_sym e e' : connect_sym e -> connect_sym e' -> connect_sym (relU e e'). Proof. move=> sym_e sym_e'; apply: symmetric_from_pre => x _ /connectP[p e_p ->]. elim: p x e_p => //= y p IHp x /andP[e_xy /IHp{IHp}/connect_trans]; apply. case/orP: e_xy => /connect1; rewrite (sym_e, sym_e'); by apply: connect_sub y x => x y e_xy; rewrite connect1 //= e_xy ?orbT. Qed. Lemma eq_connect e e' : e =2 e' -> connect e =2 connect e'. Proof. move=> eq_e x y; apply/connectP/connectP=> [] [p e_p ->]; by exists p; rewrite // (eq_path eq_e) in e_p *. Qed. Arguments eq_connect [e e']. Lemma eq_n_comp e e' : connect e =2 connect e' -> n_comp_mem e =1 n_comp_mem e'. Proof. move=> eq_e [a]; apply: eq_card => x /=. by rewrite !inE /= /roots /root /= (eq_pick (eq_e x)). Qed. Lemma eq_n_comp_r {e} a a' : a =i a' -> n_comp e a = n_comp e a'. Proof. by move=> eq_a; apply: eq_card => x; rewrite inE /= eq_a. Qed. Lemma n_compC a e : n_comp e T = n_comp e a + n_comp e [predC a]. Proof. rewrite /n_comp_mem (eq_card (fun _ => andbT _)) -(cardID a); congr (_ + _). by apply: eq_card => x; rewrite !inE andbC. Qed. Lemma eq_root e e' : e =2 e' -> root e =1 root e'. Proof. by move=> eq_e x; rewrite /root (eq_pick (eq_connect eq_e x)). Qed. Lemma eq_roots e e' : e =2 e' -> roots e =1 roots e'. Proof. by move=> eq_e x; rewrite /roots (eq_root eq_e). Qed. Lemma connect_rev e : connect [rel x y | e y x] =2 [rel x y | connect e y x]. Proof. suff crev e': subrel (connect [rel x y | e' y x]) [rel x y | connect e' y x]. by move=> x y; apply/idP/idP; apply: crev. move=> x y /connectP[p e_p p_y]; apply/connectP. exists (rev (belast x p)); first by rewrite p_y rev_path. by rewrite -(last_cons x) -rev_rcons p_y -lastI rev_cons last_rcons. Qed. Lemma sym_connect_sym e : symmetric e -> connect_sym e. Proof. by move=> sym_e x y; rewrite (eq_connect sym_e) connect_rev. Qed. End EqConnect. Arguments eq_connect [T e e']. Arguments connect_rev [T]. Section Closure. Variables (T : finType) (e : rel T). Hypothesis sym_e : connect_sym e. Implicit Type a : {pred T}. Lemma same_connect_rev : connect e =2 connect [rel x y | e y x]. Proof. by move=> x y; rewrite sym_e connect_rev. Qed. Lemma intro_closed a : (forall x y, e x y -> x \in a -> y \in a) -> closed e a. Proof. move=> cl_a x y e_xy; apply/idP/idP=> [|a_y]; first exact: cl_a. have{x e_xy} /connectP[p e_p ->]: connect e y x by rewrite sym_e connect1. by elim: p y a_y e_p => //= y p IHp x a_x /andP[/cl_a/(_ a_x)]; apply: IHp. Qed. Lemma closed_connect a : closed e a -> forall x y, connect e x y -> (x \in a) = (y \in a). Proof. move=> cl_a x _ /connectP[p e_p ->]. by elim: p x e_p => //= y p IHp x /andP[/cl_a->]; apply: IHp. Qed. Lemma connect_closed x : closed e (connect e x). Proof. by move=> y z /connect1/same_connect_r; apply. Qed. Lemma predC_closed a : closed e a -> closed e [predC a]. Proof. by move=> cl_a x y /cl_a /[!inE] ->. Qed. Lemma closure_closed a : closed e (closure e a). Proof. apply: intro_closed => x y /connect1 e_xy; congr (~~ _). by apply: eq_disjoint; apply: same_connect. Qed. Lemma mem_closure a : {subset a <= closure e a}. Proof. by move=> x a_x; apply/existsP; exists x; rewrite !inE connect0. Qed. Lemma subset_closure a : a \subset closure e a. Proof. by apply/subsetP; apply: mem_closure. Qed. Lemma n_comp_closure2 x y : n_comp e (closure e (pred2 x y)) = (~~ connect e x y).+1. Proof. rewrite -(root_connect sym_e) -card2; apply: eq_card => z. apply/idP/idP=> [/andP[/eqP {2}<- /pred0Pn[t /andP[/= ezt exyt]]] |]. by case/pred2P: exyt => <-; rewrite (rootP sym_e ezt) !inE eqxx ?orbT. by case/pred2P=> ->; rewrite !inE roots_root //; apply/existsP; [exists x | exists y]; rewrite !inE eqxx ?orbT sym_e connect_root. Qed. Lemma n_comp_connect x : n_comp e (connect e x) = 1. Proof. rewrite -(card1 (root e x)); apply: eq_card => y. apply/andP/eqP => [[/eqP r_y /rootP-> //] | ->] /=. by rewrite inE connect_root roots_root. Qed. End Closure. Arguments same_connect_rev [T e]. Section Orbit. Variables (T : finType) (f : T -> T). Definition order x := #|fconnect f x|. Definition orbit x := traject f x (order x). Definition findex x y := index y (orbit x). Definition finv x := iter (order x).-1 f x. Lemma fconnect_iter n x : fconnect f x (iter n f x). Proof. apply/connectP. by exists (traject f (f x) n); [apply: fpath_traject | rewrite last_traject]. Qed. Lemma fconnect1 x : fconnect f x (f x). Proof. exact: (fconnect_iter 1). Qed. Lemma fconnect_finv x : fconnect f x (finv x). Proof. exact: fconnect_iter. Qed. Lemma orderSpred x : (order x).-1.+1 = order x. Proof. by rewrite /order (cardD1 x) [_ x _]connect0. Qed. Lemma size_orbit x : size (orbit x) = order x. Proof. exact: size_traject. Qed. Lemma looping_order x : looping f x (order x). Proof. apply: contraFT (ltnn (order x)); rewrite -looping_uniq => /card_uniqP. rewrite size_traject => <-; apply: subset_leq_card. by apply/subsetP=> _ /trajectP[i _ ->]; apply: fconnect_iter. Qed. Lemma fconnect_orbit x y : fconnect f x y = (y \in orbit x). Proof. apply/idP/idP=> [/connectP[_ /fpathP[m ->] ->] | /trajectP[i _ ->]]. by rewrite last_traject; apply/loopingP/looping_order. exact: fconnect_iter. Qed. Lemma in_orbit x : x \in orbit x. Proof. by rewrite -fconnect_orbit. Qed. Hint Resolve in_orbit : core. Lemma order_gt0 x : order x > 0. Proof. by rewrite -orderSpred. Qed. Hint Resolve order_gt0 : core. Lemma orbit_uniq x : uniq (orbit x). Proof. rewrite /orbit -orderSpred looping_uniq; set n := (order x).-1. apply: contraFN (ltnn n) => /trajectP[i lt_i_n eq_fnx_fix]. rewrite orderSpred -(size_traject f x n). apply: (leq_trans (subset_leq_card _) (card_size _)); apply/subsetP=> z. rewrite inE fconnect_orbit => /trajectP[j le_jn ->{z}]. rewrite -orderSpred -/n ltnS leq_eqVlt in le_jn. by apply/trajectP; case/predU1P: le_jn => [->|]; [exists i | exists j]. Qed. Lemma findex_max x y : fconnect f x y -> findex x y < order x. Proof. by rewrite [_ y]fconnect_orbit -index_mem size_orbit. Qed. Lemma findex_iter x i : i < order x -> findex x (iter i f x) = i. Proof. move=> lt_ix; rewrite -(nth_traject f lt_ix) /findex index_uniq ?orbit_uniq //. by rewrite size_orbit. Qed. Lemma iter_findex x y : fconnect f x y -> iter (findex x y) f x = y. Proof. rewrite [_ y]fconnect_orbit => fxy; pose i := index y (orbit x). have lt_ix: i < order x by rewrite -size_orbit index_mem. by rewrite -(nth_traject f lt_ix) nth_index. Qed. Lemma findex0 x : findex x x = 0. Proof. by rewrite /findex /orbit -orderSpred /= eqxx. Qed. Lemma findex_eq0 x y : (findex x y == 0) = (x == y). Proof. by rewrite /findex /orbit -orderSpred /=; case: (x == y). Qed. Lemma fconnect_invariant (T' : eqType) (k : T -> T') : invariant f k =1 xpredT -> forall x y, fconnect f x y -> k x = k y. Proof. move=> eq_k_f x y /iter_findex <-; elim: {y}(findex x y) => //= n ->. by rewrite (eqP (eq_k_f _)). Qed. Lemma mem_orbit x : {homo f : y / y \in orbit x}. Proof. by move=> y; rewrite -!fconnect_orbit => /connect_trans->//; apply: fconnect1. Qed. Lemma image_orbit x : {subset image f (orbit x) <= orbit x}. Proof. by move=> _ /mapP[y yin ->]; apply: mem_orbit; rewrite ?mem_enum in yin. Qed. Section orbit_in. Variable S : {pred T}. Hypothesis f_in : {homo f : x / x \in S}. Hypothesis injf : {in S &, injective f}. Lemma finv_in : {homo finv : x / x \in S}. Proof. by move=> x xS; rewrite iter_in. Qed. Lemma f_finv_in : {in S, cancel finv f}. Proof. move=> x xS; move: (looping_order x) (orbit_uniq x). rewrite /looping /orbit -orderSpred looping_uniq /= /looping; set n := _.-1. case/predU1P=> // /trajectP[i lt_i_n]; rewrite -iterSr. by move=> /injf ->; rewrite ?(iter_in _ f_in) //; case/trajectP; exists i. Qed. Lemma finv_f_in : {in S, cancel f finv}. Proof. by move=> x xS; apply/injf; rewrite ?iter_in ?f_finv_in ?f_in. Qed. Lemma finv_inj_in : {in S &, injective finv}. Proof. by move=> x y xS yS q; rewrite -(f_finv_in xS) q f_finv_in. Qed. Lemma fconnect_sym_in : {in S &, forall x y, fconnect f x y = fconnect f y x}. Proof. suff Sf : {in S &, forall x y, fconnect f x y -> fconnect f y x}. by move=> *; apply/idP/idP=> /Sf->. move=> x _ xS _ /connectP [p f_p ->]; elim: p => //= y p IHp in x xS f_p *. case/andP: f_p => /eqP <- /(IHp _ (f_in xS)) /connect_trans -> //. by apply: (connect_trans (fconnect_finv _)); rewrite finv_f_in. Qed. Lemma iter_order_in : {in S, forall x, iter (order x) f x = x}. Proof. by move=> x xS; rewrite -orderSpred iterS; apply: f_finv_in. Qed. Lemma iter_finv_in n : {in S, forall x, n <= order x -> iter n finv x = iter (order x - n) f x}. Proof. move=> x xS; rewrite -[x in LHS]iter_order_in => // /subnKC {1}<-. move: (_ - n) => m; rewrite iterD; elim: n => // n {2}<-. by rewrite iterSr /= finv_f_in // -iterD iter_in. Qed. Lemma cycle_orbit_in : {in S, forall x, (fcycle f) (orbit x)}. Proof. move=> x xS; rewrite /orbit -orderSpred (cycle_path x) /= last_traject. by rewrite -/(finv x) fpath_traject f_finv_in ?eqxx. Qed. Lemma fpath_finv_in p x : (x \in S) && (fpath finv x p) = (last x p \in S) && (fpath f (last x p) (rev (belast x p))). Proof. elim: p x => //= y p IHp x; rewrite rev_cons rcons_path. transitivity [&& y \in S, f y == x & fpath finv y p]. apply/and3P/and3P => -[xS /eqP<- fxp]; split; by rewrite ?f_finv_in ?finv_f_in ?finv_in ?f_in. rewrite andbCA {}IHp !andbA [RHS]andbC -andbA; congr [&& _, _ & _]. by case: p => //= z p; rewrite rev_cons last_rcons. Qed. Lemma fpath_finv_f_in p : {in S, forall x, fpath finv x p -> fpath f (last x p) (rev (belast x p))}. Proof. by move=> x xS /(conj xS)/andP; rewrite fpath_finv_in => /andP[]. Qed. Lemma fpath_f_finv_in p x : last x p \in S -> fpath f (last x p) (rev (belast x p)) -> fpath finv x p. Proof. by move=> lS /(conj lS)/andP; rewrite -fpath_finv_in => /andP[]. Qed. End orbit_in. Lemma injectivePcycle x : reflect {in orbit x &, injective f} (fcycle f (orbit x)). Proof. apply: (iffP idP) => [/inj_cycle//|/cycle_orbit_in]. by apply; [apply: mem_orbit|apply: in_orbit]. Qed. Section orbit_inj. Hypothesis injf : injective f. Lemma f_finv : cancel finv f. Proof. exact: (in1T (f_finv_in _ (in2W _))). Qed. Lemma finv_f : cancel f finv. Proof. exact: (in1T (finv_f_in _ (in2W _))). Qed. Lemma finv_bij : bijective finv. Proof. by exists f; [apply: f_finv|apply: finv_f]. Qed. Lemma finv_inj : injective finv. Proof. exact: (can_inj f_finv). Qed. Lemma fconnect_sym x y : fconnect f x y = fconnect f y x. Proof. exact: (in2T (fconnect_sym_in _ (in2W _))). Qed. Let symf := fconnect_sym. Lemma iter_order x : iter (order x) f x = x. Proof. exact: (in1T (iter_order_in _ (in2W _))). Qed. Lemma iter_finv n x : n <= order x -> iter n finv x = iter (order x - n) f x. Proof. exact: (in1T (@iter_finv_in _ _ (in2W _) _)). Qed. Lemma cycle_orbit x : fcycle f (orbit x). Proof. exact: (in1T (cycle_orbit_in _ (in2W _))). Qed. Lemma fpath_finv x p : fpath finv x p = fpath f (last x p) (rev (belast x p)). Proof. exact: (@fpath_finv_in T _ (in2W _)). Qed. Lemma same_fconnect_finv : fconnect finv =2 fconnect f. Proof. move=> x y; rewrite (same_connect_rev symf); apply: {x y}eq_connect => x y /=. by rewrite (canF_eq finv_f) eq_sym. Qed. Lemma fcard_finv : fcard_mem finv =1 fcard_mem f. Proof. exact: eq_n_comp same_fconnect_finv. Qed. Definition order_set n : pred T := [pred x | order x == n]. Lemma fcard_order_set n (a : {pred T}) : a \subset order_set n -> fclosed f a -> fcard f a * n = #|a|. Proof. move=> a_n cl_a; rewrite /n_comp_mem; set b := [predI froots f & a]. suff <-: #|preim (froot f) b| = #|b| * n. apply: eq_card => x; rewrite !inE (roots_root fconnect_sym). exact/esym/(closed_connect cl_a)/connect_root. have{cl_a a_n} (x): b x -> froot f x = x /\ order x = n. by case/andP=> /eqP-> /(subsetP a_n)/eqnP->. elim: {a b}#|b| {1 3 4}b (eqxx #|b|) => [|m IHm] b def_m f_b. by rewrite eq_card0 // => x; apply: (pred0P def_m). have [x b_x | b0] := pickP b; last by rewrite (eq_card0 b0) in def_m. have [r_x ox_n] := f_b x b_x; rewrite (cardD1 x) [x \in b]b_x eqSS in def_m. rewrite mulSn -{1}ox_n -(IHm _ def_m) => [|_ /andP[_ /f_b //]]. rewrite -(cardID (fconnect f x)); congr (_ + _); apply: eq_card => y. by apply: andb_idl => /= fxy; rewrite !inE -(rootP symf fxy) r_x. by congr (~~ _ && _); rewrite /= /in_mem /= symf -(root_connect symf) r_x. Qed. Lemma fclosed1 (a : {pred T}) : fclosed f a -> forall x, (x \in a) = (f x \in a). Proof. by move=> cl_a x; apply: cl_a (eqxx _). Qed. Lemma same_fconnect1 x : fconnect f x =1 fconnect f (f x). Proof. by apply: same_connect1 => /=. Qed. Lemma same_fconnect1_r x y : fconnect f x y = fconnect f x (f y). Proof. by apply: same_connect1r x => /=. Qed. Lemma fcard_gt0P (a : {pred T}) : fclosed f a -> reflect (exists x, x \in a) (0 < fcard f a). Proof. move=> clfA; apply: (iffP card_gt0P) => [[x /andP[]]|[x xA]]; first by exists x. exists (froot f x); rewrite inE roots_root /=; last exact: fconnect_sym. by rewrite -(closed_connect clfA (connect_root _ x)). Qed. Lemma fcard_gt1P (A : {pred T}) : fclosed f A -> reflect (exists2 x, x \in A & exists2 y, y \in A & ~~ fconnect f x y) (1 < fcard f A). Proof. move=> clAf; apply: (iffP card_gt1P) => [|[x xA [y yA not_xfy]]]. move=> [x [y [/andP [/= rfx xA] /andP[/= rfy yA] xDy]]]. by exists x; try exists y; rewrite // -root_connect // (eqP rfx) (eqP rfy). exists (froot f x), (froot f y); rewrite !inE !roots_root ?root_connect //=. by split => //; rewrite -(closed_connect clAf (connect_root _ _)). Qed. End orbit_inj. Hint Resolve orbit_uniq : core. Section fcycle_p. Variables (p : seq T) (f_p : fcycle f p). Section mem_cycle. Variable (Up : uniq p) (x : T) (p_x : x \in p). (* fconnect_cycle does not dependent on Up *) Lemma fconnect_cycle y : fconnect f x y = (y \in p). Proof. have [i q def_p] := rot_to p_x; rewrite -(mem_rot i p) def_p. have{i def_p} /andP[/eqP q_x f_q]: (f (last x q) == x) && fpath f x q. by have:= f_p; rewrite -(rot_cycle i) def_p (cycle_path x). apply/idP/idP=> [/connectP[_ /fpathP[j ->] ->] | ]; last exact: path_connect. case/fpathP: f_q q_x => n ->; rewrite !last_traject -iterS => def_x. by apply: (@loopingP _ f x n.+1); rewrite /looping def_x /= mem_head. Qed. (* order_le_cycle does not dependent on Up *) Lemma order_le_cycle : order x <= size p. Proof. apply: leq_trans (card_size _); apply/subset_leq_card/subsetP=> y. by rewrite !(fconnect_cycle, inE) ?eqxx. Qed. Lemma order_cycle : order x = size p. Proof. by rewrite -(card_uniqP Up); apply: (eq_card fconnect_cycle). Qed. Lemma orbitE : orbit x = rot (index x p) p. Proof. set i := index _ _; rewrite /orbit order_cycle -(size_rot i) rot_index// -/i. set q := _ ++ _; suffices /fpathP[j ->]: fpath f x q by rewrite /= size_traject. by move: f_p; rewrite -(rot_cycle i) rot_index// (cycle_path x); case/andP. Qed. Lemma orbit_rot_cycle : {i : nat | orbit x = rot i p}. Proof. by rewrite orbitE; exists (index x p). Qed. End mem_cycle. Let f_inj := inj_cycle f_p. Let homo_f := mem_fcycle f_p. Lemma finv_cycle : {homo finv : x / x \in p}. Proof. exact: finv_in. Qed. Lemma f_finv_cycle : {in p, cancel finv f}. Proof. exact: f_finv_in. Qed. Lemma finv_f_cycle : {in p, cancel f finv}. Proof. exact: finv_f_in. Qed. Lemma finv_inj_cycle : {in p &, injective finv}. Proof. exact: finv_inj_in. Qed. Lemma iter_finv_cycle n : {in p, forall x, n <= order x -> iter n finv x = iter (order x - n) f x}. Proof. exact: iter_finv_in. Qed. Lemma cycle_orbit_cycle : {in p, forall x, fcycle f (orbit x)}. Proof. exact: cycle_orbit_in. Qed. Lemma fpath_finv_cycle q x : (x \in p) && (fpath finv x q) = (last x q \in p) && fpath f (last x q) (rev (belast x q)). Proof. exact: fpath_finv_in. Qed. Lemma fpath_finv_f_cycle q : {in p, forall x, fpath finv x q -> fpath f (last x q) (rev (belast x q))}. Proof. exact: fpath_finv_f_in. Qed. Lemma fpath_f_finv_cycle q x : last x q \in p -> fpath f (last x q) (rev (belast x q)) -> fpath finv x q. Proof. exact: fpath_f_finv_in. Qed. Lemma prevE x : x \in p -> prev p x = finv x. Proof. move=> x_p; have /eqP/(congr1 finv) := prev_cycle f_p x_p. by rewrite finv_f_cycle// mem_prev. Qed. End fcycle_p. Section fcycle_cons. Variables (x : T) (p : seq T) (f_p : fcycle f (x :: p)). Lemma fcycle_rconsE : rcons (x :: p) x = traject f x (size p).+2. Proof. by rewrite rcons_cons; have /fpathE-> := f_p; rewrite size_rcons. Qed. Lemma fcycle_consE : x :: p = traject f x (size p).+1. Proof. by have := fcycle_rconsE; rewrite trajectSr => /rcons_inj[/= <-]. Qed. Lemma fcycle_consEflatten : exists k, x :: p = flatten (nseq k.+1 (orbit x)). Proof. move: f_p; rewrite fcycle_consE; elim/ltn_ind: (size p) => n IHn t_cycle. have := order_le_cycle t_cycle (mem_head _ _); rewrite size_traject. case: ltngtP => [||<-] //; last by exists 0; rewrite /= cats0. rewrite ltnS => n_ge _; have := t_cycle. rewrite -(subnKC n_ge) -addnS trajectD. rewrite (iter_order_in (mem_fcycle f_p) (inj_cycle f_p)) ?mem_head//. set m := (_ - _) => cycle_cat. have [||k->] := IHn m; last by exists k.+1. by rewrite ltn_subrL (leq_trans _ n_ge) ?order_gt0. move: cycle_cat; rewrite -orderSpred/= rcons_cat rcons_cons -cat_rcons. by rewrite cat_path last_rcons => /andP[]. Qed. Lemma undup_cycle_cons : undup (x :: p) = orbit x. Proof. by have [n {1}->] := fcycle_consEflatten; rewrite undup_flatten_nseq ?undup_id. Qed. End fcycle_cons. Section fcycle_undup. Variable (p : seq T) (f_p : fcycle f p). Lemma fcycleEflatten : exists k, p = flatten (nseq k (undup p)). Proof. case: p f_p => [//|x q] f_q; first by exists 0. have [k {1}->] := @fcycle_consEflatten x q f_q. by exists k.+1; rewrite undup_cycle_cons. Qed. Lemma fcycle_undup : fcycle f (undup p). Proof. case: p f_p => [//|x q] f_q; rewrite undup_cycle_cons//. by rewrite (cycle_orbit_in (mem_fcycle f_q) (inj_cycle f_q)) ?mem_head. Qed. Let p_undup_uniq := undup_uniq p. Let f_inj := inj_cycle f_p. Let homo_f := mem_fcycle f_p. Lemma in_orbit_cycle : {in p &, forall x, orbit x =i p}. Proof. by move=> x y xp yp; rewrite (orbitE fcycle_undup)// ?mem_rot ?mem_undup. Qed. Lemma eq_order_cycle : {in p &, forall x y, order y = order x}. Proof. by move=> x y xp yp; rewrite !(order_cycle fcycle_undup) ?mem_undup. Qed. Lemma iter_order_cycle : {in p &, forall x y, iter (order x) f y = y}. Proof. by move=> x y xp yp; rewrite (eq_order_cycle yp) ?(iter_order_in homo_f f_inj). Qed. End fcycle_undup. Section fconnect. Lemma fconnect_eqVf x y : fconnect f x y = (x == y) || fconnect f (f x) y. Proof. apply/idP/idP => [/iter_findex <-|/predU1P [<-|] //]; last first. exact/connect_trans/fconnect1. by case: findex => [|i]; rewrite ?eqxx// iterSr fconnect_iter orbT. Qed. (*****************************************************************************) (* Lemma orbitPcycle is of type "The Following Are Equivalent", which means *) (* all four statements are equivalent to each other. In order to use it, one *) (* has to apply it to the natural numbers corresponding to the line, e.g. *) (* `orbitPcycle 0 2 : fcycle f (orbit x) <-> exists k, iter k.+1 f x = x`. *) (* examples of this are in order_id_cycle and fconnnect_f. *) (* One may also use lemma all_iffLR to get a one sided implication, as in *) (* orderPcycle. *) (*****************************************************************************) Lemma orbitPcycle {x} : [<-> (* 0 *) fcycle f (orbit x); (* 1 *) order (f x) = order x; (* 2 *) x \in fconnect f (f x); (* 3 *) exists k, iter k.+1 f x = x; (* 4 *) iter (order x) f x = x; (* 5 *) {in orbit x &, injective f}]. Proof. tfae=> [xorbit_cycle|||[k fkx]|fx y z|/injectivePcycle//]. - by apply: eq_order_cycle xorbit_cycle _ _ _ _; rewrite ?mem_orbit. - move=> /subset_cardP/(_ _)->; rewrite ?inE//; apply/subsetP=> y. by apply: connect_trans; apply: fconnect1. - by exists (findex (f x) x); rewrite // iterSr iter_findex. - apply: (@iter_order_cycle (traject f x k.+1)); rewrite /= ?mem_head//. by apply/fpathP; exists k.+1; rewrite trajectSr -iterSr fkx. - rewrite -!fconnect_orbit => /iter_findex <- /iter_findex <-. move/(congr1 (iter (order x).-1 f)). by rewrite -!iterSr !orderSpred -!iterD ![order _ + _]addnC !iterD fx. Qed. Lemma order_id_cycle x : fcycle f (orbit x) -> order (f x) = order x. Proof. by move/(orbitPcycle 0 1). Qed. Inductive order_spec_cycle x : bool -> Type := | OrderStepCycle of fcycle f (orbit x) & order x = order (f x) : order_spec_cycle x true | OrderStepNoCycle of ~~ fcycle f (orbit x) & order x = (order (f x)).+1 : order_spec_cycle x false. Lemma orderPcycle x : order_spec_cycle x (fcycle f (orbit x)). Proof. have [xcycle|Ncycle] := boolP (fcycle f (orbit x)); constructor => //. by rewrite order_id_cycle. rewrite /order (eq_card (_ : _ =1 [predU1 x & fconnect f (f x)])). by rewrite cardU1 inE (contraNN (all_iffLR orbitPcycle 2 0)). by move=> y; rewrite !inE fconnect_eqVf eq_sym. Qed. Lemma fconnect_f x : fconnect f (f x) x = fcycle f (orbit x). Proof. by apply/idP/idP => /(orbitPcycle 0 2). Qed. Lemma fconnect_findex x y : fconnect f x y -> y != x -> findex x y = (findex (f x) y).+1. Proof. rewrite /findex fconnect_orbit /orbit -orderSpred /= inE => /orP [-> //|]. rewrite eq_sym; move=> yin /negPf->; have [_ eq_o|_ ->//] := orderPcycle x. by rewrite -(orderSpred (f x)) trajectSr -cats1 index_cat -eq_o yin. Qed. End fconnect. End Orbit. #[global] Hint Resolve in_orbit mem_orbit order_gt0 orbit_uniq : core. Prenex Implicits order orbit findex finv order_set. Arguments orbitPcycle {T f x}. Arguments same_fconnect_finv [T f]. Section FconnectId. Variable T : finType. Lemma fconnect_id (x : T) : fconnect id x =1 xpred1 x. Proof. by move=> y; rewrite (@fconnect_cycle _ _ [:: x]) //= ?inE ?eqxx. Qed. Lemma order_id (x : T) : order id x = 1. Proof. by rewrite /order (eq_card (fconnect_id x)) card1. Qed. Lemma orbit_id (x : T) : orbit id x = [:: x]. Proof. by rewrite /orbit order_id. Qed. Lemma froots_id (x : T) : froots id x. Proof. by rewrite /roots -fconnect_id connect_root. Qed. Lemma froot_id (x : T) : froot id x = x. Proof. by apply/eqP; apply: froots_id. Qed. Lemma fcard_id (a : {pred T}) : fcard id a = #|a|. Proof. by apply: eq_card => x; rewrite inE froots_id. Qed. End FconnectId. Section FconnectEq. Variables (T : finType) (f f' : T -> T). Lemma finv_eq_can : cancel f f' -> finv f =1 f'. Proof. move=> fK; have inj_f := can_inj fK. by apply: bij_can_eq fK; [apply: injF_bij | apply: finv_f]. Qed. Hypothesis eq_f : f =1 f'. Let eq_rf := eq_frel eq_f. Lemma eq_fconnect : fconnect f =2 fconnect f'. Proof. exact: eq_connect eq_rf. Qed. Lemma eq_fcard : fcard_mem f =1 fcard_mem f'. Proof. exact: eq_n_comp eq_fconnect. Qed. Lemma eq_finv : finv f =1 finv f'. Proof. by move=> x; rewrite /finv /order (eq_card (@eq_fconnect x)) (eq_iter eq_f). Qed. Lemma eq_froot : froot f =1 froot f'. Proof. exact: eq_root eq_rf. Qed. Lemma eq_froots : froots f =1 froots f'. Proof. exact: eq_roots eq_rf. Qed. End FconnectEq. Arguments eq_fconnect [T f f']. Section FinvEq. Variables (T : finType) (f : T -> T). Hypothesis injf : injective f. Lemma finv_inv : finv (finv f) =1 f. Proof. exact: (finv_eq_can (f_finv injf)). Qed. Lemma order_finv : order (finv f) =1 order f. Proof. by move=> x; apply: eq_card (@same_fconnect_finv _ _ injf x). Qed. Lemma order_set_finv n : order_set (finv f) n =i order_set f n. Proof. by move=> x; rewrite !inE order_finv. Qed. End FinvEq. Section RelAdjunction. Variables (T T' : finType) (h : T' -> T) (e : rel T) (e' : rel T'). Hypotheses (sym_e : connect_sym e) (sym_e' : connect_sym e'). Record rel_adjunction_mem m_a := RelAdjunction { rel_unit x : in_mem x m_a -> {x' : T' | connect e x (h x')}; rel_functor x' y' : in_mem (h x') m_a -> connect e' x' y' = connect e (h x') (h y') }. Variable a : {pred T}. Hypothesis cl_a : closed e a. Local Notation rel_adjunction := (rel_adjunction_mem (mem a)). Lemma intro_adjunction (h' : forall x, x \in a -> T') : (forall x a_x, [/\ connect e x (h (h' x a_x)) & forall y a_y, e x y -> connect e' (h' x a_x) (h' y a_y)]) -> (forall x' a_x, [/\ connect e' x' (h' (h x') a_x) & forall y', e' x' y' -> connect e (h x') (h y')]) -> rel_adjunction. Proof. move=> Aee' Ae'e; split=> [y a_y | x' z' a_x]. by exists (h' y a_y); case/Aee': (a_y). apply/idP/idP=> [/connectP[p e'p ->{z'}] | /connectP[p e_p p_z']]. elim: p x' a_x e'p => //= y' p IHp x' a_x. case: (Ae'e x' a_x) => _ Ae'x /andP[/Ae'x e_xy /IHp e_yz] {Ae'x}. by apply: connect_trans (e_yz _); rewrite // -(closed_connect cl_a e_xy). case: (Ae'e x' a_x) => /connect_trans-> //. elim: p {x'}(h x') p_z' a_x e_p => /= [|y p IHp] x p_z' a_x. by rewrite -p_z' in a_x *; case: (Ae'e _ a_x); rewrite sym_e'. case/andP=> e_xy /(IHp _ p_z') e'yz; have a_y: y \in a by rewrite -(cl_a e_xy). by apply: connect_trans (e'yz a_y); case: (Aee' _ a_x) => _ ->. Qed. Lemma strict_adjunction : injective h -> a \subset codom h -> rel_base h e e' [predC a] -> rel_adjunction. Proof. move=> /= injh h_a a_ee'; pose h' x Hx := iinv (subsetP h_a x Hx). apply: (@intro_adjunction h') => [x a_x | x' a_x]. rewrite f_iinv connect0; split=> // y a_y e_xy. by rewrite connect1 // -a_ee' !f_iinv ?negbK. rewrite [h' _ _]iinv_f //; split=> // y' e'xy. by rewrite connect1 // a_ee' ?negbK. Qed. Let ccl_a := closed_connect cl_a. Lemma adjunction_closed : rel_adjunction -> closed e' [preim h of a]. Proof. case=> _ Ae'e; apply: intro_closed => // x' y' /connect1 e'xy a_x. by rewrite Ae'e // in e'xy; rewrite !inE -(ccl_a e'xy). Qed. Lemma adjunction_n_comp : rel_adjunction -> n_comp e a = n_comp e' [preim h of a]. Proof. case=> Aee' Ae'e. have inj_h: {in predI (roots e') [preim h of a] &, injective (root e \o h)}. move=> x' y' /andP[/eqP r_x' /= a_x'] /andP[/eqP r_y' _] /(rootP sym_e). by rewrite -Ae'e // => /(rootP sym_e'); rewrite r_x' r_y'. rewrite /n_comp_mem -(card_in_image inj_h); apply: eq_card => x. apply/andP/imageP=> [[/eqP rx a_x] | [x' /andP[/eqP r_x' a_x'] ->]]; last first. by rewrite /= -(ccl_a (connect_root _ _)) roots_root. have [y' e_xy]:= Aee' x a_x; pose x' := root e' y'. have ay': h y' \in a by rewrite -(ccl_a e_xy). have e_yx: connect e (h y') (h x') by rewrite -Ae'e ?connect_root. exists x'; first by rewrite inE /= -(ccl_a e_yx) ?roots_root. by rewrite /= -(rootP sym_e e_yx) -(rootP sym_e e_xy). Qed. End RelAdjunction. Notation rel_adjunction h e e' a := (rel_adjunction_mem h e e' (mem a)). Notation "@ 'rel_adjunction' T T' h e e' a" := (@rel_adjunction_mem T T' h e e' (mem a)) (at level 10, T, T', h, e, e', a at level 8, only parsing) : type_scope. Notation fun_adjunction h f f' a := (rel_adjunction h (frel f) (frel f') a). Notation "@ 'fun_adjunction' T T' h f f' a" := (@rel_adjunction T T' h (frel f) (frel f') a) (at level 10, T, T', h, f, f', a at level 8, only parsing) : type_scope. Arguments intro_adjunction [T T' h e e'] _ [a]. Arguments adjunction_n_comp [T T'] h [e e'] _ _ [a]. Unset Implicit Arguments.
Dissociation.lean
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.Group.Pointwise.Set.Basic import Mathlib.Algebra.Group.Units.Equiv import Mathlib.Algebra.Notation.Indicator import Mathlib.Data.Finset.Powerset import Mathlib.Data.Fintype.Pi import Mathlib.Order.Preorder.Finite /-! # Dissociation and span This file defines dissociation and span of sets in groups. These are analogs to the usual linear independence and linear span of sets in a vector space but where the scalars are only allowed to be `0` or `±1`. In characteristic 2 or 3, the two pairs of concepts are actually equivalent. ## Main declarations * `MulDissociated`/`AddDissociated`: Predicate for a set to be dissociated. * `Finset.mulSpan`/`Finset.addSpan`: Span of a finset. -/ variable {α β : Type*} [CommGroup α] [CommGroup β] section dissociation variable {s : Set α} {t u : Finset α} {d : ℕ} {a : α} open Set /-- A set is dissociated iff all its finite subsets have different products. This is an analog of linear independence in a vector space, but with the "scalars" restricted to `0` and `±1`. -/ @[to_additive /-- A set is dissociated iff all its finite subsets have different sums. This is an analog of linear independence in a vector space, but with the "scalars" restricted to `0` and `±1`. -/] def MulDissociated (s : Set α) : Prop := {t : Finset α | ↑t ⊆ s}.InjOn (∏ x ∈ ·, x) @[to_additive] lemma mulDissociated_iff_sum_eq_subsingleton : MulDissociated s ↔ ∀ a, {t : Finset α | ↑t ⊆ s ∧ ∏ x ∈ t, x = a}.Subsingleton := ⟨fun hs _ _t ht _u hu ↦ hs ht.1 hu.1 <| ht.2.trans hu.2.symm, fun hs _t ht _u hu htu ↦ hs _ ⟨ht, htu⟩ ⟨hu, rfl⟩⟩ @[to_additive] lemma MulDissociated.subset {t : Set α} (hst : s ⊆ t) (ht : MulDissociated t) : MulDissociated s := ht.mono fun _ ↦ hst.trans' @[to_additive (attr := simp)] lemma mulDissociated_empty : MulDissociated (∅ : Set α) := by simp [MulDissociated, subset_empty_iff] @[to_additive (attr := simp)] lemma mulDissociated_singleton : MulDissociated ({a} : Set α) ↔ a ≠ 1 := by simp [MulDissociated, setOf_or, -subset_singleton_iff, Finset.coe_subset_singleton] @[to_additive (attr := simp)] lemma not_mulDissociated : ¬ MulDissociated s ↔ ∃ t : Finset α, ↑t ⊆ s ∧ ∃ u : Finset α, ↑u ⊆ s ∧ t ≠ u ∧ ∏ x ∈ t, x = ∏ x ∈ u, x := by simp [MulDissociated, InjOn]; aesop @[to_additive] lemma not_mulDissociated_iff_exists_disjoint : ¬ MulDissociated s ↔ ∃ t u : Finset α, ↑t ⊆ s ∧ ↑u ⊆ s ∧ Disjoint t u ∧ t ≠ u ∧ ∏ a ∈ t, a = ∏ a ∈ u, a := by classical refine not_mulDissociated.trans ⟨?_, fun ⟨t, u, ht, hu, _, htune, htusum⟩ ↦ ⟨t, ht, u, hu, htune, htusum⟩⟩ rintro ⟨t, ht, u, hu, htu, h⟩ refine ⟨t \ u, u \ t, ?_, ?_, disjoint_sdiff_sdiff, sdiff_ne_sdiff_iff.2 htu, Finset.prod_sdiff_eq_prod_sdiff_iff.2 h⟩ <;> push_cast <;> exact diff_subset.trans ‹_› @[to_additive (attr := simp)] lemma MulEquiv.mulDissociated_preimage (e : β ≃* α) : MulDissociated (e ⁻¹' s) ↔ MulDissociated s := by simp [MulDissociated, InjOn, ← e.finsetCongr.forall_congr_right, ← e.apply_eq_iff_eq, (Finset.map_injective _).eq_iff] @[to_additive (attr := simp)] lemma mulDissociated_inv : MulDissociated s⁻¹ ↔ MulDissociated s := (MulEquiv.inv α).mulDissociated_preimage @[to_additive] protected alias ⟨MulDissociated.of_inv, MulDissociated.inv⟩ := mulDissociated_inv end dissociation namespace Finset variable [DecidableEq α] [Fintype α] {s t u : Finset α} {a : α} {d : ℕ} /-- The span of a finset `s` is the finset of elements of the form `∏ a ∈ s, a ^ ε a` where `ε ∈ {-1, 0, 1} ^ s`. This is an analog of the linear span in a vector space, but with the "scalars" restricted to `0` and `±1`. -/ @[to_additive /-- The span of a finset `s` is the finset of elements of the form `∑ a ∈ s, ε a • a` where `ε ∈ {-1, 0, 1} ^ s`. This is an analog of the linear span in a vector space, but with the "scalars" restricted to `0` and `±1`. -/] def mulSpan (s : Finset α) : Finset α := (Fintype.piFinset fun _a ↦ ({-1, 0, 1} : Finset ℤ)).image fun ε ↦ ∏ a ∈ s, a ^ ε a @[to_additive (attr := simp)] lemma mem_mulSpan : a ∈ mulSpan s ↔ ∃ ε : α → ℤ, (∀ a, ε a = -1 ∨ ε a = 0 ∨ ε a = 1) ∧ ∏ a ∈ s, a ^ ε a = a := by simp [mulSpan] @[to_additive (attr := simp)] lemma subset_mulSpan : s ⊆ mulSpan s := fun a ha ↦ mem_mulSpan.2 ⟨Pi.single a 1, fun b ↦ by obtain rfl | hab := eq_or_ne a b <;> simp [*], by simp [Pi.single, Function.update, pow_ite, ha]⟩ @[to_additive] lemma prod_div_prod_mem_mulSpan (ht : t ⊆ s) (hu : u ⊆ s) : (∏ a ∈ t, a) / ∏ a ∈ u, a ∈ mulSpan s := mem_mulSpan.2 ⟨Set.indicator t 1 - Set.indicator u 1, fun a ↦ by by_cases a ∈ t <;> by_cases a ∈ u <;> simp [*], by simp [prod_div_distrib, zpow_sub, ← div_eq_mul_inv, Set.indicator, pow_ite, inter_eq_right.2, *]⟩ /-- If every dissociated subset of `s` has size at most `d`, then `s` is actually generated by a subset of size at most `d`. This is a dissociation analog of the fact that a set whose linearly independent subsets all have size at most `d` is of dimension at most `d` itself. -/ @[to_additive /-- If every dissociated subset of `s` has size at most `d`, then `s` is actually generated by a subset of size at most `d`. This is a dissociation analog of the fact that a set whose linearly independent subspaces all have size at most `d` is of dimension at most `d` itself. -/] lemma exists_subset_mulSpan_card_le_of_forall_mulDissociated (hs : ∀ s', s' ⊆ s → MulDissociated (s' : Set α) → s'.card ≤ d) : ∃ s', s' ⊆ s ∧ s'.card ≤ d ∧ s ⊆ mulSpan s' := by classical obtain ⟨s', hs'⟩ := (s.powerset.filter fun s' : Finset α ↦ MulDissociated (s' : Set α)).exists_maximal ⟨∅, mem_filter.2 ⟨empty_mem_powerset _, by simp⟩⟩ simp only [mem_filter, mem_powerset] at hs' refine ⟨s', hs'.1.1, hs _ hs'.1.1 hs'.1.2, fun a ha ↦ ?_⟩ by_cases ha' : a ∈ s' · exact subset_mulSpan ha' obtain ⟨t, u, ht, hu, htu⟩ := not_mulDissociated_iff_exists_disjoint.1 fun h ↦ hs'.not_gt ⟨insert_subset_iff.2 ⟨ha, hs'.1.1⟩, h⟩ <| ssubset_insert ha' by_cases hat : a ∈ t · have : a = (∏ b ∈ u, b) / ∏ b ∈ t.erase a, b := by rw [prod_erase_eq_div hat, htu.2.2, div_div_self'] rw [this] exact prod_div_prod_mem_mulSpan ((subset_insert_iff_of_notMem <| disjoint_left.1 htu.1 hat).1 hu) (subset_insert_iff.1 ht) rw [coe_subset, subset_insert_iff_of_notMem hat] at ht by_cases hau : a ∈ u · have : a = (∏ b ∈ t, b) / ∏ b ∈ u.erase a, b := by rw [prod_erase_eq_div hau, htu.2.2, div_div_self'] rw [this] exact prod_div_prod_mem_mulSpan ht (subset_insert_iff.1 hu) · rw [coe_subset, subset_insert_iff_of_notMem hau] at hu cases not_mulDissociated_iff_exists_disjoint.2 ⟨t, u, ht, hu, htu⟩ hs'.1.2 end Finset
Option.lean
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.Finsupp.Basic import Mathlib.Algebra.Module.Defs /-! # Declarations about finitely supported functions whose support is an `Option` type p ## Main declarations * `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported function on `α`. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. -/ noncomputable section open Finset Function variable {α M N R : Type*} namespace Finsupp section Option /-- Restrict a finitely supported function on `Option α` to a finitely supported function on `α`. -/ def some [Zero M] (f : Option α →₀ M) : α →₀ M := f.comapDomain Option.some fun _ => by simp @[simp] theorem some_apply [Zero M] (f : Option α →₀ M) (a : α) : f.some a = f (Option.some a) := rfl @[simp] theorem some_zero [Zero M] : (0 : Option α →₀ M).some = 0 := by ext simp @[simp] theorem some_add [AddZeroClass M] (f g : Option α →₀ M) : (f + g).some = f.some + g.some := by ext simp @[simp] theorem some_single_none [Zero M] (m : M) : (single none m : Option α →₀ M).some = 0 := by ext simp @[simp] theorem some_single_some [Zero M] (a : α) (m : M) : (single (Option.some a) m : Option α →₀ M).some = single a m := by classical ext b simp [single_apply] @[simp] theorem embDomain_some_some [Zero M] (f : α →₀ M) (x) : f.embDomain .some (.some x) = f x := by simp [← Function.Embedding.some_apply] @[simp] theorem some_update_none [Zero M] (f : Option α →₀ M) (a : M) : (f.update .none a).some = f.some := by ext simp [Finsupp.update] /-- `Finsupp`s from `Option` are equivalent to pairs of an element and a `Finsupp` on the original type. -/ @[simps] noncomputable def optionEquiv [Zero M] : (Option α →₀ M) ≃ M × (α →₀ M) where toFun P := (P .none, P.some) invFun P := (P.2.embDomain .some).update .none P.1 left_inv P := by ext (_ | a) <;> simp [Finsupp.update] right_inv P := by ext <;> simp [Finsupp.update] theorem eq_option_embedding_update_none_iff [Zero M] {n : Option α →₀ M} {m : α →₀ M} {i : M} : n = (embDomain Embedding.some m).update none i ↔ n none = i ∧ n.some = m := (optionEquiv.apply_eq_iff_eq_symm_apply (y := (_, _))).symm.trans Prod.ext_iff @[to_additive] theorem prod_option_index [AddZeroClass M] [CommMonoid N] (f : Option α →₀ M) (b : Option α → M → N) (h_zero : ∀ o, b o 0 = 1) (h_add : ∀ o m₁ m₂, b o (m₁ + m₂) = b o m₁ * b o m₂) : f.prod b = b none (f none) * f.some.prod fun a => b (Option.some a) := by classical induction f using induction_linear with | zero => simp [some_zero, h_zero] | add f₁ f₂ h₁ h₂ => rw [Finsupp.prod_add_index, h₁, h₂, some_add, Finsupp.prod_add_index] · simp only [h_add, Pi.add_apply, Finsupp.coe_add] rw [mul_mul_mul_comm] all_goals simp [h_zero, h_add] | single a m => cases a <;> simp [h_zero] theorem sum_option_index_smul [Semiring R] [AddCommMonoid M] [Module R M] (f : Option α →₀ R) (b : Option α → M) : (f.sum fun o r => r • b o) = f none • b none + f.some.sum fun a r => r • b (Option.some a) := f.sum_option_index _ (fun _ => zero_smul _ _) fun _ _ _ => add_smul _ _ _ @[simp] lemma some_embDomain_some [Zero M] (f : α →₀ M) : (f.embDomain .some).some = f := by ext; rw [some_apply]; exact embDomain_apply _ _ _ @[simp] lemma embDomain_some_none [Zero M] (f : α →₀ M) : f.embDomain .some .none = 0 := embDomain_notin_range _ _ _ (by simp) end Option end Finsupp
AddCircle.lean
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Complex.Circle import Mathlib.Analysis.InnerProductSpace.l2Space import Mathlib.MeasureTheory.Function.ContinuousMapDense import Mathlib.MeasureTheory.Function.L2Space import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Integral.IntervalIntegral.Periodic import Mathlib.Topology.ContinuousMap.StoneWeierstrass import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Fourier analysis on the additive circle This file contains basic results on Fourier series for functions on the additive circle `AddCircle T = ℝ / ℤ • T`. ## Main definitions * `haarAddCircle`, Haar measure on `AddCircle T`, normalized to have total measure `1`. Note that this is not the same normalisation as the standard measure defined in `IntervalIntegral.Periodic`, so we do not declare it as a `MeasureSpace` instance, to avoid confusion. * for `n : ℤ`, `fourier n` is the monomial `fun x => exp (2 π i n x / T)`, bundled as a continuous map from `AddCircle T` to `ℂ`. * `fourierBasis` is the Hilbert basis of `Lp ℂ 2 haarAddCircle` given by the images of the monomials `fourier n`. * `fourierCoeff f n`, for `f : AddCircle T → E` (with `E` a complete normed `ℂ`-vector space), is the `n`-th Fourier coefficient of `f`, defined as an integral over `AddCircle T`. The lemma `fourierCoeff_eq_intervalIntegral` expresses this as an integral over `[a, a + T]` for any real `a`. * `fourierCoeffOn`, for `f : ℝ → E` and `a < b` reals, is the `n`-th Fourier coefficient of the unique periodic function of period `b - a` which agrees with `f` on `(a, b]`. The lemma `fourierCoeffOn_eq_integral` expresses this as an integral over `[a, b]`. ## Main statements The theorem `span_fourier_closure_eq_top` states that the span of the monomials `fourier n` is dense in `C(AddCircle T, ℂ)`, i.e. that its `Submodule.topologicalClosure` is `⊤`. This follows from the Stone-Weierstrass theorem after checking that the span is a subalgebra, is closed under conjugation, and separates points. Using this and general theory on approximation of Lᵖ functions by continuous functions, we deduce (`span_fourierLp_closure_eq_top`) that for any `1 ≤ p < ∞`, the span of the Fourier monomials is dense in the Lᵖ space of `AddCircle T`. For `p = 2` we show (`orthonormal_fourier`) that the monomials are also orthonormal, so they form a Hilbert basis for L², which is named as `fourierBasis`; in particular, for `L²` functions `f`, the Fourier series of `f` converges to `f` in the `L²` topology (`hasSum_fourier_series_L2`). Parseval's identity, `tsum_sq_fourierCoeff`, is a direct consequence. For continuous maps `f : AddCircle T → ℂ`, the theorem `hasSum_fourier_series_of_summable` states that if the sequence of Fourier coefficients of `f` is summable, then the Fourier series `∑ (i : ℤ), fourierCoeff f i * fourier i` converges to `f` in the uniform-convergence topology of `C(AddCircle T, ℂ)`. -/ noncomputable section open scoped ENNReal ComplexConjugate Real open TopologicalSpace ContinuousMap MeasureTheory MeasureTheory.Measure Algebra Submodule Set variable {T : ℝ} namespace AddCircle /-! ### Measure on `AddCircle T` In this file we use the Haar measure on `AddCircle T` normalised to have total measure 1 (which is **not** the same as the standard measure defined in `Topology.Instances.AddCircle`). -/ variable [hT : Fact (0 < T)] /-- Haar measure on the additive circle, normalised to have total measure 1. -/ def haarAddCircle : Measure (AddCircle T) := addHaarMeasure ⊤ deriving IsAddHaarMeasure instance : IsProbabilityMeasure (@haarAddCircle T _) := IsProbabilityMeasure.mk addHaarMeasure_self theorem volume_eq_smul_haarAddCircle : (volume : Measure (AddCircle T)) = ENNReal.ofReal T • (@haarAddCircle T _) := rfl end AddCircle open AddCircle section Monomials /-- The family of exponential monomials `fun x => exp (2 π i n x / T)`, parametrized by `n : ℤ` and considered as bundled continuous maps from `ℝ / ℤ • T` to `ℂ`. -/ def fourier (n : ℤ) : C(AddCircle T, ℂ) where toFun x := toCircle (n • x :) continuous_toFun := continuous_induced_dom.comp <| continuous_toCircle.comp <| continuous_zsmul _ @[simp] theorem fourier_apply {n : ℤ} {x : AddCircle T} : fourier n x = toCircle (n • x :) := rfl -- simp normal form is `fourier_coe_apply'` theorem fourier_coe_apply {n : ℤ} {x : ℝ} : fourier n (x : AddCircle T) = Complex.exp (2 * π * Complex.I * n * x / T) := by rw [fourier_apply, ← QuotientAddGroup.mk_zsmul, toCircle, Function.Periodic.lift_coe, Circle.coe_exp, Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_mul, zsmul_eq_mul, Complex.ofReal_mul, Complex.ofReal_intCast] norm_num congr 1; ring @[simp] theorem fourier_coe_apply' {n : ℤ} {x : ℝ} : toCircle (n • (x : AddCircle T) :) = Complex.exp (2 * π * Complex.I * n * x / T) := by rw [← fourier_apply]; exact fourier_coe_apply -- simp normal form is `fourier_zero'` theorem fourier_zero {x : AddCircle T} : fourier 0 x = 1 := by induction x using QuotientAddGroup.induction_on simp only [fourier_coe_apply] norm_num theorem fourier_zero' {x : AddCircle T} : @toCircle T 0 = (1 : ℂ) := by have : fourier 0 x = @toCircle T 0 := by rw [fourier_apply, zero_smul] rw [← this]; exact fourier_zero -- simp normal form is *also* `fourier_zero'` theorem fourier_eval_zero (n : ℤ) : fourier n (0 : AddCircle T) = 1 := by rw [← QuotientAddGroup.mk_zero, fourier_coe_apply, Complex.ofReal_zero, mul_zero, zero_div, Complex.exp_zero] theorem fourier_one {x : AddCircle T} : fourier 1 x = toCircle x := by rw [fourier_apply, one_zsmul] -- simp normal form is `fourier_neg'` theorem fourier_neg {n : ℤ} {x : AddCircle T} : fourier (-n) x = conj (fourier n x) := by induction x using QuotientAddGroup.induction_on simp_rw [fourier_apply, toCircle] rw [← QuotientAddGroup.mk_zsmul, ← QuotientAddGroup.mk_zsmul] simp_rw [Function.Periodic.lift_coe, ← Circle.coe_inv_eq_conj, ← Circle.exp_neg, neg_smul, mul_neg] @[simp] theorem fourier_neg' {n : ℤ} {x : AddCircle T} : @toCircle T (-(n • x)) = conj (fourier n x) := by rw [← neg_smul, ← fourier_apply]; exact fourier_neg -- simp normal form is `fourier_add'` theorem fourier_add {m n : ℤ} {x : AddCircle T} : fourier (m+n) x = fourier m x * fourier n x := by simp_rw [fourier_apply, add_zsmul, toCircle_add, Circle.coe_mul] @[simp] theorem fourier_add' {m n : ℤ} {x : AddCircle T} : toCircle ((m + n) • x :) = fourier m x * fourier n x := by rw [← fourier_apply]; exact fourier_add theorem fourier_norm [Fact (0 < T)] (n : ℤ) : ‖@fourier T n‖ = 1 := by rw [ContinuousMap.norm_eq_iSup_norm] have : ∀ x : AddCircle T, ‖fourier n x‖ = 1 := fun x => Circle.norm_coe _ simp_rw [this] exact @ciSup_const _ _ _ Zero.instNonempty _ /-- For `n ≠ 0`, a translation by `T / 2 / n` negates the function `fourier n`. -/ theorem fourier_add_half_inv_index {n : ℤ} (hn : n ≠ 0) (hT : 0 < T) (x : AddCircle T) : @fourier T n (x + ↑(T / 2 / n)) = -fourier n x := by rw [fourier_apply, zsmul_add, ← QuotientAddGroup.mk_zsmul, toCircle_add, Metric.unitSphere.coe_mul] have : (n : ℂ) ≠ 0 := by simpa using hn have : (@toCircle T (n • (T / 2 / n) : ℝ) : ℂ) = -1 := by rw [zsmul_eq_mul, toCircle, Function.Periodic.lift_coe, Circle.coe_exp] replace hT := Complex.ofReal_ne_zero.mpr hT.ne' convert Complex.exp_pi_mul_I using 3 field_simp; ring rw [this]; simp /-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` . -/ def fourierSubalgebra : StarSubalgebra ℂ C(AddCircle T, ℂ) where toSubalgebra := Algebra.adjoin ℂ (range fourier) star_mem' := by change Algebra.adjoin ℂ (range (fourier (T := T))) ≤ star (Algebra.adjoin ℂ (range (fourier (T := T)))) refine adjoin_le ?_ rintro - ⟨n, rfl⟩ exact subset_adjoin ⟨-n, ext fun _ => fourier_neg⟩ /-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is in fact the linear span of these functions. -/ theorem fourierSubalgebra_coe : Subalgebra.toSubmodule (@fourierSubalgebra T).toSubalgebra = span ℂ (range (@fourier T)) := by apply adjoin_eq_span_of_subset refine Subset.trans ?_ Submodule.subset_span intro x hx refine Submonoid.closure_induction (fun _ => id) ⟨0, ?_⟩ ?_ hx · ext1 z; exact fourier_zero · rintro - - - - ⟨m, rfl⟩ ⟨n, rfl⟩ refine ⟨m + n, ?_⟩ ext1 z exact fourier_add /- a post-port refactor made `fourierSubalgebra` into a `StarSubalgebra`, and eliminated `conjInvariantSubalgebra` entirely, making this lemma irrelevant. -/ variable [hT : Fact (0 < T)] /-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` separates points. -/ theorem fourierSubalgebra_separatesPoints : (@fourierSubalgebra T).SeparatesPoints := by intro x y hxy refine ⟨_, ⟨fourier 1, subset_adjoin ⟨1, rfl⟩, rfl⟩, ?_⟩ dsimp only; rw [fourier_one, fourier_one] contrapose! hxy rw [Subtype.coe_inj] at hxy exact injective_toCircle hT.elim.ne' hxy /-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is dense. -/ theorem fourierSubalgebra_closure_eq_top : (@fourierSubalgebra T).topologicalClosure = ⊤ := ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints fourierSubalgebra fourierSubalgebra_separatesPoints /-- The linear span of the monomials `fourier n` is dense in `C(AddCircle T, ℂ)`. -/ theorem span_fourier_closure_eq_top : (span ℂ (range <| @fourier T)).topologicalClosure = ⊤ := by rw [← fourierSubalgebra_coe] exact congr_arg (Subalgebra.toSubmodule <| StarSubalgebra.toSubalgebra ·) fourierSubalgebra_closure_eq_top /-- The family of monomials `fourier n`, parametrized by `n : ℤ` and considered as elements of the `Lp` space of functions `AddCircle T → ℂ`. -/ abbrev fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : Lp ℂ p (@haarAddCircle T hT) := toLp (E := ℂ) p haarAddCircle ℂ (fourier n) theorem coeFn_fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : @fourierLp T hT p _ n =ᵐ[haarAddCircle] fourier n := coeFn_toLp haarAddCircle (fourier n) /-- For each `1 ≤ p < ∞`, the linear span of the monomials `fourier n` is dense in `Lp ℂ p haarAddCircle`. -/ theorem span_fourierLp_closure_eq_top {p : ℝ≥0∞} [Fact (1 ≤ p)] (hp : p ≠ ∞) : (span ℂ (range (@fourierLp T _ p _))).topologicalClosure = ⊤ := by convert (ContinuousMap.toLp_denseRange ℂ (@haarAddCircle T hT) ℂ hp).topologicalClosure_map_submodule span_fourier_closure_eq_top rw [map_span] unfold fourierLp rw [range_comp'] simp only [ContinuousLinearMap.coe_coe] /-- The monomials `fourier n` are an orthonormal set with respect to normalised Haar measure. -/ theorem orthonormal_fourier : Orthonormal ℂ (@fourierLp T _ 2 _) := by rw [orthonormal_iff_ite] intro i j rw [ContinuousMap.inner_toLp (@haarAddCircle T hT) (fourier i) (fourier j)] simp_rw [← fourier_neg, ← fourier_add] split_ifs with h · simp_rw [h, add_neg_cancel] have : ⇑(@fourier T 0) = (fun _ => 1 : AddCircle T → ℂ) := by ext1; exact fourier_zero rw [this, integral_const, measureReal_univ_eq_one, Complex.real_smul, Complex.ofReal_one, mul_one] have hij : j + -i ≠ 0 := by exact sub_ne_zero.mpr (Ne.symm h) convert integral_eq_zero_of_add_right_eq_neg (μ := haarAddCircle) (fourier_add_half_inv_index hij hT.elim) end Monomials section ScopeHT -- everything from here on needs `0 < T` variable [hT : Fact (0 < T)] section fourierCoeff variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℂ E] /-- The `n`-th Fourier coefficient of a function `AddCircle T → E`, for `E` a complete normed `ℂ`-vector space, defined as the integral over `AddCircle T` of `fourier (-n) t • f t`. -/ def fourierCoeff (f : AddCircle T → E) (n : ℤ) : E := ∫ t : AddCircle T, fourier (-n) t • f t ∂haarAddCircle /-- The Fourier coefficients of a function on `AddCircle T` can be computed as an integral over `[a, a + T]`, for any real `a`. -/ theorem fourierCoeff_eq_intervalIntegral (f : AddCircle T → E) (n : ℤ) (a : ℝ) : fourierCoeff f n = (1 / T) • ∫ x in a..a + T, @fourier T (-n) x • f x := by have : ∀ x : ℝ, @fourier T (-n) x • f x = (fun z : AddCircle T => @fourier T (-n) z • f z) x := by intro x; rfl -- After https://github.com/leanprover/lean4/pull/3124, we need to add `singlePass := true` to avoid an infinite loop. simp_rw +singlePass [this] rw [fourierCoeff, AddCircle.intervalIntegral_preimage T a (fun z => _ • _), volume_eq_smul_haarAddCircle, integral_smul_measure, ENNReal.toReal_ofReal hT.out.le, ← smul_assoc, smul_eq_mul, one_div_mul_cancel hT.out.ne', one_smul] theorem fourierCoeff.const_smul (f : AddCircle T → E) (c : ℂ) (n : ℤ) : fourierCoeff (c • f :) n = c • fourierCoeff f n := by simp_rw [fourierCoeff, Pi.smul_apply, ← smul_assoc, smul_eq_mul, mul_comm, ← smul_eq_mul, smul_assoc, integral_smul] theorem fourierCoeff.const_mul (f : AddCircle T → ℂ) (c : ℂ) (n : ℤ) : fourierCoeff (fun x => c * f x) n = c * fourierCoeff f n := fourierCoeff.const_smul f c n /-- For a function on `ℝ`, the Fourier coefficients of `f` on `[a, b]` are defined as the Fourier coefficients of the unique periodic function agreeing with `f` on `Ioc a b`. -/ def fourierCoeffOn {a b : ℝ} (hab : a < b) (f : ℝ → E) (n : ℤ) : E := haveI := Fact.mk (by linarith : 0 < b - a) fourierCoeff (AddCircle.liftIoc (b - a) a f) n theorem fourierCoeffOn_eq_integral {a b : ℝ} (f : ℝ → E) (n : ℤ) (hab : a < b) : fourierCoeffOn hab f n = (1 / (b - a)) • ∫ x in a..b, fourier (-n) (x : AddCircle (b - a)) • f x := by haveI := Fact.mk (by linarith : 0 < b - a) rw [fourierCoeffOn, fourierCoeff_eq_intervalIntegral _ _ a, add_sub, add_sub_cancel_left] congr 1 simp_rw [intervalIntegral.integral_of_le hab.le] refine setIntegral_congr_fun measurableSet_Ioc fun x hx => ?_ rw [liftIoc_coe_apply] rwa [add_sub, add_sub_cancel_left] theorem fourierCoeffOn.const_smul {a b : ℝ} (f : ℝ → E) (c : ℂ) (n : ℤ) (hab : a < b) : fourierCoeffOn hab (c • f) n = c • fourierCoeffOn hab f n := by haveI := Fact.mk (by linarith : 0 < b - a) apply fourierCoeff.const_smul theorem fourierCoeffOn.const_mul {a b : ℝ} (f : ℝ → ℂ) (c : ℂ) (n : ℤ) (hab : a < b) : fourierCoeffOn hab (fun x => c * f x) n = c * fourierCoeffOn hab f n := fourierCoeffOn.const_smul _ _ _ _ theorem fourierCoeff_liftIoc_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) : fourierCoeff (AddCircle.liftIoc T a f) n = fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral, add_sub_cancel_left a T] · congr 1 refine intervalIntegral.integral_congr_ae (ae_of_all _ fun x hx => ?_) rw [liftIoc_coe_apply] rwa [uIoc_of_le (lt_add_of_pos_right a hT.out).le] at hx theorem fourierCoeff_liftIco_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) : fourierCoeff (AddCircle.liftIco T a f) n = fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral _ _ a, add_sub_cancel_left a T] congr 1 simp_rw [intervalIntegral.integral_of_le (lt_add_of_pos_right a hT.out).le] iterate 2 rw [integral_Ioc_eq_integral_Ioo] refine setIntegral_congr_fun measurableSet_Ioo fun x hx => ?_ rw [liftIco_coe_apply (Ioo_subset_Ico_self hx)] end fourierCoeff section FourierL2 /-- We define `fourierBasis` to be a `ℤ`-indexed Hilbert basis for `Lp ℂ 2 haarAddCircle`, which by definition is an isometric isomorphism from `Lp ℂ 2 haarAddCircle` to `ℓ²(ℤ, ℂ)`. -/ def fourierBasis : HilbertBasis ℤ ℂ (Lp ℂ 2 <| @haarAddCircle T hT) := HilbertBasis.mk orthonormal_fourier (span_fourierLp_closure_eq_top (by simp)).ge /-- The elements of the Hilbert basis `fourierBasis` are the functions `fourierLp 2`, i.e. the monomials `fourier n` on the circle considered as elements of `L²`. -/ @[simp] theorem coe_fourierBasis : ⇑(@fourierBasis T hT) = @fourierLp T hT 2 _ := HilbertBasis.coe_mk _ _ /-- Under the isometric isomorphism `fourierBasis` from `Lp ℂ 2 haarAddCircle` to `ℓ²(ℤ, ℂ)`, the `i`-th coefficient is `fourierCoeff f i`, i.e., the integral over `AddCircle T` of `fun t => fourier (-i) t * f t` with respect to the Haar measure of total mass 1. -/ theorem fourierBasis_repr (f : Lp ℂ 2 <| @haarAddCircle T hT) (i : ℤ) : fourierBasis.repr f i = fourierCoeff f i := by trans ∫ t : AddCircle T, conj ((@fourierLp T hT 2 _ i : AddCircle T → ℂ) t) * f t ∂haarAddCircle · rw [fourierBasis.repr_apply_apply f i, MeasureTheory.L2.inner_def, coe_fourierBasis] simp only [RCLike.inner_apply'] · apply integral_congr_ae filter_upwards [coeFn_fourierLp 2 i] with _ ht rw [ht, ← fourier_neg, smul_eq_mul] /-- The Fourier series of an `L2` function `f` sums to `f`, in the `L²` space of `AddCircle T`. -/ theorem hasSum_fourier_series_L2 (f : Lp ℂ 2 <| @haarAddCircle T hT) : HasSum (fun i => fourierCoeff f i • fourierLp 2 i) f := by simp_rw [← fourierBasis_repr]; rw [← coe_fourierBasis] exact HilbertBasis.hasSum_repr fourierBasis f /-- **Parseval's identity**: for an `L²` function `f` on `AddCircle T`, the sum of the squared norms of the Fourier coefficients equals the `L²` norm of `f`. -/ theorem tsum_sq_fourierCoeff (f : Lp ℂ 2 <| @haarAddCircle T hT) : ∑' i : ℤ, ‖fourierCoeff f i‖ ^ 2 = ∫ t : AddCircle T, ‖f t‖ ^ 2 ∂haarAddCircle := by simp_rw [← fourierBasis_repr] have H₁ : ‖fourierBasis.repr f‖ ^ 2 = ∑' i, ‖fourierBasis.repr f i‖ ^ 2 := by apply_mod_cast lp.norm_rpow_eq_tsum ?_ (fourierBasis.repr f) norm_num have H₂ : ‖fourierBasis.repr f‖ ^ 2 = ‖f‖ ^ 2 := by simp have H₃ := congr_arg RCLike.re (@L2.inner_def (AddCircle T) ℂ ℂ _ _ _ _ _ f f) rw [← integral_re] at H₃ · simp only [← norm_sq_eq_re_inner] at H₃ rw [← H₁, H₂, H₃] · exact L2.integrable_inner f f end FourierL2 section Convergence variable (f : C(AddCircle T, ℂ)) theorem fourierCoeff_toLp (n : ℤ) : fourierCoeff (toLp (E := ℂ) 2 haarAddCircle ℂ f) n = fourierCoeff f n := integral_congr_ae (Filter.EventuallyEq.mul (Filter.Eventually.of_forall (by tauto)) (ContinuousMap.coeFn_toAEEqFun haarAddCircle f)) variable {f} /-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series converges uniformly to `f`. -/ theorem hasSum_fourier_series_of_summable (h : Summable (fourierCoeff f)) : HasSum (fun i => fourierCoeff f i • fourier i) f := by have sum_L2 := hasSum_fourier_series_L2 (toLp (E := ℂ) 2 haarAddCircle ℂ f) simp_rw [fourierCoeff_toLp] at sum_L2 refine ContinuousMap.hasSum_of_hasSum_Lp (.of_norm ?_) sum_L2 simp_rw [norm_smul, fourier_norm, mul_one] exact h.norm /-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series of `f` converges everywhere pointwise to `f`. -/ theorem has_pointwise_sum_fourier_series_of_summable (h : Summable (fourierCoeff f)) (x : AddCircle T) : HasSum (fun i => fourierCoeff f i • fourier i x) (f x) := by convert (ContinuousMap.evalCLM ℂ x).hasSum (hasSum_fourier_series_of_summable h) end Convergence end ScopeHT section deriv open Complex intervalIntegral open scoped Interval variable (T) theorem hasDerivAt_fourier (n : ℤ) (x : ℝ) : HasDerivAt (fun y : ℝ => fourier n (y : AddCircle T)) (2 * π * I * n / T * fourier n (x : AddCircle T)) x := by simp_rw [fourier_coe_apply] refine (?_ : HasDerivAt (fun y => exp (2 * π * I * n * y / T)) _ _).comp_ofReal rw [(fun α β => by ring : ∀ α β : ℂ, α * exp β = exp β * α)] refine (hasDerivAt_exp _).comp (x : ℂ) ?_ convert hasDerivAt_mul_const (2 * ↑π * I * ↑n / T) using 1 ext1 y; ring theorem hasDerivAt_fourier_neg (n : ℤ) (x : ℝ) : HasDerivAt (fun y : ℝ => fourier (-n) (y : AddCircle T)) (-2 * π * I * n / T * fourier (-n) (x : AddCircle T)) x := by simpa using hasDerivAt_fourier T (-n) x variable {T} theorem has_antideriv_at_fourier_neg (hT : Fact (0 < T)) {n : ℤ} (hn : n ≠ 0) (x : ℝ) : HasDerivAt (fun y : ℝ => (T : ℂ) / (-2 * π * I * n) * fourier (-n) (y : AddCircle T)) (fourier (-n) (x : AddCircle T)) x := by convert (hasDerivAt_fourier_neg T n x).div_const (-2 * π * I * n / T) using 1 · ext1 y; rw [div_div_eq_mul_div]; ring · simp [mul_div_cancel_left₀, hn, (Fact.out : 0 < T).ne', Real.pi_pos.ne'] /-- Express Fourier coefficients of `f` on an interval in terms of those of its derivative. -/ theorem fourierCoeffOn_of_hasDeriv_right {a b : ℝ} (hab : a < b) {f f' : ℝ → ℂ} {n : ℤ} (hn : n ≠ 0) (hf : ContinuousOn f [[a, b]]) (hff' : ∀ x, x ∈ Ioo (min a b) (max a b) → HasDerivWithinAt f (f' x) (Ioi x) x) (hf' : IntervalIntegrable f' volume a b) : fourierCoeffOn hab f n = 1 / (-2 * π * I * n) * (fourier (-n) (a : AddCircle (b - a)) * (f b - f a) - (b - a) * fourierCoeffOn hab f' n) := by rw [← ofReal_sub] have hT : Fact (0 < b - a) := ⟨by linarith⟩ simp_rw [fourierCoeffOn_eq_integral, smul_eq_mul, real_smul, ofReal_div, ofReal_one] conv => pattern (occs := 1 2 3) fourier _ _ * _ <;> (rw [mul_comm]) rw [integral_mul_deriv_eq_deriv_mul_of_hasDeriv_right hf (fun x _ ↦ has_antideriv_at_fourier_neg hT hn x |>.continuousAt |>.continuousWithinAt) hff' (fun x _ ↦ has_antideriv_at_fourier_neg hT hn x |>.hasDerivWithinAt) hf' (((map_continuous (fourier (-n))).comp (AddCircle.continuous_mk' _)).intervalIntegrable _ _)] have : ∀ u v w : ℂ, u * ((b - a : ℝ) / v * w) = (b - a : ℝ) / v * (u * w) := by intros; ring conv in intervalIntegral _ _ _ _ => congr; ext; rw [this] rw [(by ring : ((b - a : ℝ) : ℂ) / (-2 * π * I * n) = ((b - a : ℝ) : ℂ) * (1 / (-2 * π * I * n)))] have s2 : (b : AddCircle (b - a)) = (a : AddCircle (b - a)) := by simpa using coe_add_period (b - a) a rw [s2, intervalIntegral.integral_const_mul, ← sub_mul, mul_sub, mul_sub] congr 1 · conv_lhs => rw [mul_comm, mul_div, mul_one] rw [div_eq_iff (ofReal_ne_zero.mpr hT.out.ne')] ring · ring /-- Express Fourier coefficients of `f` on an interval in terms of those of its derivative. -/ theorem fourierCoeffOn_of_hasDerivAt_Ioo {a b : ℝ} (hab : a < b) {f f' : ℝ → ℂ} {n : ℤ} (hn : n ≠ 0) (hf : ContinuousOn f [[a, b]]) (hff' : ∀ x, x ∈ Ioo (min a b) (max a b) → HasDerivAt f (f' x) x) (hf' : IntervalIntegrable f' volume a b) : fourierCoeffOn hab f n = 1 / (-2 * π * I * n) * (fourier (-n) (a : AddCircle (b - a)) * (f b - f a) - (b - a) * fourierCoeffOn hab f' n) := fourierCoeffOn_of_hasDeriv_right hab hn hf (fun x hx ↦ hff' x hx |>.hasDerivWithinAt) hf' /-- Express Fourier coefficients of `f` on an interval in terms of those of its derivative. -/ theorem fourierCoeffOn_of_hasDerivAt {a b : ℝ} (hab : a < b) {f f' : ℝ → ℂ} {n : ℤ} (hn : n ≠ 0) (hf : ∀ x, x ∈ [[a, b]] → HasDerivAt f (f' x) x) (hf' : IntervalIntegrable f' volume a b) : fourierCoeffOn hab f n = 1 / (-2 * π * I * n) * (fourier (-n) (a : AddCircle (b - a)) * (f b - f a) - (b - a) * fourierCoeffOn hab f' n) := fourierCoeffOn_of_hasDerivAt_Ioo hab hn (fun x hx ↦ hf x hx |>.continuousAt.continuousWithinAt) (fun x hx ↦ hf x <| mem_Icc_of_Ioo hx) hf' end deriv
ULift.lean
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Group.ULift import Mathlib.Algebra.Ring.Equiv import Mathlib.Data.Int.Cast.Basic /-! # `ULift` instances for ring This file defines instances for ring, semiring and related structures on `ULift` types. (Recall `ULift R` is just a "copy" of a type `R` in a higher universe.) We also provide `ULift.ringEquiv : ULift R ≃+* R`. -/ universe u v variable {R : Type u} namespace ULift instance mulZeroClass {M₀ : Type*} [MulZeroClass M₀] : MulZeroClass (ULift M₀) := { zero := (0 : ULift M₀), mul := (· * ·), zero_mul := fun _ => (Equiv.ulift).injective (by simp), mul_zero := fun _ => (Equiv.ulift).injective (by simp) } instance distrib [Distrib R] : Distrib (ULift R) := { add := (· + ·), mul := (· * ·), left_distrib := fun _ _ _ => (Equiv.ulift).injective (by simp [left_distrib]), right_distrib := fun _ _ _ => (Equiv.ulift).injective (by simp [right_distrib]) } instance instNatCast [NatCast R] : NatCast (ULift R) := ⟨(up ·)⟩ instance instIntCast [IntCast R] : IntCast (ULift R) := ⟨(up ·)⟩ @[simp, norm_cast] theorem up_natCast [NatCast R] (n : ℕ) : up (n : R) = n := rfl @[simp] theorem up_ofNat [NatCast R] (n : ℕ) [n.AtLeastTwo] : up (ofNat(n) : R) = ofNat(n) := rfl @[simp, norm_cast] theorem up_intCast [IntCast R] (n : ℤ) : up (n : R) = n := rfl @[simp, norm_cast] theorem down_natCast [NatCast R] (n : ℕ) : down (n : ULift R) = n := rfl @[simp] theorem down_ofNat [NatCast R] (n : ℕ) [n.AtLeastTwo] : down (ofNat(n) : ULift R) = ofNat(n) := rfl @[simp, norm_cast] theorem down_intCast [IntCast R] (n : ℤ) : down (n : ULift R) = n := rfl instance addMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ULift R) := { ULift.one, ULift.addMonoid with natCast := (⟨·⟩) natCast_zero := congr_arg ULift.up Nat.cast_zero, natCast_succ := fun _ => congr_arg ULift.up (Nat.cast_succ _) } instance addCommMonoidWithOne [AddCommMonoidWithOne R] : AddCommMonoidWithOne (ULift R) := { ULift.addMonoidWithOne, ULift.addCommMonoid with } instance addGroupWithOne [AddGroupWithOne R] : AddGroupWithOne (ULift R) := { ULift.addMonoidWithOne, ULift.addGroup with intCast := (⟨·⟩), intCast_ofNat := fun _ => congr_arg ULift.up (Int.cast_natCast _), intCast_negSucc := fun _ => congr_arg ULift.up (Int.cast_negSucc _) } instance addCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne (ULift R) := { ULift.addGroupWithOne, ULift.addCommGroup with } instance nonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] : NonUnitalNonAssocSemiring (ULift R) := { zero := (0 : ULift R), add := (· + ·), mul := (· * ·), nsmul := AddMonoid.nsmul, zero_add, add_zero, zero_mul, mul_zero, left_distrib, right_distrib, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, add_assoc, add_comm } instance nonAssocSemiring [NonAssocSemiring R] : NonAssocSemiring (ULift R) := { ULift.addMonoidWithOne with nsmul := AddMonoid.nsmul, natCast := fun n => ULift.up n, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, one_mul, mul_one } instance nonUnitalSemiring [NonUnitalSemiring R] : NonUnitalSemiring (ULift R) := { zero := (0 : ULift R), add := (· + ·), mul := (· * ·), nsmul := AddMonoid.nsmul, add_assoc, zero_add, add_zero, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _ } instance semiring [Semiring R] : Semiring (ULift R) := { ULift.addMonoidWithOne with nsmul := AddMonoid.nsmul, npow := Monoid.npow, natCast := fun n => ULift.up n, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, one_mul, mul_one, npow_zero := fun _ => Monoid.npow_zero _, npow_succ := fun _ _ => Monoid.npow_succ _ _ } /-- The ring equivalence between `ULift R` and `R`. -/ def ringEquiv [NonUnitalNonAssocSemiring R] : ULift R ≃+* R where toFun := ULift.down invFun := ULift.up map_mul' _ _ := rfl map_add' _ _ := rfl left_inv := fun _ => rfl right_inv := fun _ => rfl instance nonUnitalCommSemiring [NonUnitalCommSemiring R] : NonUnitalCommSemiring (ULift R) := { zero := (0 : ULift R), add := (· + ·), mul := (· * ·), nsmul := AddMonoid.nsmul, add_assoc, zero_add, add_zero, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, mul_comm, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _ } instance commSemiring [CommSemiring R] : CommSemiring (ULift R) := { ULift.semiring with nsmul := AddMonoid.nsmul, natCast := fun n => ULift.up n, npow := Monoid.npow, mul_comm } instance nonUnitalNonAssocRing [NonUnitalNonAssocRing R] : NonUnitalNonAssocRing (ULift R) := { zero := (0 : ULift R), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, zsmul := SubNegMonoid.zsmul, add_assoc, zero_add, add_zero, neg_add_cancel, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, sub_eq_add_neg, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg' } instance nonUnitalRing [NonUnitalRing R] : NonUnitalRing (ULift R) := { zero := (0 : ULift R), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, zsmul := SubNegMonoid.zsmul, add_assoc, zero_add, add_zero, add_comm, neg_add_cancel, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, sub_eq_add_neg nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg' } instance nonAssocRing [NonAssocRing R] : NonAssocRing (ULift R) := { zero := (0 : ULift R), one := (1 : ULift R), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, natCast := fun n => ULift.up n, intCast := fun n => ULift.up n, zsmul := SubNegMonoid.zsmul, intCast_ofNat := addGroupWithOne.intCast_ofNat, add_assoc, zero_add, add_zero, neg_add_cancel, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, one_mul, mul_one, sub_eq_add_neg, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg', natCast_zero := AddMonoidWithOne.natCast_zero, natCast_succ := AddMonoidWithOne.natCast_succ, intCast_negSucc := AddGroupWithOne.intCast_negSucc } instance ring [Ring R] : Ring (ULift R) := { zero := (0 : ULift R), one := (1 : ULift R), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, npow := Monoid.npow, zsmul := SubNegMonoid.zsmul, intCast_ofNat := addGroupWithOne.intCast_ofNat, add_assoc, zero_add, add_zero, add_comm, left_distrib, right_distrib, zero_mul, mul_zero, mul_assoc, one_mul, mul_one, sub_eq_add_neg, neg_add_cancel, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, natCast := fun n => ULift.up n, intCast := fun n => ULift.up n, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, natCast_zero := AddMonoidWithOne.natCast_zero, natCast_succ := AddMonoidWithOne.natCast_succ, npow_zero := fun _ => Monoid.npow_zero _, npow_succ := fun _ _ => Monoid.npow_succ _ _, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg', intCast_negSucc := AddGroupWithOne.intCast_negSucc } instance nonUnitalCommRing [NonUnitalCommRing R] : NonUnitalCommRing (ULift R) := { zero := (0 : ULift R), add := (· + ·), mul := (· * ·), sub := Sub.sub, neg := Neg.neg, nsmul := AddMonoid.nsmul, zsmul := SubNegMonoid.zsmul, zero_mul, add_assoc, zero_add, add_zero, mul_zero, left_distrib, right_distrib, add_comm, mul_assoc, mul_comm, nsmul_zero := fun _ => AddMonoid.nsmul_zero _, neg_add_cancel, nsmul_succ := fun _ _ => AddMonoid.nsmul_succ _ _, sub_eq_add_neg, zsmul_zero' := SubNegMonoid.zsmul_zero', zsmul_succ' := SubNegMonoid.zsmul_succ', zsmul_neg' := SubNegMonoid.zsmul_neg'.. } instance commRing [CommRing R] : CommRing (ULift R) := { ULift.ring with mul_comm } end ULift
Instances.lean
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Control.EquivFunctor import Mathlib.Data.Fintype.OfMap /-! # `EquivFunctor` instances We derive some `EquivFunctor` instances, to enable `equiv_rw` to rewrite under these functions. -/ open Equiv instance EquivFunctorUnique : EquivFunctor Unique where map e := Equiv.uniqueCongr e map_refl' α := by simp [eq_iff_true_of_subsingleton] map_trans' := by simp [eq_iff_true_of_subsingleton] instance EquivFunctorPerm : EquivFunctor Perm where map e p := (e.symm.trans p).trans e map_refl' α := by ext; simp map_trans' _ _ := by ext; simp -- There is a classical instance of `LawfulFunctor Finset` available, -- but we provide this computable alternative separately. instance EquivFunctorFinset : EquivFunctor Finset where map e s := s.map e.toEmbedding map_refl' α := by ext; simp map_trans' k h := by ext _ a; simp; constructor <;> intro h' · let ⟨a, ha₁, ha₂⟩ := h' rw [← ha₂]; simpa · exists (Equiv.symm k) ((Equiv.symm h) a) simp [h'] instance EquivFunctorFintype : EquivFunctor Fintype where map e _ := Fintype.ofBijective e e.bijective map_refl' α := by ext; simp [eq_iff_true_of_subsingleton] map_trans' := by simp [eq_iff_true_of_subsingleton]
Relation.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Logic.Relator import Mathlib.Tactic.Use import Mathlib.Tactic.MkIffOfInductiveProp import Mathlib.Tactic.SimpRw import Mathlib.Logic.Basic import Mathlib.Order.Defs.Unbundled /-! # Relation closures This file defines the reflexive, transitive, reflexive transitive and equivalence closures of relations and proves some basic results on them. Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For the bundled version, see `Rel`. ## Definitions * `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all `a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`. * `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`. * `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything `r` related transitively, plus for all `a` it relates `a` with itself. So `ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as the reflexive closure of the transitive closure, or the transitive closure of the reflexive closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of rewrites. * `Relation.EqvGen`: Equivalence closure. `EqvGen r` relates everything `ReflTransGen r` relates, plus for all related pairs it relates them in the opposite order. * `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and `s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to both. * `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`, `g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b` related by `r`. * `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term. -/ open Function variable {α β γ δ ε ζ : Type*} section NeImp variable {r : α → α → Prop} theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x /-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`, it suffices to show it holds when `x ≠ y`. -/ theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by by_cases hxy : x = y · exact hxy ▸ h x · exact hr hxy /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. -/ theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y := ⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩ /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/ theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y := IsRefl.reflexive.ne_imp_iff protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x := ⟨fun h ↦ H h, fun h ↦ H h⟩ theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r := funext₂ fun _ _ ↦ propext <| h.iff _ _ theorem Symmetric.swap_eq : Symmetric r → swap r = r := Symmetric.flip_eq theorem flip_eq_iff : flip r = r ↔ Symmetric r := ⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩ theorem swap_eq_iff : swap r = r ↔ Symmetric r := flip_eq_iff end NeImp section Comap variable {r : β → β → Prop} theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a) theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) := fun _ _ _ hab hbc ↦ h hab hbc theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) := ⟨fun a ↦ h.refl (f a), h.symm, h.trans⟩ end Comap namespace Relation section Comp variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop} /-- The composition of two relations, yielding a new relation. The result relates a term of `α` and a term of `γ` if there is an intermediate term of `β` related to both. -/ def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃ b, r a b ∧ p b c @[inherit_doc] local infixr:80 " ∘r " => Relation.Comp @[simp] theorem comp_eq_fun (f : γ → β) : r ∘r (· = f ·) = (r · <| f ·) := by ext x y simp [Comp] @[simp] theorem comp_eq : r ∘r (· = ·) = r := comp_eq_fun .. @[simp] theorem fun_eq_comp (f : γ → α) : (f · = ·) ∘r r = (r <| f ·) := by ext x y simp [Comp] @[simp] theorem eq_comp : (· = ·) ∘r r = r := fun_eq_comp .. @[simp] theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, eq_comp] @[simp] theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, comp_eq] theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by funext a d apply propext constructor · exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩ · exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩ theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by funext c a apply propext constructor · exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩ · exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩ end Comp section Fibration variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β) /-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all `a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/ def Fibration := ∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b variable {rα rβ} /-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is accessible under `rα`, then `f a` is accessible under `rβ`. -/ theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by induction ha with | intro a _ ih => ?_ refine Acc.intro (f a) fun b hr ↦ ?_ obtain ⟨a', hr', rfl⟩ := fib hr exact ih a' hr' theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α) (ha : Acc (InvImage rβ f) a) : Acc rβ (f a) := ha.of_fibration f fun a _ h ↦ let ⟨a', he⟩ := dc h ⟨a', by simp_all [InvImage], he⟩ end Fibration section Map variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ} /-- The map of a relation `r` through a pair of functions pushes the relation to the codomains of the functions. The resulting relation is defined by having pairs of terms related if they have preimages related by `r`. -/ protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦ ∃ a b, r a b ∧ f a = c ∧ g b = d lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl @[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) : Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by ext a b simp_rw [Relation.Map, Function.comp_apply, ← exists_and_right, @exists_comm γ, @exists_comm δ] refine exists₂_congr fun a b ↦ ⟨?_, fun h ↦ ⟨_, _, ⟨⟨h.1, rfl, rfl⟩, h.2⟩⟩⟩ rintro ⟨_, _, ⟨hab, rfl, rfl⟩, h⟩ exact ⟨hab, h⟩ @[simp] lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) : Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff] @[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map] instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) := ‹Decidable _› lemma map_reflexive {r : α → α → Prop} (hr : Reflexive r) {f : α → β} (hf : f.Surjective) : Reflexive (Relation.Map r f f) := by intro x obtain ⟨y, rfl⟩ := hf x exact ⟨y, y, hr y, rfl, rfl⟩ lemma map_symmetric {r : α → α → Prop} (hr : Symmetric r) (f : α → β) : Symmetric (Relation.Map r f f) := by rintro _ _ ⟨x, y, hxy, rfl, rfl⟩; exact ⟨_, _, hr hxy, rfl, rfl⟩ lemma map_transitive {r : α → α → Prop} (hr : Transitive r) {f : α → β} (hf : ∀ x y, f x = f y → r x y) : Transitive (Relation.Map r f f) := by rintro _ _ _ ⟨x, y, hxy, rfl, rfl⟩ ⟨y', z, hyz, hy, rfl⟩ exact ⟨x, z, hr hxy <| hr (hf _ _ hy.symm) hyz, rfl, rfl⟩ lemma map_equivalence {r : α → α → Prop} (hr : Equivalence r) (f : α → β) (hf : f.Surjective) (hf_ker : ∀ x y, f x = f y → r x y) : Equivalence (Relation.Map r f f) where refl := map_reflexive hr.reflexive hf symm := @(map_symmetric hr.symmetric _) trans := @(map_transitive hr.transitive hf_ker) -- TODO: state this using `≤`, after adjusting imports. lemma map_mono {r s : α → β → Prop} {f : α → γ} {g : β → δ} (h : ∀ x y, r x y → s x y) : ∀ x y, Relation.Map r f g x y → Relation.Map s f g x y := fun _ _ ⟨x, y, hxy, hx, hy⟩ => ⟨x, y, h _ _ hxy, hx, hy⟩ end Map variable {r : α → α → Prop} {a b c : α} /-- `ReflTransGen r`: reflexive transitive closure of `r` -/ @[mk_iff ReflTransGen.cases_tail_iff] inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop | refl : ReflTransGen r a a | tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c attribute [refl] ReflTransGen.refl /-- `ReflGen r`: reflexive closure of `r` -/ @[mk_iff] inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop | refl : ReflGen r a a | single {b} : r a b → ReflGen r a b variable (r) in /-- `EqvGen r`: equivalence closure of `r`. -/ @[mk_iff] inductive EqvGen : α → α → Prop | rel x y : r x y → EqvGen x y | refl x : EqvGen x x | symm x y : EqvGen x y → EqvGen y x | trans x y z : EqvGen x y → EqvGen y z → EqvGen x z attribute [mk_iff] TransGen attribute [refl] ReflGen.refl namespace ReflGen theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b | a, _, refl => by rfl | _, _, single h => ReflTransGen.tail ReflTransGen.refl h theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b | a, _, ReflGen.refl => by rfl | a, b, single h => single (hp a b h) instance : IsRefl α (ReflGen r) := ⟨@refl α r⟩ end ReflGen namespace ReflTransGen @[trans] theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by induction hbc with | refl => assumption | tail _ hcd hac => exact hac.tail hcd theorem single (hab : r a b) : ReflTransGen r a b := refl.tail hab theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by induction hbc with | refl => exact refl.tail hab | tail _ hcd hac => exact hac.tail hcd theorem symmetric (h : Symmetric r) : Symmetric (ReflTransGen r) := by intro x y h induction h with | refl => rfl | tail _ b c => apply Relation.ReflTransGen.head (h b) c theorem cases_tail : ReflTransGen r a b → b = a ∨ ∃ c, ReflTransGen r a c ∧ r c b := (cases_tail_iff r a b).1 @[elab_as_elim] theorem head_induction_on {motive : ∀ a : α, ReflTransGen r a b → Prop} {a : α} (h : ReflTransGen r a b) (refl : motive b refl) (head : ∀ {a c} (h' : r a c) (h : ReflTransGen r c b), motive c h → motive a (h.head h')) : motive a h := by induction h with | refl => exact refl | @tail b c _ hbc ih => apply ih · exact head hbc _ refl · exact fun h1 h2 ↦ head h1 (h2.tail hbc) @[elab_as_elim] theorem trans_induction_on {motive : ∀ {a b : α}, ReflTransGen r a b → Prop} {a b : α} (h : ReflTransGen r a b) (refl : ∀ a, @motive a a refl) (single : ∀ {a b} (h : r a b), motive (single h)) (trans : ∀ {a b c} (h₁ : ReflTransGen r a b) (h₂ : ReflTransGen r b c), motive h₁ → motive h₂ → motive (h₁.trans h₂)) : motive h := by induction h with | refl => exact refl a | tail hab hbc ih => exact trans hab (.single hbc) ih (single hbc) theorem cases_head (h : ReflTransGen r a b) : a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by induction h using Relation.ReflTransGen.head_induction_on <;> grind theorem cases_head_iff : ReflTransGen r a b ↔ a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by use cases_head rintro (rfl | ⟨c, hac, hcb⟩) · rfl · exact head hac hcb theorem total_of_right_unique (U : Relator.RightUnique r) (ab : ReflTransGen r a b) (ac : ReflTransGen r a c) : ReflTransGen r b c ∨ ReflTransGen r c b := by induction ab with | refl => exact Or.inl ac | tail _ bd IH => rcases IH with (IH | IH) · rcases cases_head IH with (rfl | ⟨e, be, ec⟩) · exact Or.inr (single bd) · cases U bd be exact Or.inl ec · exact Or.inr (IH.tail bd) end ReflTransGen namespace TransGen theorem to_reflTransGen {a b} (h : TransGen r a b) : ReflTransGen r a b := by induction h with | single h => exact ReflTransGen.single h | tail _ bc ab => exact ReflTransGen.tail ab bc theorem trans_left (hab : TransGen r a b) (hbc : ReflTransGen r b c) : TransGen r a c := by induction hbc with | refl => assumption | tail _ hcd hac => exact hac.tail hcd attribute [trans] trans theorem head' (hab : r a b) (hbc : ReflTransGen r b c) : TransGen r a c := trans_left (single hab) hbc theorem tail' (hab : ReflTransGen r a b) (hbc : r b c) : TransGen r a c := by induction hab generalizing c with | refl => exact single hbc | tail _ hdb IH => exact tail (IH hdb) hbc theorem head (hab : r a b) (hbc : TransGen r b c) : TransGen r a c := head' hab hbc.to_reflTransGen @[elab_as_elim] theorem head_induction_on {motive : ∀ a : α, TransGen r a b → Prop} {a : α} (h : TransGen r a b) (single : ∀ {a} (h : r a b), motive a (single h)) (head : ∀ {a c} (h' : r a c) (h : TransGen r c b), motive c h → motive a (h.head h')) : motive a h := by induction h with | single h => exact single h | @tail b c _ hbc h_ih => apply h_ih · exact fun h ↦ head h (.single hbc) (single hbc) · exact fun hab hbc ↦ head hab _ @[elab_as_elim] theorem trans_induction_on {motive : ∀ {a b : α}, TransGen r a b → Prop} {a b : α} (h : TransGen r a b) (single : ∀ {a b} (h : r a b), motive (single h)) (trans : ∀ {a b c} (h₁ : TransGen r a b) (h₂ : TransGen r b c), motive h₁ → motive h₂ → motive (h₁.trans h₂)) : motive h := by induction h with | single h => exact single h | tail hab hbc h_ih => exact trans hab (.single hbc) h_ih (single hbc) theorem trans_right (hab : ReflTransGen r a b) (hbc : TransGen r b c) : TransGen r a c := by induction hbc with | single hbc => exact tail' hab hbc | tail _ hcd hac => exact hac.tail hcd theorem tail'_iff : TransGen r a c ↔ ∃ b, ReflTransGen r a b ∧ r b c := by refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ tail' hab hbc⟩ cases h with | single hac => exact ⟨_, by rfl, hac⟩ | tail hab hbc => exact ⟨_, hab.to_reflTransGen, hbc⟩ theorem head'_iff : TransGen r a c ↔ ∃ b, r a b ∧ ReflTransGen r b c := by refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ head' hab hbc⟩ induction h with | single hac => exact ⟨_, hac, by rfl⟩ | tail _ hbc IH => rcases IH with ⟨d, had, hdb⟩ exact ⟨_, had, hdb.tail hbc⟩ end TransGen section reflGen lemma reflGen_eq_self (hr : Reflexive r) : ReflGen r = r := by ext x y simpa only [reflGen_iff, or_iff_right_iff_imp] using fun h ↦ h ▸ hr y lemma reflexive_reflGen : Reflexive (ReflGen r) := fun _ ↦ .refl lemma reflGen_minimal {r' : α → α → Prop} (hr' : Reflexive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflGen r x y) : r' x y := by simpa [reflGen_eq_self hr'] using ReflGen.mono h hxy end reflGen section TransGen instance : IsTrans α (TransGen r) := ⟨@TransGen.trans α r⟩ instance : Trans (TransGen r) r (TransGen r) := ⟨TransGen.tail⟩ instance : Trans r (TransGen r) (TransGen r) := ⟨TransGen.head⟩ instance : Trans (TransGen r) (ReflTransGen r) (TransGen r) := ⟨TransGen.trans_left⟩ instance : Trans (ReflTransGen r) (TransGen r) (TransGen r) := ⟨TransGen.trans_right⟩ theorem transGen_eq_self (trans : Transitive r) : TransGen r = r := funext fun a ↦ funext fun b ↦ propext <| ⟨fun h ↦ by induction h with | single hc => exact hc | tail _ hcd hac => exact trans hac hcd, TransGen.single⟩ theorem transitive_transGen : Transitive (TransGen r) := fun _ _ _ ↦ TransGen.trans theorem transGen_idem : TransGen (TransGen r) = TransGen r := transGen_eq_self transitive_transGen theorem TransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b)) (hab : TransGen r a b) : TransGen p (f a) (f b) := by induction hab with | single hac => exact TransGen.single (h a _ hac) | tail _ hcd hac => exact TransGen.tail hac (h _ _ hcd) theorem TransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → TransGen p (f a) (f b)) (hab : TransGen r a b) : TransGen p (f a) (f b) := by simpa [transGen_idem] using hab.lift f h theorem TransGen.closed {p : α → α → Prop} : (∀ a b, r a b → TransGen p a b) → TransGen r a b → TransGen p a b := TransGen.lift' id lemma TransGen.closed' {P : α → Prop} (dc : ∀ {a b}, r a b → P b → P a) {a b : α} (h : TransGen r a b) : P b → P a := h.head_induction_on dc fun hr _ hi ↦ dc hr ∘ hi theorem TransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) → TransGen r a b → TransGen p a b := TransGen.lift id lemma transGen_minimal {r' : α → α → Prop} (hr' : Transitive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : TransGen r x y) : r' x y := by simpa [transGen_eq_self hr'] using TransGen.mono h hxy theorem TransGen.swap (h : TransGen r b a) : TransGen (swap r) a b := by induction h with | single h => exact TransGen.single h | tail _ hbc ih => exact ih.head hbc theorem transGen_swap : TransGen (swap r) a b ↔ TransGen r b a := ⟨TransGen.swap, TransGen.swap⟩ end TransGen section ReflTransGen open ReflTransGen theorem reflTransGen_iff_eq (h : ∀ b, ¬r a b) : ReflTransGen r a b ↔ b = a := by rw [cases_head_iff]; simp [h, eq_comm] theorem reflTransGen_iff_eq_or_transGen : ReflTransGen r a b ↔ b = a ∨ TransGen r a b := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · cases h with | refl => exact Or.inl rfl | tail hac hcb => exact Or.inr (TransGen.tail' hac hcb) · rcases h with (rfl | h) · rfl · exact h.to_reflTransGen theorem ReflTransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := ReflTransGen.trans_induction_on hab (fun _ ↦ refl) (ReflTransGen.single ∘ h _ _) fun _ _ ↦ trans theorem ReflTransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) → ReflTransGen r a b → ReflTransGen p a b := ReflTransGen.lift id theorem reflTransGen_eq_self (refl : Reflexive r) (trans : Transitive r) : ReflTransGen r = r := funext fun a ↦ funext fun b ↦ propext <| ⟨fun h ↦ by induction h with | refl => apply refl | tail _ h₂ IH => exact trans IH h₂, single⟩ lemma reflTransGen_minimal {r' : α → α → Prop} (hr₁ : Reflexive r') (hr₂ : Transitive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflTransGen r x y) : r' x y := by simpa [reflTransGen_eq_self hr₁ hr₂] using ReflTransGen.mono h hxy theorem reflexive_reflTransGen : Reflexive (ReflTransGen r) := fun _ ↦ refl theorem transitive_reflTransGen : Transitive (ReflTransGen r) := fun _ _ _ ↦ trans instance : Trans r (ReflTransGen r) (ReflTransGen r) := ⟨head⟩ instance : Trans (ReflTransGen r) r (ReflTransGen r) := ⟨tail⟩ instance : IsRefl α (ReflTransGen r) := ⟨@ReflTransGen.refl α r⟩ instance : IsTrans α (ReflTransGen r) := ⟨@ReflTransGen.trans α r⟩ theorem reflTransGen_idem : ReflTransGen (ReflTransGen r) = ReflTransGen r := reflTransGen_eq_self reflexive_reflTransGen transitive_reflTransGen theorem ReflTransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → ReflTransGen p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := by simpa [reflTransGen_idem] using hab.lift f h theorem reflTransGen_closed {p : α → α → Prop} : (∀ a b, r a b → ReflTransGen p a b) → ReflTransGen r a b → ReflTransGen p a b := ReflTransGen.lift' id theorem ReflTransGen.swap (h : ReflTransGen r b a) : ReflTransGen (swap r) a b := by induction h with | refl => rfl | tail _ hbc ih => exact ih.head hbc theorem reflTransGen_swap : ReflTransGen (swap r) a b ↔ ReflTransGen r b a := ⟨ReflTransGen.swap, ReflTransGen.swap⟩ @[simp] lemma reflGen_transGen : ReflGen (TransGen r) = ReflTransGen r := by ext x y simp_rw [reflTransGen_iff_eq_or_transGen, reflGen_iff] @[simp] lemma transGen_reflGen : TransGen (ReflGen r) = ReflTransGen r := by ext x y refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · simpa [reflTransGen_idem] using TransGen.to_reflTransGen <| TransGen.mono (fun _ _ ↦ ReflGen.to_reflTransGen) h · obtain (rfl | h) := reflTransGen_iff_eq_or_transGen.mp h · exact .single .refl · exact TransGen.mono (fun _ _ ↦ .single) h @[simp] lemma reflTransGen_reflGen : ReflTransGen (ReflGen r) = ReflTransGen r := by simp only [← transGen_reflGen, reflGen_eq_self reflexive_reflGen] @[simp] lemma reflTransGen_transGen : ReflTransGen (TransGen r) = ReflTransGen r := by simp only [← reflGen_transGen, transGen_idem] lemma reflTransGen_eq_transGen (hr : Reflexive r) : ReflTransGen r = TransGen r := by rw [← transGen_reflGen, reflGen_eq_self hr] lemma reflTransGen_eq_reflGen (hr : Transitive r) : ReflTransGen r = ReflGen r := by rw [← reflGen_transGen, transGen_eq_self hr] end ReflTransGen namespace EqvGen variable (r) theorem is_equivalence : Equivalence (@EqvGen α r) := Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _) /-- `EqvGen.setoid r` is the setoid generated by a relation `r`. The motivation for this definition is that `Quot r` behaves like `Quotient (EqvGen.setoid r)`, see for example `Quot.eqvGen_exact` and `Quot.eqvGen_sound`. -/ def setoid : Setoid α := Setoid.mk _ (EqvGen.is_equivalence r) theorem mono {r p : α → α → Prop} (hrp : ∀ a b, r a b → p a b) (h : EqvGen r a b) : EqvGen p a b := by induction h with | rel a b h => exact EqvGen.rel _ _ (hrp _ _ h) | refl => exact EqvGen.refl _ | symm a b _ ih => exact EqvGen.symm _ _ ih | trans a b c _ _ hab hbc => exact EqvGen.trans _ _ _ hab hbc end EqvGen /-- The join of a relation on a single type is a new relation for which pairs of terms are related if there is a third term they are both related to. For example, if `r` is a relation representing rewrites in a term rewriting system, then *confluence* is the property that if `a` rewrites to both `b` and `c`, then `join r` relates `b` and `c` (see `Relation.church_rosser`). -/ def Join (r : α → α → Prop) : α → α → Prop := fun a b ↦ ∃ c, r a c ∧ r b c section Join open ReflTransGen ReflGen /-- A sufficient condition for the Church-Rosser property. -/ theorem church_rosser (h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d) (hab : ReflTransGen r a b) (hac : ReflTransGen r a c) : Join (ReflTransGen r) b c := by induction hab with | refl => exact ⟨c, hac, refl⟩ | @tail d e _ hde ih => rcases ih with ⟨b, hdb, hcb⟩ have : ∃ a, ReflTransGen r e a ∧ ReflGen r b a := by clear hcb induction hdb with | refl => exact ⟨e, refl, ReflGen.single hde⟩ | @tail f b _ hfb ih => rcases ih with ⟨a, hea, hfa⟩ cases hfa with | refl => exact ⟨b, hea.tail hfb, ReflGen.refl⟩ | single hfa => rcases h _ _ _ hfb hfa with ⟨c, hbc, hac⟩ exact ⟨c, hea.trans hac, hbc⟩ rcases this with ⟨a, hea, hba⟩ cases hba with | refl => exact ⟨b, hea, hcb⟩ | single hba => exact ⟨a, hea, hcb.tail hba⟩ theorem join_of_single (h : Reflexive r) (hab : r a b) : Join r a b := ⟨b, hab, h b⟩ theorem symmetric_join : Symmetric (Join r) := fun _ _ ⟨c, hac, hcb⟩ ↦ ⟨c, hcb, hac⟩ theorem reflexive_join (h : Reflexive r) : Reflexive (Join r) := fun a ↦ ⟨a, h a, h a⟩ theorem transitive_join (ht : Transitive r) (h : ∀ a b c, r a b → r a c → Join r b c) : Transitive (Join r) := fun _ b _ ⟨x, hax, hbx⟩ ⟨y, hby, hcy⟩ ↦ let ⟨z, hxz, hyz⟩ := h b x y hbx hby ⟨z, ht hax hxz, ht hcy hyz⟩ theorem equivalence_join (hr : Reflexive r) (ht : Transitive r) (h : ∀ a b c, r a b → r a c → Join r b c) : Equivalence (Join r) := ⟨reflexive_join hr, @symmetric_join _ _, @transitive_join _ _ ht h⟩ theorem equivalence_join_reflTransGen (h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d) : Equivalence (Join (ReflTransGen r)) := equivalence_join reflexive_reflTransGen transitive_reflTransGen fun _ _ _ ↦ church_rosser h theorem join_of_equivalence {r' : α → α → Prop} (hr : Equivalence r) (h : ∀ a b, r' a b → r a b) : Join r' a b → r a b | ⟨_, hac, hbc⟩ => hr.trans (h _ _ hac) (hr.symm <| h _ _ hbc) theorem reflTransGen_of_transitive_reflexive {r' : α → α → Prop} (hr : Reflexive r) (ht : Transitive r) (h : ∀ a b, r' a b → r a b) (h' : ReflTransGen r' a b) : r a b := by induction h' with | refl => exact hr _ | tail _ hbc ih => exact ht ih (h _ _ hbc) theorem reflTransGen_of_equivalence {r' : α → α → Prop} (hr : Equivalence r) : (∀ a b, r' a b → r a b) → ReflTransGen r' a b → r a b := reflTransGen_of_transitive_reflexive hr.1 (fun _ _ _ ↦ hr.trans) end Join end Relation section EqvGen open Relation variable {r : α → α → Prop} {a b : α} theorem Quot.eqvGen_exact (H : Quot.mk r a = Quot.mk r b) : EqvGen r a b := @Quotient.exact _ (EqvGen.setoid r) a b (congrArg (Quot.lift (Quotient.mk (EqvGen.setoid r)) (fun x y h ↦ Quot.sound (EqvGen.rel x y h))) H) theorem Quot.eqvGen_sound (H : EqvGen r a b) : Quot.mk r a = Quot.mk r b := EqvGen.rec (fun _ _ h ↦ Quot.sound h) (fun _ ↦ rfl) (fun _ _ _ IH ↦ Eq.symm IH) (fun _ _ _ _ _ IH₁ IH₂ ↦ Eq.trans IH₁ IH₂) H theorem Equivalence.eqvGen_iff (h : Equivalence r) : EqvGen r a b ↔ r a b := Iff.intro (by intro h induction h with | rel => assumption | refl => exact h.1 _ | symm => apply h.symm; assumption | trans _ _ _ _ _ hab hbc => exact h.trans hab hbc) (EqvGen.rel a b) theorem Equivalence.eqvGen_eq (h : Equivalence r) : EqvGen r = r := funext fun _ ↦ funext fun _ ↦ propext <| h.eqvGen_iff end EqvGen
mxpoly.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice seq. From mathcomp Require Import div fintype tuple finfun bigop fingroup perm. From mathcomp Require Import ssralg zmodp matrix mxalgebra poly polydiv. (******************************************************************************) (* This file provides basic support for formal computation with matrices, *) (* mainly results combining matrices and univariate polynomials, such as the *) (* Cayley-Hamilton theorem; it also contains an extension of the first order *) (* representation of algebra introduced in ssralg (GRing.term/formula). *) (* rVpoly v == the little-endian decoding of the row vector v as a *) (* polynomial p = \sum_i (v 0 i)%:P * 'X^i. *) (* poly_rV p == the partial inverse to rVpoly, for polynomials of degree *) (* less than d to 'rV_d (d is inferred from the context). *) (* Sylvester_mx p q == the Sylvester matrix of p and q. *) (* resultant p q == the resultant of p and q, i.e., \det (Sylvester_mx p q). *) (* horner_mx A == the morphism from {poly R} to 'M_n (n of the form n'.+1) *) (* mapping a (scalar) polynomial p to the value of its *) (* scalar matrix interpretation at A (this is an instance of *) (* the generic horner_morph construct defined in poly). *) (* powers_mx A d == the d x (n ^ 2) matrix whose rows are the mxvec encodings *) (* of the first d powers of A (n of the form n'.+1). Thus, *) (* vec_mx (v *m powers_mx A d) = horner_mx A (rVpoly v). *) (* char_poly A == the characteristic polynomial of A. *) (* char_poly_mx A == a matrix whose determinant is char_poly A. *) (* companionmx p == a matrix whose char_poly is p *) (* mxminpoly A == the minimal polynomial of A, i.e., the smallest monic *) (* polynomial that annihilates A (A must be nontrivial). *) (* degree_mxminpoly A == the (positive) degree of mxminpoly A. *) (* mx_inv_horner A == the inverse of horner_mx A for polynomials of degree *) (* smaller than degree_mxminpoly A. *) (* kermxpoly g p == the kernel of p(g) *) (* geigenspace g a == the generalized eigenspace of g for eigenvalue a *) (* := kermxpoly g ('X ^ n - a%:P) where g : 'M_n *) (* eigenpoly g p <=> p is an eigen polynomial for g, i.e. kermxpoly g p != 0 *) (* integralOver RtoK u <-> u is in the integral closure of the image of R *) (* under RtoK : R -> K, i.e. u is a root of the image of a *) (* monic polynomial in R. *) (* algebraicOver FtoE u <-> u : E is algebraic over E; it is a root of the *) (* image of a nonzero polynomial under FtoE; as F must be a *) (* fieldType, this is equivalent to integralOver FtoE u. *) (* integralRange RtoK <-> the integral closure of the image of R contains *) (* all of K (:= forall u, integralOver RtoK u). *) (* This toolkit for building formal matrix expressions is packaged in the *) (* MatrixFormula submodule, and comprises the following: *) (* eval_mx e == GRing.eval lifted to matrices (:= map_mx (GRing.eval e)). *) (* mx_term A == GRing.Const lifted to matrices. *) (* mulmx_term A B == the formal product of two matrices of terms. *) (* mxrank_form m A == a GRing.formula asserting that the interpretation of *) (* the term matrix A has rank m. *) (* submx_form A B == a GRing.formula asserting that the row space of the *) (* interpretation of the term matrix A is included in the *) (* row space of the interpretation of B. *) (* seq_of_rV v == the seq corresponding to a row vector. *) (* row_env e == the flattening of a tensored environment e : seq 'rV_d. *) (* row_var F d k == the term vector of width d such that for e : seq 'rV[F]_d *) (* we have eval e 'X_k = eval_mx (row_env e) (row_var d k). *) (* conjmx V f := V *m f *m pinvmx V *) (* == the conjugation of f by V, i.e. "the" matrix of f *) (* in the basis of row vectors of V. *) (* Although this makes sense only when f stabilizes V, *) (* the definition can be stated more generally. *) (* restrictmx V := conjmx (row_base V) *) (* A ~_P {in S'} == where P is a base change matrix, A is a matrix, and S *) (* is a boolean predicate representing a set of matrices, *) (* this states that conjmx P A is in S, *) (* which means A is similar to a matrix in S. *) (* From the latter, we derive several related notions: *) (* A ~_P B := A ~_P {in pred1 B} *) (* A is similar to B, with base change matrix P *) (* A ~_{in S} B := exists P, P \in S /\ A ~_P B *) (* == A is similar to B, with a base change matrix in S *) (* A ~_{in S} {in S'} := exists P, P \in S /\ A ~_P {in S'} *) (* == A is similar to a matrix in the class S', *) (* with a base change matrix in S *) (* all_simmx_in S As S' == all the matrices in the sequence As are *) (* similar to some matrix in the predicate S', *) (* with a base change matrix in S. *) (* *) (* We also specialize the class S' to diagonalizability: *) (* diagonalizable_for P A := A ~_P {in is_diag_mx}. *) (* diagonalizable_in S A := A ~_{in S} {in is_diag_mx}. *) (* diagonalizable A := diagonalizable_in unitmx A. *) (* codiagonalizable_in S As := all_simmx_in S As is_diag_mx. *) (* codiagonalizable As := codiagonalizable_in unitmx As. *) (* *) (* The main results in diagnonalization theory are: *) (* - diagonalizablePeigen: *) (* a matrix is diagonalizable iff there is a sequence *) (* of scalars r, such that the sum of the associated *) (* eigenspaces is full. *) (* - diagonalizableP: *) (* a matrix is diagonalizable iff its minimal polynomial *) (* divides a split polynomial with simple roots. *) (* - codiagonalizableP: *) (* a sequence of matrices are diagonalizable in the same basis *) (* iff they are all diagonalizable and commute pairwize. *) (* *) (* Naming conventions: *) (* - p, q are polynomials *) (* - A, B, C are matrices *) (* - f, g are matrices that are viewed as linear maps *) (* - V, W are matrices that are viewed as subspaces *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Monoid.Theory. Local Open Scope ring_scope. Import Pdiv.Idomain. (* Row vector <-> bounded degree polynomial bijection *) Section RowPoly. Variables (R : nzRingType) (d : nat). Implicit Types u v : 'rV[R]_d. Implicit Types p q : {poly R}. Definition rVpoly v := \poly_(k < d) (if insub k is Some i then v 0 i else 0). Definition poly_rV p := \row_(i < d) p`_i. Lemma coef_rVpoly v k : (rVpoly v)`_k = if insub k is Some i then v 0 i else 0. Proof. by rewrite coef_poly; case: insubP => [i ->|]; rewrite ?if_same. Qed. Lemma coef_rVpoly_ord v (i : 'I_d) : (rVpoly v)`_i = v 0 i. Proof. by rewrite coef_rVpoly valK. Qed. Lemma rVpoly_delta i : rVpoly (delta_mx 0 i) = 'X^i. Proof. apply/polyP=> j; rewrite coef_rVpoly coefXn. case: insubP => [k _ <- | j_ge_d]; first by rewrite mxE. by case: eqP j_ge_d => // ->; rewrite ltn_ord. Qed. Lemma rVpolyK : cancel rVpoly poly_rV. Proof. by move=> u; apply/rowP=> i; rewrite mxE coef_rVpoly_ord. Qed. Lemma poly_rV_K p : size p <= d -> rVpoly (poly_rV p) = p. Proof. move=> le_p_d; apply/polyP=> k; rewrite coef_rVpoly. case: insubP => [i _ <- | ]; first by rewrite mxE. by rewrite -ltnNge => le_d_l; rewrite nth_default ?(leq_trans le_p_d). Qed. Lemma poly_rV_is_linear : linear poly_rV. Proof. by move=> a p q; apply/rowP=> i; rewrite !mxE coefD coefZ. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} 'rV_d _ poly_rV (GRing.semilinear_linear poly_rV_is_linear). Lemma rVpoly_is_linear : linear rVpoly. Proof. move=> a u v; apply/polyP=> k; rewrite coefD coefZ !coef_rVpoly. by case: insubP => [i _ _ | _]; rewrite ?mxE // mulr0 addr0. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R 'rV_d {poly R} _ rVpoly (GRing.semilinear_linear rVpoly_is_linear). End RowPoly. Prenex Implicits rVpoly rVpolyK. Arguments poly_rV {R d}. Arguments poly_rV_K {R d} [p] le_p_d. Section Resultant. Variables (R : nzRingType) (p q : {poly R}). Let dS := ((size q).-1 + (size p).-1)%N. Local Notation band r := (lin1_mx (poly_rV \o r \o* rVpoly)). Definition Sylvester_mx : 'M[R]_dS := col_mx (band p) (band q). Lemma Sylvester_mxE (i j : 'I_dS) : let S_ r k := r`_(j - k) *+ (k <= j) in Sylvester_mx i j = match split i with inl k => S_ p k | inr k => S_ q k end. Proof. move=> S_ /[1!mxE]; case: {i}(split i) => i /[!mxE]/=; by rewrite rVpoly_delta coefXnM ltnNge if_neg -mulrb. Qed. Definition resultant := \det Sylvester_mx. End Resultant. Prenex Implicits Sylvester_mx resultant. Lemma resultant_in_ideal (R : comNzRingType) (p q : {poly R}) : size p > 1 -> size q > 1 -> {uv : {poly R} * {poly R} | size uv.1 < size q /\ size uv.2 < size p & (resultant p q)%:P = uv.1 * p + uv.2 * q}. Proof. move=> p_nc q_nc; pose dp := (size p).-1; pose dq := (size q).-1. pose S := Sylvester_mx p q; pose dS := (dq + dp)%N. have dS_gt0: dS > 0 by rewrite /dS /dq -(subnKC q_nc). pose j0 := Ordinal dS_gt0. pose Ss0 := col_mx (p *: \col_(i < dq) 'X^i) (q *: \col_(i < dp) 'X^i). pose Ss := \matrix_(i, j) (if j == j0 then Ss0 i 0 else (S i j)%:P). pose u ds s := \sum_(i < ds) cofactor Ss (s i) j0 * 'X^i. exists (u _ (lshift dp), u _ ((rshift dq) _)). suffices sz_u ds s: ds > 1 -> size (u ds.-1 s) < ds by rewrite !sz_u. move/ltn_predK=> {2}<-; apply: leq_trans (size_sum _ _ _) _. apply/bigmax_leqP=> i _. have ->: cofactor Ss (s i) j0 = (cofactor S (s i) j0)%:P. rewrite rmorphM /= rmorph_sign -det_map_mx; congr (_ * \det _). by apply/matrixP=> i' j'; rewrite !mxE. apply: leq_trans (size_polyMleq _ _) (leq_trans _ (valP i)). by rewrite size_polyC size_polyXn addnS /= -add1n leq_add2r leq_b1. transitivity (\det Ss); last first. rewrite (expand_det_col Ss j0) big_split_ord !big_distrl /=. by congr (_ + _); apply: eq_bigr => i _; rewrite mxE eqxx (col_mxEu, col_mxEd) !mxE mulrC mulrA mulrAC. pose S_ j1 := map_mx polyC (\matrix_(i, j) S i (if j == j0 then j1 else j)). pose Ss0_ i dj := \poly_(j < dj) S i (insubd j0 j). pose Ss_ dj := \matrix_(i, j) (if j == j0 then Ss0_ i dj else (S i j)%:P). have{Ss u} ->: Ss = Ss_ dS. apply/matrixP=> i j; rewrite mxE [in RHS]mxE; case: (j == j0) => {j}//. apply/polyP=> k; rewrite coef_poly Sylvester_mxE mxE. have [k_ge_dS | k_lt_dS] := leqP dS k. case: (split i) => {}i; rewrite !mxE coefMXn; case: ifP => // /negbT; rewrite -ltnNge ltnS => hi. apply: (leq_sizeP _ _ (leqnn (size p))); rewrite -(ltn_predK p_nc). by rewrite ltn_subRL (leq_trans _ k_ge_dS) // ltn_add2r. - apply: (leq_sizeP _ _ (leqnn (size q))); rewrite -(ltn_predK q_nc). by rewrite ltn_subRL (leq_trans _ k_ge_dS) // addnC ltn_add2l. by rewrite insubdK //; case: (split i) => {}i; rewrite !mxE coefMXn; case: leqP. case: (ubnPgeq dS) (dS_gt0); elim=> // dj IHj ltjS _; pose j1 := Ordinal ltjS. pose rj0T (A : 'M[{poly R}]_dS) := row j0 A^T. have: rj0T (Ss_ dj.+1) = 'X^dj *: rj0T (S_ j1) + 1 *: rj0T (Ss_ dj). apply/rowP=> i; apply/polyP=> k; rewrite scale1r !(Sylvester_mxE, mxE) eqxx. rewrite coefD coefXnM coefC !coef_poly ltnS subn_eq0 ltn_neqAle andbC. have [k_le_dj | k_gt_dj] /= := leqP k dj; last by rewrite addr0. rewrite Sylvester_mxE insubdK; last exact: leq_ltn_trans (ltjS). by have [->|] := eqP; rewrite (addr0, add0r). rewrite -det_tr => /determinant_multilinear->; try by apply/matrixP=> i j; rewrite !mxE lift_eqF. have [dj0 | dj_gt0] := posnP dj; rewrite ?dj0 !mul1r. rewrite !det_tr det_map_mx addrC (expand_det_col _ j0) big1 => [|i _]. rewrite add0r; congr (\det _)%:P. apply/matrixP=> i j; rewrite [in RHS]mxE; case: eqP => // ->. by congr (S i _); apply: val_inj. by rewrite mxE /= [Ss0_ _ _]poly_def big_ord0 mul0r. have /determinant_alternate->: j1 != j0 by rewrite -val_eqE -lt0n. by rewrite mulr0 add0r det_tr IHj // ltnW. by move=> i; rewrite !mxE if_same. Qed. Lemma resultant_eq0 (R : idomainType) (p q : {poly R}) : (resultant p q == 0) = (size (gcdp p q) > 1). Proof. have dvdpp := dvdpp; set r := gcdp p q. pose dp := (size p).-1; pose dq := (size q).-1. have /andP[r_p r_q]: (r %| p) && (r %| q) by rewrite -dvdp_gcd. apply/det0P/idP=> [[uv nz_uv] | r_nonC]. have [p0 _ | p_nz] := eqVneq p 0. have: dq + dp > 0. rewrite lt0n; apply: contraNneq nz_uv => dqp0. by rewrite dqp0 in uv *; rewrite [uv]thinmx0. by rewrite /dp /dq /r p0 size_poly0 addn0 gcd0p -subn1 subn_gt0. do [rewrite -[uv]hsubmxK -{1}row_mx0 mul_row_col !mul_rV_lin1 /=] in nz_uv *. set u := rVpoly _; set v := rVpoly _; pose m := gcdp (v * p) (v * q). have lt_vp: size v < size p by rewrite (polySpred p_nz) ltnS size_poly. move/(congr1 rVpoly)/eqP; rewrite -linearD linear0 poly_rV_K; last first. rewrite (leq_trans (size_polyD _ _)) // geq_max. rewrite !(leq_trans (size_polyMleq _ _)) // -subn1 leq_subLR. by rewrite addnC addnA leq_add ?leqSpred ?size_poly. by rewrite addnCA leq_add ?leqSpred ?size_poly. rewrite addrC addr_eq0 => /eqP vq_up. have nz_v: v != 0. apply: contraNneq nz_uv => v0; apply/eqP. congr row_mx; apply: (can_inj rVpolyK); rewrite linear0 // -/u. by apply: contra_eq vq_up; rewrite v0 mul0r -addr_eq0 add0r => /mulf_neq0->. have r_nz: r != 0 := dvdpN0 r_p p_nz. have /dvdpP [[c w] /= nz_c wv]: v %| m by rewrite dvdp_gcd !dvdp_mulr. have m_wd d: m %| v * d -> w %| d. case/dvdpP=> [[k f]] /= nz_k /(congr1 ( *:%R c)). rewrite mulrC scalerA scalerAl scalerAr wv mulrA => /(mulIf nz_v)def_fw. by apply/dvdpP; exists (c * k, f); rewrite //= mulf_neq0. have w_r: w %| r by rewrite dvdp_gcd !m_wd ?dvdp_gcdl ?dvdp_gcdr. have w_nz: w != 0 := dvdpN0 w_r r_nz. have p_m: p %| m by rewrite dvdp_gcd vq_up -mulNr !dvdp_mull. rewrite (leq_trans _ (dvdp_leq r_nz w_r)) // -(ltn_add2l (size v)). rewrite addnC -ltn_subRL subn1 -size_mul // mulrC -wv size_scale //. rewrite (leq_trans lt_vp) // dvdp_leq // -size_poly_eq0. by rewrite -(size_scale _ nz_c) size_poly_eq0 wv mulf_neq0. have [[c p'] /= nz_c p'r] := dvdpP _ _ r_p. have [[k q'] /= nz_k q'r] := dvdpP _ _ r_q. have def_r := subnKC r_nonC; have r_nz: r != 0 by rewrite -size_poly_eq0 -def_r. have le_p'_dp: size p' <= dp. have [-> | nz_p'] := eqVneq p' 0; first by rewrite size_poly0. by rewrite /dp -(size_scale p nz_c) p'r size_mul // addnC -def_r leq_addl. have le_q'_dq: size q' <= dq. have [-> | nz_q'] := eqVneq q' 0; first by rewrite size_poly0. by rewrite /dq -(size_scale q nz_k) q'r size_mul // addnC -def_r leq_addl. exists (row_mx (- c *: poly_rV q') (k *: poly_rV p')); last first. rewrite mul_row_col scaleNr mulNmx !mul_rV_lin1 /= 2!linearZ /= !poly_rV_K //. by rewrite !scalerCA p'r q'r mulrCA addNr. apply: contraNneq r_nz; rewrite -row_mx0 => /eq_row_mx[/eqP]. rewrite scaleNr oppr_eq0 gcdp_eq0 -!size_poly_eq0 => /eqP q0 p0. rewrite -(size_scale p nz_c) -(size_scale (c *: p) nz_k) p'r. rewrite -(size_scale q nz_k) -(size_scale (k *: q) nz_c) q'r !scalerAl. rewrite -(poly_rV_K le_p'_dp) -(poly_rV_K le_q'_dq). by rewrite -2![_ *: rVpoly _]linearZ p0 q0 !linear0 mul0r size_poly0. Qed. Section HornerMx. Variables (R : comNzRingType) (n' : nat). Local Notation n := n'.+1. Implicit Types (A B : 'M[R]_n) (p q : {poly R}). Section OneMatrix. Variable A : 'M[R]_n. Definition horner_mx := horner_morph (comm_mx_scalar^~ A). HB.instance Definition _ := GRing.RMorphism.on horner_mx. Lemma horner_mx_C a : horner_mx a%:P = a%:M. Proof. exact: horner_morphC. Qed. Lemma horner_mx_X : horner_mx 'X = A. Proof. exact: horner_morphX. Qed. Lemma horner_mxZ : scalable horner_mx. Proof. move=> a p /=; rewrite -mul_polyC rmorphM /=. by rewrite horner_mx_C [_ * _]mul_scalar_mx. Qed. HB.instance Definition _ := GRing.isScalable.Build R _ _ *:%R horner_mx horner_mxZ. Definition powers_mx d := \matrix_(i < d) mxvec (A ^+ i). Lemma horner_rVpoly m (u : 'rV_m) : horner_mx (rVpoly u) = vec_mx (u *m powers_mx m). Proof. rewrite mulmx_sum_row [rVpoly u]poly_def 2!linear_sum; apply: eq_bigr => i _. by rewrite valK /= 2!linearZ rmorphXn/= horner_mx_X rowK mxvecK. Qed. End OneMatrix. Lemma horner_mx_diag (d : 'rV[R]_n) (p : {poly R}) : horner_mx (diag_mx d) p = diag_mx (map_mx (horner p) d). Proof. apply/matrixP => i j; rewrite !mxE. elim/poly_ind: p => [|p c ihp]; first by rewrite rmorph0 horner0 mxE mul0rn. rewrite !hornerE mulrnDl rmorphD rmorphM /= horner_mx_X horner_mx_C !mxE. rewrite (bigD1 j)//= ihp mxE eqxx mulr1n -mulrnAl big1 ?addr0. by have [->|_] := eqVneq; rewrite /= !(mulr1n, addr0, mul0r). by move=> k /negPf nkF; rewrite mxE nkF mulr0. Qed. Lemma comm_mx_horner A B p : comm_mx A B -> comm_mx A (horner_mx B p). Proof. move=> fg; apply: commr_horner => // i. by rewrite coef_map; apply/comm_scalar_mx. Qed. Lemma comm_horner_mx A B p : comm_mx A B -> comm_mx (horner_mx A p) B. Proof. by move=> ?; apply/comm_mx_sym/comm_mx_horner/comm_mx_sym. Qed. Lemma comm_horner_mx2 A p q : GRing.comm (horner_mx A p) (horner_mx A q). Proof. exact/comm_mx_horner/comm_horner_mx. Qed. End HornerMx. Lemma horner_mx_stable (K : fieldType) m n p (V : 'M[K]_(n.+1, m.+1)) (f : 'M_m.+1) : stablemx V f -> stablemx V (horner_mx f p). Proof. move=> V_fstab; elim/poly_ind: p => [|p c]; first by rewrite rmorph0 stablemx0. move=> fp_stable; rewrite rmorphD rmorphM/= horner_mx_X horner_mx_C. by rewrite stablemxD ?stablemxM ?fp_stable ?stablemxC. Qed. Prenex Implicits horner_mx powers_mx. Section CharPoly. Variables (R : nzRingType) (n : nat) (A : 'M[R]_n). Implicit Types p q : {poly R}. Definition char_poly_mx := 'X%:M - map_mx (@polyC R) A. Definition char_poly := \det char_poly_mx. Let diagA := [seq A i i | i <- index_enum _ & true]. Let size_diagA : size diagA = n. Proof. by rewrite -[n]card_ord size_map; have [e _ _ []] := big_enumP. Qed. Let split_diagA : exists2 q, \prod_(x <- diagA) ('X - x%:P) + q = char_poly & size q <= n.-1. Proof. rewrite [char_poly](bigD1 1%g) //=; set q := \sum_(s | _) _; exists q. congr (_ + _); rewrite odd_perm1 mul1r big_map big_filter /=. by apply: eq_bigr => i _; rewrite !mxE perm1 eqxx. apply: leq_trans {q}(size_sum _ _ _) _; apply/bigmax_leqP=> s nt_s. have{nt_s} [i nfix_i]: exists i, s i != i. apply/existsP; rewrite -negb_forall; apply: contra nt_s => s_1. by apply/eqP/permP=> i; apply/eqP; rewrite perm1 (forallP s_1). apply: leq_trans (_ : #|[pred j | s j == j]|.+1 <= n.-1). rewrite -sum1_card (@big_mkcond nat) /= size_Msign. apply: (big_ind2 (fun p m => size p <= m.+1)) => [| p mp q mq IHp IHq | j _]. - by rewrite size_poly1. - apply: leq_trans (size_polyMleq _ _) _. by rewrite -subn1 -addnS leq_subLR addnA leq_add. rewrite !mxE eq_sym !inE; case: (s j == j); first by rewrite polyseqXsubC. by rewrite sub0r size_polyN size_polyC leq_b1. rewrite -[n in n.-1]card_ord -(cardC (pred2 (s i) i)) card2 nfix_i !ltnS. apply/subset_leq_card/subsetP=> j /(_ =P j) fix_j. rewrite !inE -{1}fix_j (inj_eq perm_inj) orbb. by apply: contraNneq nfix_i => <-; rewrite fix_j. Qed. Lemma size_char_poly : size char_poly = n.+1. Proof. have [q <- lt_q_n] := split_diagA; have le_q_n := leq_trans lt_q_n (leq_pred n). by rewrite size_polyDl size_prod_XsubC size_diagA. Qed. Lemma char_poly_monic : char_poly \is monic. Proof. rewrite monicE -(monicP (monic_prod_XsubC diagA xpredT id)). rewrite !lead_coefE size_char_poly. have [q <- lt_q_n] := split_diagA; have le_q_n := leq_trans lt_q_n (leq_pred n). by rewrite size_prod_XsubC size_diagA coefD (nth_default 0 le_q_n) addr0. Qed. Lemma char_poly_trace : n > 0 -> char_poly`_n.-1 = - \tr A. Proof. move=> n_gt0; have [q <- lt_q_n] := split_diagA; set p := \prod_(x <- _) _. rewrite coefD {q lt_q_n}(nth_default 0 lt_q_n) addr0. have{n_gt0} ->: p`_n.-1 = ('X * p)`_n by rewrite coefXM eqn0Ngt n_gt0. have ->: \tr A = \sum_(x <- diagA) x by rewrite big_map big_filter. rewrite -size_diagA {}/p; elim: diagA => [|x d IHd]. by rewrite !big_nil mulr1 coefX oppr0. rewrite !big_cons coefXM mulrBl coefB IHd opprD addrC; congr (- _ + _). rewrite mul_polyC coefZ [size _]/= -(size_prod_XsubC _ id) -lead_coefE. by rewrite (monicP _) ?monic_prod_XsubC ?mulr1. Qed. Lemma char_poly_det : char_poly`_0 = (- 1) ^+ n * \det A. Proof. rewrite big_distrr coef_sum [0%N]lock /=; apply: eq_bigr => s _. rewrite -{1}rmorphN -rmorphXn mul_polyC coefZ /=. rewrite mulrA -exprD addnC exprD -mulrA -lock; congr (_ * _). transitivity (\prod_(i < n) - A i (s i)); last by rewrite prodrN card_ord. elim: (index_enum _) => [|i e IHe]; rewrite !(big_nil, big_cons) ?coef1 //. by rewrite coefM big_ord1 IHe !mxE coefB coefC coefMn coefX mul0rn sub0r. Qed. End CharPoly. Prenex Implicits char_poly_mx char_poly. Lemma mx_poly_ring_isom (R : nzRingType) n' (n := n'.+1) : exists phi : {rmorphism 'M[{poly R}]_n -> {poly 'M[R]_n}}, [/\ bijective phi, forall p, phi p%:M = map_poly scalar_mx p, forall A, phi (map_mx polyC A) = A%:P & forall A i j k, (phi A)`_k i j = (A i j)`_k]. Proof. set M_RX := 'M[{poly R}]_n; set MR_X := ({poly 'M[R]_n}). pose Msize (A : M_RX) := \max_i \max_j size (A i j). pose phi (A : M_RX) := \poly_(k < Msize A) \matrix_(i, j) (A i j)`_k. have coef_phi A i j k: (phi A)`_k i j = (A i j)`_k. rewrite coef_poly; case: (ltnP k _) => le_m_k; rewrite mxE // nth_default //. by apply: leq_trans (leq_trans (leq_bigmax i) le_m_k); apply: (leq_bigmax j). have phi_is_zmod_morphism : zmod_morphism phi. move=> A B; apply/polyP => k; apply/matrixP => i j. by rewrite !(coef_phi, mxE, coefD, coefN). have phi_is_monoid_morphism : monoid_morphism phi. split=> [|A B]; apply/polyP => k; apply/matrixP => i j. by rewrite coef_phi mxE coefMn !coefC; case: (k == _); rewrite ?mxE ?mul0rn. rewrite !coef_phi !mxE !coefM summxE coef_sum. pose F k1 k2 := (A i k1)`_k2 * (B k1 j)`_(k - k2). transitivity (\sum_k1 \sum_(k2 < k.+1) F k1 k2); rewrite {}/F. by apply: eq_bigr=> k1 _; rewrite coefM. rewrite exchange_big /=; apply: eq_bigr => k2 _. by rewrite mxE; apply: eq_bigr => k1 _; rewrite !coef_phi. have bij_phi: bijective phi. exists (fun P : MR_X => \matrix_(i, j) \poly_(k < size P) P`_k i j) => [A|P]. apply/matrixP=> i j; rewrite mxE; apply/polyP=> k. rewrite coef_poly -coef_phi. by case: leqP => // P_le_k; rewrite nth_default ?mxE. apply/polyP=> k; apply/matrixP=> i j; rewrite coef_phi mxE coef_poly. by case: leqP => // P_le_k; rewrite nth_default ?mxE. pose phiaM := GRing.isZmodMorphism.Build _ _ phi phi_is_zmod_morphism. pose phimM := GRing.isMonoidMorphism.Build _ _ phi phi_is_monoid_morphism. pose phiRM : {rmorphism _ -> _} := HB.pack phi phiaM phimM. exists phiRM; split=> // [p | A]; apply/polyP=> k; apply/matrixP=> i j. by rewrite coef_phi coef_map !mxE coefMn. by rewrite coef_phi !mxE !coefC; case k; last rewrite /= mxE. Qed. Theorem Cayley_Hamilton (R : comNzRingType) n' (A : 'M[R]_n'.+1) : horner_mx A (char_poly A) = 0. Proof. have [phi [_ phiZ phiC _]] := mx_poly_ring_isom R n'. apply/rootP/factor_theorem; rewrite -phiZ -mul_adj_mx rmorphM /=. by move: (phi _) => q; exists q; rewrite rmorphB phiC phiZ map_polyX. Qed. Lemma eigenvalue_root_char (F : fieldType) n (A : 'M[F]_n) a : eigenvalue A a = root (char_poly A) a. Proof. transitivity (\det (a%:M - A) == 0). apply/eigenvalueP/det0P=> [[v Av_av v_nz] | [v v_nz Av_av]]; exists v => //. by rewrite mulmxBr Av_av mul_mx_scalar subrr. by apply/eqP; rewrite -mul_mx_scalar eq_sym -subr_eq0 -mulmxBr Av_av. congr (_ == 0); rewrite horner_sum; apply: eq_bigr => s _. rewrite hornerM horner_exp !hornerE; congr (_ * _). rewrite (big_morph _ (fun p q => hornerM p q a) (hornerC 1 a)). by apply: eq_bigr => i _; rewrite !mxE !(hornerE, hornerMn). Qed. Lemma char_poly_trig {R : comNzRingType} n (A : 'M[R]_n) : is_trig_mx A -> char_poly A = \prod_(i < n) ('X - (A i i)%:P). Proof. move=> /is_trig_mxP Atrig; rewrite /char_poly det_trig. by apply: eq_bigr => i; rewrite !mxE eqxx. by apply/is_trig_mxP => i j lt_ij; rewrite !mxE -val_eqE ltn_eqF ?Atrig ?subrr. Qed. Definition companionmx {R : nzRingType} (p : seq R) (d := (size p).-1) := \matrix_(i < d, j < d) if (i == d.-1 :> nat) then - p`_j else (i.+1 == j :> nat)%:R. Lemma companionmxK {R : comNzRingType} (p : {poly R}) : p \is monic -> char_poly (companionmx p) = p. Proof. pose D n : 'M[{poly R}]_n := \matrix_(i, j) ('X *+ (i == j.+1 :> nat) - ((i == j)%:R)%:P). have detD n : \det (D n) = (-1) ^+ n. elim: n => [|n IHn]; first by rewrite det_mx00. rewrite (expand_det_row _ ord0) big_ord_recl !mxE /= sub0r. rewrite big1 ?addr0; last by move=> i _; rewrite !mxE /= subrr mul0r. rewrite /cofactor mul1r [X in \det X](_ : _ = D _) ?IHn ?exprS//. by apply/matrixP=> i j; rewrite !mxE /= /bump !add1n eqSS. elim/poly_ind: p => [|p c IHp]. by rewrite monicE lead_coef0 eq_sym oner_eq0. have [->|p_neq0] := eqVneq p 0. rewrite mul0r add0r monicE lead_coefC => /eqP->. by rewrite /companionmx /char_poly size_poly1 det_mx00. rewrite monicE lead_coefDl ?lead_coefMX => [p_monic|]; last first. rewrite size_polyC size_mulX ?polyX_eq0// ltnS. by rewrite (leq_trans (leq_b1 _)) ?size_poly_gt0. rewrite -[in RHS]IHp // /companionmx size_MXaddC (negPf p_neq0) /=. rewrite /char_poly polySpred //. have [->|spV1_gt0] := posnP (size p).-1. rewrite [X in \det X]mx11_scalar det_scalar1 !mxE ?eqxx det_mx00. by rewrite mul1r -horner_coef0 hornerMXaddC mulr0 add0r rmorphN opprK. rewrite (expand_det_col _ ord0) /= -[(size p).-1]prednK //. rewrite big_ord_recr big_ord_recl/= big1 ?add0r //=; last first. move=> i _; rewrite !mxE -val_eqE /= /bump leq0n add1n eqSS. by rewrite ltn_eqF ?subrr ?mul0r. rewrite !mxE ?subnn -horner_coef0 /= hornerMXaddC. rewrite !(eqxx, mulr0, add0r, addr0, subr0, rmorphN, opprK)/=. rewrite mulrC /cofactor; congr (_ * 'X + _). rewrite /cofactor -signr_odd oddD addbb mul1r; congr (\det _). apply/matrixP => i j; rewrite !mxE -val_eqE coefD coefMX coefC. by rewrite /= /bump /= !add1n !eqSS addr0. rewrite /cofactor [X in \det X](_ : _ = D _). by rewrite detD /= addn0 -signr_odd -signr_addb addbb mulr1. apply/matrixP=> i j; rewrite !mxE -!val_eqE /= /bump /=. by rewrite leqNgt ltn_ord add0n add1n [_ == _.-2.+1]ltn_eqF. Qed. Lemma mulmx_delta_companion (R : nzRingType) (p : seq R) (i: 'I_(size p).-1) (i_small : i.+1 < (size p).-1): delta_mx 0 i *m companionmx p = delta_mx 0 (Ordinal i_small) :> 'rV__. Proof. apply/rowP => j; rewrite !mxE (bigD1 i) //= ?(=^~val_eqE, mxE) /= eqxx mul1r. rewrite ltn_eqF ?big1 ?addr0 1?eq_sym //; last first. by rewrite -ltnS prednK // (leq_trans _ i_small). by move=> k /negPf ki_eqF; rewrite !mxE eqxx ki_eqF mul0r. Qed. Lemma row'_col'_char_poly_mx {R : nzRingType} m i (M : 'M[R]_m) : row' i (col' i (char_poly_mx M)) = char_poly_mx (row' i (col' i M)). Proof. by apply/matrixP => k l; rewrite !mxE (inj_eq lift_inj). Qed. Lemma char_block_diag_mx {R : nzRingType} m n (A : 'M[R]_m) (B : 'M[R]_n) : char_poly_mx (block_mx A 0 0 B) = block_mx (char_poly_mx A) 0 0 (char_poly_mx B). Proof. rewrite /char_poly_mx map_block_mx/= !map_mx0. by rewrite scalar_mx_block opp_block_mx add_block_mx !subr0. Qed. Section MinPoly. Variables (F : fieldType) (n' : nat). Local Notation n := n'.+1. Variable A : 'M[F]_n. Implicit Types p q : {poly F}. Fact degree_mxminpoly_proof : exists d, \rank (powers_mx A d.+1) <= d. Proof. by exists (n ^ 2)%N; rewrite rank_leq_col. Qed. Definition degree_mxminpoly := ex_minn degree_mxminpoly_proof. Local Notation d := degree_mxminpoly. Local Notation Ad := (powers_mx A d). Lemma mxminpoly_nonconstant : d > 0. Proof. rewrite /d; case: ex_minnP => -[] //; rewrite leqn0 mxrank_eq0; move/eqP. by move/row_matrixP/(_ 0)/eqP; rewrite rowK row0 mxvec_eq0 -mxrank_eq0 mxrank1. Qed. Lemma minpoly_mx1 : (1%:M \in Ad)%MS. Proof. by apply: (eq_row_sub (Ordinal mxminpoly_nonconstant)); rewrite rowK. Qed. Lemma minpoly_mx_free : row_free Ad. Proof. have:= mxminpoly_nonconstant; rewrite /d; case: ex_minnP => -[] // d' _ /(_ d'). by move/implyP; rewrite ltnn implybF -ltnS ltn_neqAle rank_leq_row andbT negbK. Qed. Lemma horner_mx_mem p : (horner_mx A p \in Ad)%MS. Proof. elim/poly_ind: p => [|p a IHp]; first by rewrite rmorph0 // linear0 sub0mx. rewrite rmorphD rmorphM /= horner_mx_C horner_mx_X. rewrite addrC -scalemx1 linearP /= -(mul_vec_lin (mulmxr A)). case/submxP: IHp => u ->{p}. have: (powers_mx A (1 + d) <= Ad)%MS. rewrite -(geq_leqif (mxrank_leqif_sup _)). by rewrite (eqnP minpoly_mx_free) /d; case: ex_minnP. rewrite addnC; apply/row_subP=> i. by apply: eq_row_sub (lshift 1 i) _; rewrite !rowK. apply: submx_trans; rewrite addmx_sub ?scalemx_sub //. by apply: (eq_row_sub 0); rewrite rowK. rewrite -mulmxA mulmx_sub {u}//; apply/row_subP=> i. rewrite row_mul rowK mul_vec_lin /= mulmxE -exprSr. by apply: (eq_row_sub (rshift 1 i)); rewrite rowK. Qed. Definition mx_inv_horner B := rVpoly (mxvec B *m pinvmx Ad). Lemma mx_inv_horner0 : mx_inv_horner 0 = 0. Proof. by rewrite /mx_inv_horner !(linear0, mul0mx). Qed. Lemma mx_inv_hornerK B : (B \in Ad)%MS -> horner_mx A (mx_inv_horner B) = B. Proof. by move=> sBAd; rewrite horner_rVpoly mulmxKpV ?mxvecK. Qed. Lemma minpoly_mxM B C : (B \in Ad -> C \in Ad -> B * C \in Ad)%MS. Proof. move=> AdB AdC; rewrite -(mx_inv_hornerK AdB) -(mx_inv_hornerK AdC). by rewrite -rmorphM ?horner_mx_mem. Qed. Lemma minpoly_mx_ring : mxring Ad. Proof. apply/andP; split; first exact/mulsmx_subP/minpoly_mxM. apply/mxring_idP; exists 1%:M; split=> *; rewrite ?mulmx1 ?mul1mx //. by rewrite -mxrank_eq0 mxrank1. exact: minpoly_mx1. Qed. Definition mxminpoly := 'X^d - mx_inv_horner (A ^+ d). Local Notation p_A := mxminpoly. Lemma size_mxminpoly : size p_A = d.+1. Proof. by rewrite size_polyDl ?size_polyXn // size_polyN ltnS size_poly. Qed. Lemma mxminpoly_monic : p_A \is monic. Proof. rewrite monicE /lead_coef size_mxminpoly coefB coefXn eqxx /=. by rewrite nth_default ?size_poly // subr0. Qed. Lemma size_mod_mxminpoly p : size (p %% p_A) <= d. Proof. by rewrite -ltnS -size_mxminpoly ltn_modp // -size_poly_eq0 size_mxminpoly. Qed. Lemma mx_root_minpoly : horner_mx A p_A = 0. Proof. rewrite rmorphB -{3}(horner_mx_X A) -rmorphXn /=. by rewrite mx_inv_hornerK ?subrr ?horner_mx_mem. Qed. Lemma horner_rVpolyK (u : 'rV_d) : mx_inv_horner (horner_mx A (rVpoly u)) = rVpoly u. Proof. congr rVpoly; rewrite horner_rVpoly vec_mxK. by apply: (row_free_inj minpoly_mx_free); rewrite mulmxKpV ?submxMl. Qed. Lemma horner_mxK p : mx_inv_horner (horner_mx A p) = p %% p_A. Proof. rewrite {1}(Pdiv.IdomainMonic.divp_eq mxminpoly_monic p) rmorphD rmorphM /=. rewrite mx_root_minpoly mulr0 add0r. by rewrite -(poly_rV_K (size_mod_mxminpoly _)) horner_rVpolyK. Qed. Lemma mxminpoly_min p : horner_mx A p = 0 -> p_A %| p. Proof. by move=> pA0; rewrite /dvdp -horner_mxK pA0 mx_inv_horner0. Qed. Lemma mxminpoly_minP p : reflect (horner_mx A p = 0) (p_A %| p). Proof. apply: (iffP idP); last exact: mxminpoly_min. by move=> /Pdiv.Field.dvdpP[q ->]; rewrite rmorphM/= mx_root_minpoly mulr0. Qed. Lemma dvd_mxminpoly p : (p_A %| p) = (horner_mx A p == 0). Proof. exact/mxminpoly_minP/eqP. Qed. Lemma horner_rVpoly_inj : injective (horner_mx A \o rVpoly : 'rV_d -> 'M_n). Proof. apply: can_inj (poly_rV \o mx_inv_horner) _ => u /=. by rewrite horner_rVpolyK rVpolyK. Qed. Lemma mxminpoly_linear_is_scalar : (d <= 1) = is_scalar_mx A. Proof. have scalP := has_non_scalar_mxP minpoly_mx1. rewrite leqNgt -(eqnP minpoly_mx_free); apply/scalP/idP=> [|[[B]]]. case scalA: (is_scalar_mx A); [by right | left]. by exists A; rewrite ?scalA // -{1}(horner_mx_X A) horner_mx_mem. move/mx_inv_hornerK=> <- nsB; case/is_scalar_mxP=> a defA; case/negP: nsB. move: {B}(_ B); apply: poly_ind => [|p c]. by rewrite rmorph0 ?mx0_is_scalar. rewrite rmorphD ?rmorphM /= horner_mx_X defA; case/is_scalar_mxP=> b ->. by rewrite -rmorphM horner_mx_C -rmorphD /= scalar_mx_is_scalar. Qed. Lemma mxminpoly_dvd_char : p_A %| char_poly A. Proof. exact/mxminpoly_min/Cayley_Hamilton. Qed. Lemma eigenvalue_root_min a : eigenvalue A a = root p_A a. Proof. apply/idP/idP=> Aa; last first. rewrite eigenvalue_root_char !root_factor_theorem in Aa *. exact: dvdp_trans Aa mxminpoly_dvd_char. have{Aa} [v Av_av v_nz] := eigenvalueP Aa. apply: contraR v_nz => pa_nz; rewrite -{pa_nz}(eqmx_eq0 (eqmx_scale _ pa_nz)). apply/eqP; rewrite -(mulmx0 _ v) -mx_root_minpoly. elim/poly_ind: p_A => [|p c IHp]. by rewrite rmorph0 horner0 scale0r mulmx0. rewrite !hornerE rmorphD rmorphM /= horner_mx_X horner_mx_C scalerDl. by rewrite -scalerA mulmxDr mul_mx_scalar mulmxA -IHp -scalemxAl Av_av. Qed. Lemma root_mxminpoly a : root p_A a = root (char_poly A) a. Proof. by rewrite -eigenvalue_root_min eigenvalue_root_char. Qed. End MinPoly. Lemma mxminpoly_diag {F : fieldType} {n} (d : 'rV[F]_n.+1) (u := undup [seq d 0 i | i <- enum 'I_n.+1]) : mxminpoly (diag_mx d) = \prod_(r <- u) ('X - r%:P). Proof. apply/eqP; rewrite -eqp_monic ?mxminpoly_monic ?monic_prod_XsubC// /eqp. rewrite mxminpoly_min/=; last first. rewrite horner_mx_diag; apply/matrixP => i j; rewrite !mxE horner_prod. case: (altP (i =P j)) => [->|neq_ij//]; rewrite mulr1n. rewrite (bigD1_seq (d 0 j)) ?undup_uniq ?mem_undup ?map_f// /=. by rewrite hornerD hornerN hornerX hornerC subrr mul0r. apply: uniq_roots_dvdp; last by rewrite uniq_rootsE undup_uniq. apply/allP => x; rewrite mem_undup root_mxminpoly char_poly_trig//. rewrite -(big_map _ predT (fun x => _ - x%:P)) root_prod_XsubC. by move=> /mapP[i _ ->]; apply/mapP; exists i; rewrite ?(mxE, eqxx). Qed. Prenex Implicits degree_mxminpoly mxminpoly mx_inv_horner. Arguments mx_inv_hornerK {F n' A} [B] AnB. Arguments horner_rVpoly_inj {F n' A} [u1 u2] eq_u12A : rename. (* Parametricity. *) Section MapRingMatrix. Variables (aR rR : nzRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx (GRing.RMorphism.sort f) A) : ring_scope. Local Notation fp := (map_poly (GRing.RMorphism.sort f)). Variables (d n : nat) (A : 'M[aR]_n). Lemma map_rVpoly (u : 'rV_d) : fp (rVpoly u) = rVpoly u^f. Proof. apply/polyP=> k; rewrite coef_map !coef_rVpoly. by case: (insub k) => [i|]; rewrite /= ?rmorph0 // mxE. Qed. Lemma map_poly_rV p : (poly_rV p)^f = poly_rV (fp p) :> 'rV_d. Proof. by apply/rowP=> j; rewrite !mxE coef_map. Qed. Lemma map_char_poly_mx : map_mx fp (char_poly_mx A) = char_poly_mx A^f. Proof. rewrite raddfB /= map_scalar_mx /= map_polyX; congr (_ - _). by apply/matrixP=> i j; rewrite !mxE map_polyC. Qed. Lemma map_char_poly : fp (char_poly A) = char_poly A^f. Proof. by rewrite -det_map_mx map_char_poly_mx. Qed. End MapRingMatrix. Section MapResultant. Lemma map_resultant (aR rR : nzRingType) (f : {rmorphism {poly aR} -> rR}) p q : f (lead_coef p) != 0 -> f (lead_coef q) != 0 -> f (resultant p q)= resultant (map_poly f p) (map_poly f q). Proof. move=> nz_fp nz_fq; rewrite /resultant /Sylvester_mx !size_map_poly_id0 //. rewrite -det_map_mx /= map_col_mx; congr (\det (col_mx _ _)); by apply: map_lin1_mx => v; rewrite map_poly_rV rmorphM /= map_rVpoly. Qed. End MapResultant. Section MapComRing. Variables (aR rR : comNzRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Local Notation fp := (map_poly f). Variables (n' : nat) (A : 'M[aR]_n'.+1). Lemma map_powers_mx e : (powers_mx A e)^f = powers_mx A^f e. Proof. by apply/row_matrixP=> i; rewrite -map_row !rowK map_mxvec rmorphXn. Qed. Lemma map_horner_mx p : (horner_mx A p)^f = horner_mx A^f (fp p). Proof. rewrite -[p](poly_rV_K (leqnn _)) map_rVpoly. by rewrite !horner_rVpoly map_vec_mx map_mxM map_powers_mx. Qed. End MapComRing. Section MapField. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Local Notation fp := (map_poly f). Variables (n' : nat) (A : 'M[aF]_n'.+1) (p : {poly aF}). Lemma map_mx_companion (e := congr1 predn (size_map_poly _ _)) : (companionmx p)^f = castmx (e, e) (companionmx (fp p)). Proof. apply/matrixP => i j; rewrite !(castmxE, mxE) /= (fun_if f). by rewrite rmorphN coef_map size_map_poly rmorph_nat. Qed. Lemma companion_map_poly (e := esym (congr1 predn (size_map_poly _ _))) : companionmx (fp p) = castmx (e, e) (companionmx p)^f. Proof. by rewrite map_mx_companion castmx_comp castmx_id. Qed. Lemma degree_mxminpoly_map : degree_mxminpoly A^f = degree_mxminpoly A. Proof. by apply: eq_ex_minn => e; rewrite -map_powers_mx mxrank_map. Qed. Lemma mxminpoly_map : mxminpoly A^f = fp (mxminpoly A). Proof. rewrite rmorphB; congr (_ - _). by rewrite /= map_polyXn degree_mxminpoly_map. rewrite degree_mxminpoly_map -rmorphXn /=. apply/polyP=> i; rewrite coef_map //= !coef_rVpoly degree_mxminpoly_map. case/insub: i => [i|]; last by rewrite rmorph0. by rewrite -map_powers_mx -map_pinvmx // -map_mxvec -map_mxM // mxE. Qed. Lemma map_mx_inv_horner u : fp (mx_inv_horner A u) = mx_inv_horner A^f u^f. Proof. rewrite map_rVpoly map_mxM map_mxvec map_pinvmx map_powers_mx. by rewrite /mx_inv_horner degree_mxminpoly_map. Qed. End MapField. Section KernelLemmas. Variable K : fieldType. (* convertible to kermx (horner_mx g p) when n = n.+1 *) Definition kermxpoly n (g : 'M_n) (p : {poly K}) : 'M_n := kermx ((if n is n.+1 then horner_mx^~ p : 'M_n.+1 -> 'M_n.+1 else \0) g). Lemma kermxpolyC n (g : 'M_n) c : c != 0 -> kermxpoly g c%:P = 0. Proof. move=> c_neq0; case: n => [|n] in g *; first by rewrite thinmx0. apply/eqP; rewrite /kermxpoly horner_mx_C kermx_eq0 row_free_unit. by rewrite -scalemx1 scaler_unit ?unitmx1// unitfE. Qed. Lemma kermxpoly1 n (g : 'M_n) : kermxpoly g 1 = 0. Proof. by rewrite kermxpolyC ?oner_eq0. Qed. Lemma kermxpolyX n (g : 'M_n) : kermxpoly g 'X = kermx g. Proof. case: n => [|n] in g *; first by rewrite !thinmx0. by rewrite /kermxpoly horner_mx_X. Qed. Lemma kermxpoly_min n (g : 'M[K]_n.+1) p : mxminpoly g %| p -> (kermxpoly g p :=: 1)%MS. Proof. by rewrite /kermxpoly => /mxminpoly_minP ->; apply: kermx0. Qed. Lemma comm_mx_stable_kermxpoly n (f g : 'M_n) (p : {poly K}) : comm_mx f g -> stablemx (kermxpoly f p) g. Proof. case: n => [|n] in f g *; first by rewrite !thinmx0. move=> fg; rewrite /kermxpoly; apply: comm_mx_stable_ker. by apply/comm_mx_sym/comm_mx_horner/comm_mx_sym. Qed. Lemma mxdirect_kermxpoly n (g : 'M_n) (p q : {poly K}) : coprimep p q -> (kermxpoly g p :&: kermxpoly g q = 0)%MS. Proof. case: n => [|n] in g *; first by rewrite thinmx0 ?cap0mx ?submx_refl. move=> /Bezout_eq1_coprimepP [[/= u v]]; rewrite mulrC [v * _]mulrC => cpq. apply/eqP/rowV0P => x. rewrite sub_capmx => /andP[/sub_kermxP xgp0 /sub_kermxP xgq0]. move: cpq => /(congr1 (mulmx x \o horner_mx g))/=. rewrite !(rmorphM, rmorphD, rmorph1, mulmx1, mulmxDr, mulmxA). by rewrite xgp0 xgq0 !mul0mx add0r. Qed. Lemma kermxpolyM n (g : 'M_n) (p q : {poly K}) : coprimep p q -> (kermxpoly g (p * q) :=: kermxpoly g p + kermxpoly g q)%MS. Proof. case: n => [|n] in g *; first by rewrite !thinmx0. move=> /Bezout_eq1_coprimepP [[/= u v]]; rewrite mulrC [v * _]mulrC => cpq. apply/eqmxP/andP; split; last first. apply/sub_kermxP/eqmx0P; rewrite !addsmxMr [in X in (_ + X)%MS]mulrC. by rewrite !rmorphM/= !mulmxA !mulmx_ker !mul0mx !addsmx0 submx_refl. move: cpq => /(congr1 (horner_mx g))/=; rewrite rmorph1 rmorphD/=. rewrite -[X in (X <= _)%MS]mulr1 => <-; rewrite mulrDr [p * u]mulrC addrC. rewrite addmx_sub_adds//; apply/sub_kermxP; rewrite mulmxE -mulrA -rmorphM. by rewrite mulrAC [q * p]mulrC rmorphM/= mulrA -!mulmxE mulmx_ker mul0mx. rewrite -[_ * _ * q]mulrA [u * _]mulrC. by rewrite rmorphM mulrA -!mulmxE mulmx_ker mul0mx. Qed. Lemma kermxpoly_prod n (g : 'M_n) (I : finType) (P : {pred I}) (p_ : I -> {poly K}) : {in P &, forall i j, j != i -> coprimep (p_ i) (p_ j)} -> (kermxpoly g (\prod_(i | P i) p_ i) :=: \sum_(i | P i) kermxpoly g (p_ i))%MS. Proof. move=> p_coprime; elim: index_enum (index_enum_uniq I). by rewrite !big_nil ?kermxpoly1 ?submx_refl//. move=> j js ihjs /= /andP[jNjs js_uniq]; apply/eqmxP. rewrite !big_cons; case: ifP => [Pj|PNj]; rewrite ?ihjs ?submx_refl//. suff cjjs: coprimep (p_ j) (\prod_(i <- js | P i) p_ i). by rewrite !kermxpolyM// !(adds_eqmx (eqmx_refl _) (ihjs _)) ?submx_refl. rewrite (@big_morph _ _ _ true andb) ?big_all_cond ?coprimep1//; last first. by move=> p q; rewrite coprimepMr. apply/allP => i i_js; apply/implyP => Pi; apply: p_coprime => //. by apply: contraNneq jNjs => <-. Qed. Lemma mxdirect_sum_kermx n (g : 'M_n) (I : finType) (P : {pred I}) (p_ : I -> {poly K}) : {in P &, forall i j, j != i -> coprimep (p_ i) (p_ j)} -> mxdirect (\sum_(i | P i) kermxpoly g (p_ i))%MS. Proof. move=> p_coprime; apply/mxdirect_sumsP => i Pi; apply/eqmx0P. have cpNi : {in [pred j | P j && (j != i)] &, forall j k : I, k != j -> coprimep (p_ j) (p_ k)}. by move=> j k /andP[Pj _] /andP[Pk _]; apply: p_coprime. rewrite -!(cap_eqmx (eqmx_refl _) (kermxpoly_prod g _))//. rewrite mxdirect_kermxpoly ?submx_refl//. rewrite (@big_morph _ _ _ true andb) ?big_all_cond ?coprimep1//; last first. by move=> p q; rewrite coprimepMr. by apply/allP => j _; apply/implyP => /andP[Pj neq_ji]; apply: p_coprime. Qed. Lemma eigenspace_poly n a (f : 'M_n) : eigenspace f a = kermxpoly f ('X - a%:P). Proof. case: n => [|m] in a f *; first by rewrite !thinmx0. by congr (kermx _); rewrite rmorphB /= ?horner_mx_X ?horner_mx_C. Qed. Definition geigenspace n (g : 'M_n) a := kermxpoly g (('X - a%:P) ^+ n). Lemma geigenspaceE n' (g : 'M_n'.+1) a : geigenspace g a = kermx ((g - a%:M) ^+ n'.+1). Proof. by rewrite /geigenspace /kermxpoly rmorphXn/= rmorphB/= horner_mx_X horner_mx_C. Qed. Lemma eigenspace_sub_geigen n (g : 'M_n) a : (eigenspace g a <= geigenspace g a)%MS. Proof. case: n => [|n] in g *; rewrite ?thinmx0 ?sub0mx// geigenspaceE. by apply/sub_kermxP; rewrite exprS mulmxA mulmx_ker mul0mx. Qed. Lemma mxdirect_sum_geigenspace (I : finType) (n : nat) (g : 'M_n) (P : {pred I}) (a_ : I -> K) : {in P &, injective a_} -> mxdirect (\sum_(i | P i) geigenspace g (a_ i)). Proof. move=> /inj_in_eq eq_a; apply: mxdirect_sum_kermx => i j Pi Pj Nji. by rewrite coprimep_expr ?coprimep_expl// coprimep_XsubC root_XsubC eq_a. Qed. Definition eigenpoly n (g : 'M_n) : pred {poly K} := (fun p => kermxpoly g p != 0). Lemma eigenpolyP n (g : 'M_n) (p : {poly K}) : reflect (exists2 v : 'rV_n, (v <= kermxpoly g p)%MS & v != 0) (eigenpoly g p). Proof. exact: rowV0Pn. Qed. Lemma eigenvalue_poly n a (f : 'M_n) : eigenvalue f a = eigenpoly f ('X - a%:P). Proof. by rewrite /eigenpoly /eigenvalue eigenspace_poly. Qed. Lemma comm_mx_stable_geigenspace n (f g : 'M_n) a : comm_mx f g -> stablemx (geigenspace f a) g. Proof. exact: comm_mx_stable_kermxpoly. Qed. End KernelLemmas. Section MapKermxPoly. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Lemma map_kermxpoly (n : nat) (g : 'M_n) (p : {poly aF}) : map_mx f (kermxpoly g p) = kermxpoly (map_mx f g) (map_poly f p). Proof. by case: n => [|n] in g *; rewrite ?thinmx0// map_kermx map_horner_mx. Qed. Lemma map_geigenspace (n : nat) (g : 'M_n) (a : aF) : map_mx f (geigenspace g a) = geigenspace (map_mx f g) (f a). Proof. by rewrite map_kermxpoly rmorphXn/= rmorphB /= map_polyX map_polyC. Qed. Lemma eigenpoly_map n (g : 'M_n) (p : {poly aF}) : eigenpoly (map_mx f g) (map_poly f p) = eigenpoly g p. Proof. by rewrite /eigenpoly -map_kermxpoly map_mx_eq0. Qed. End MapKermxPoly. Section IntegralOverRing. Definition integralOver (R K : nzRingType) (RtoK : R -> K) (z : K) := exists2 p, p \is monic & root (map_poly RtoK p) z. Definition integralRange R K RtoK := forall z, @integralOver R K RtoK z. Variables (B R K : nzRingType) (BtoR : B -> R) (RtoK : {rmorphism R -> K}). Lemma integral_rmorph x : integralOver BtoR x -> integralOver (RtoK \o BtoR) (RtoK x). Proof. by case=> p; exists p; rewrite // map_poly_comp rmorph_root. Qed. Lemma integral_id x : integralOver RtoK (RtoK x). Proof. by exists ('X - x%:P); rewrite ?monicXsubC ?rmorph_root ?root_XsubC. Qed. Lemma integral_nat n : integralOver RtoK n%:R. Proof. by rewrite -(rmorph_nat RtoK); apply: integral_id. Qed. Lemma integral0 : integralOver RtoK 0. Proof. exact: (integral_nat 0). Qed. Lemma integral1 : integralOver RtoK 1. Proof. exact: (integral_nat 1). Qed. Lemma integral_poly (p : {poly K}) : (forall i, integralOver RtoK p`_i) <-> {in p : seq K, integralRange RtoK}. Proof. split=> intRp => [_ /(nthP 0)[i _ <-] // | i]; rewrite -[p]coefK coef_poly. by case: ifP => [ltip | _]; [apply/intRp/mem_nth | apply: integral0]. Qed. End IntegralOverRing. Section IntegralOverComRing. Variables (R K : comNzRingType) (RtoK : {rmorphism R -> K}). Lemma integral_horner_root w (p q : {poly K}) : p \is monic -> root p w -> {in p : seq K, integralRange RtoK} -> {in q : seq K, integralRange RtoK} -> integralOver RtoK q.[w]. Proof. move=> mon_p pw0 intRp intRq. pose memR y := exists x, y = RtoK x. have memRid x: memR (RtoK x) by exists x. have memR_nat n: memR n%:R by rewrite -(rmorph_nat RtoK) /=. have [memR0 memR1]: memR 0 * memR 1 := (memR_nat 0, memR_nat 1). have memRN1: memR (- 1) by exists (- 1); rewrite rmorphN1. pose rVin (E : K -> Prop) n (a : 'rV[K]_n) := forall i, E (a 0 i). pose pXin (E : K -> Prop) (r : {poly K}) := forall i, E r`_i. pose memM E n (X : 'rV_n) y := exists a, rVin E n a /\ y = (a *m X^T) 0 0. pose finM E S := exists n, exists X, forall y, memM E n X y <-> S y. have tensorM E n1 n2 X Y: finM E (memM (memM E n2 Y) n1 X). exists (n1 * n2)%N, (mxvec (X^T *m Y)) => y. split=> [[a [Ea Dy]] | [a1 [/fin_all_exists[a /all_and2[Ea Da1]] ->]]]. exists (Y *m (vec_mx a)^T); split=> [i|]. exists (row i (vec_mx a)); split=> [j|]; first by rewrite !mxE; apply: Ea. by rewrite -row_mul -{1}[Y]trmxK -trmx_mul !mxE. by rewrite -[Y]trmxK -!trmx_mul mulmxA -mxvec_dotmul trmx_mul trmxK vec_mxK. exists (mxvec (\matrix_i a i)); split. by case/mxvec_indexP=> i j; rewrite mxvecE mxE; apply: Ea. rewrite -[mxvec _]trmxK -trmx_mul mxvec_dotmul -mulmxA trmx_mul !mxE. apply: eq_bigr => i _; rewrite Da1 !mxE; congr (_ * _). by apply: eq_bigr => j _; rewrite !mxE. suffices [m [X [[u [_ Du]] idealM]]]: exists m, exists X, let M := memM memR m X in M 1 /\ forall y, M y -> M (q.[w] * y). - do [set M := memM _ m X; move: q.[w] => z] in idealM *. have MX i: M (X 0 i). by exists (delta_mx 0 i); split=> [j|]; rewrite -?rowE !mxE. have /fin_all_exists[a /all_and2[Fa Da1]] i := idealM _ (MX i). have /fin_all_exists[r Dr] i := fin_all_exists (Fa i). pose A := \matrix_(i, j) r j i; pose B := z%:M - map_mx RtoK A. have XB0: X *m B = 0. apply/eqP; rewrite mulmxBr mul_mx_scalar subr_eq0; apply/eqP/rowP=> i. by rewrite !mxE Da1 mxE; apply: eq_bigr=> j _; rewrite !mxE mulrC Dr. exists (char_poly A); first exact: char_poly_monic. have: (\det B *: (u *m X^T)) 0 0 == 0. rewrite scalemxAr -linearZ -mul_mx_scalar -mul_mx_adj mulmxA XB0 /=. by rewrite mul0mx trmx0 mulmx0 mxE. rewrite mxE -Du mulr1 rootE -horner_evalE -2!det_map_mx; congr (\det _ == 0). rewrite raddfB/= map_scalar_mx; apply/matrixP=> i j. by rewrite !mxE raddfB raddfMn/= map_polyX map_polyC /horner_eval !hornerE. pose gen1 x E y := exists2 r, pXin E r & y = r.[x]; pose gen := foldr gen1 memR. have gen1S (E : K -> Prop) x y: E 0 -> E y -> gen1 x E y. by exists y%:P => [i|]; rewrite ?hornerC ?coefC //; case: ifP. have genR S y: memR y -> gen S y. by elim: S => //= x S IH in y * => /IH; apply/gen1S/IH. have gen0 := genR _ 0 memR0; have gen_1 := genR _ 1 memR1. have{gen1S} genS S y: y \in S -> gen S y. elim: S => //= x S IH /predU1P[-> | /IH//]; last exact: gen1S. by exists 'X => [i|]; rewrite ?hornerX // coefX; apply: genR. pose propD (R : K -> Prop) := forall x y, R x -> R y -> R (x + y). have memRD: propD memR. by move=> _ _ [a ->] [b ->]; exists (a + b); rewrite rmorphD. have genD S: propD (gen S). elim: S => //= x S IH _ _ [r1 Sr1 ->] [r2 Sr2 ->]; rewrite -hornerD. by exists (r1 + r2) => // i; rewrite coefD; apply: IH. have gen_sum S := big_ind _ (gen0 S) (genD S). pose propM (R : K -> Prop) := forall x y, R x -> R y -> R (x * y). have memRM: propM memR. by move=> _ _ [a ->] [b ->]; exists (a * b); rewrite rmorphM. have genM S: propM (gen S). elim: S => //= x S IH _ _ [r1 Sr1 ->] [r2 Sr2 ->]; rewrite -hornerM. by exists (r1 * r2) => // i; rewrite coefM; apply: gen_sum => j _; apply: IH. have gen_horner S r y: pXin (gen S) r -> gen S y -> gen S r.[y]. move=> Sq Sy; rewrite horner_coef; apply: gen_sum => [[i _] /= _]. by elim: {2}i => [|n IHn]; rewrite ?mulr1 // exprSr mulrA; apply: genM. pose S := w :: q ++ p; suffices [m [X defX]]: finM memR (gen S). exists m, X => M; split=> [|y /defX Xy]; first exact/defX. apply/defX/genM => //; apply: gen_horner => // [i|]; last exact/genS/mem_head. rewrite -[q]coefK coef_poly; case: ifP => // lt_i_q. by apply: genS; rewrite inE mem_cat mem_nth ?orbT. pose intR R y := exists r, [/\ r \is monic, root r y & pXin R r]. pose fix genI s := if s is y :: s1 then intR (gen s1) y /\ genI s1 else True. have{mon_p pw0 intRp intRq}: genI S. split; set S1 := _ ++ _; first exists p. split=> // i; rewrite -[p]coefK coef_poly; case: ifP => // lt_i_p. by apply: genS; rewrite mem_cat orbC mem_nth. set S2 := S1; have: all [in S1] S2 by apply/allP. elim: S2 => //= y S2 IH /andP[S1y S12]; split; last exact: IH. have{q S S1 IH S1y S12 intRp intRq} [q mon_q qx0]: integralOver RtoK y. by move: S1y; rewrite mem_cat => /orP[]; [apply: intRq | apply: intRp]. exists (map_poly RtoK q); split=> // [|i]; first exact: monic_map. by rewrite coef_map /=; apply: genR. elim: {w p q}S => /= [_|x S IH [[p [mon_p px0 Sp]] /IH{IH}[m2 [X2 defS]]]]. exists 1, 1 => y; split=> [[a [Fa ->]] | Fy]. by rewrite tr_scalar_mx mulmx1; apply: Fa. by exists y%:M; split=> [i|]; rewrite 1?ord1 ?tr_scalar_mx ?mulmx1 mxE. pose m1 := (size p).-1; pose X1 := \row_(i < m1) x ^+ i. have [m [X defM]] := tensorM memR m1 m2 X1 X2; set M := memM _ _ _ in defM. exists m, X => y; rewrite -/M; split=> [/defM[a [M2a]] | [q Sq]] -> {y}. exists (rVpoly a) => [i|]. by rewrite coef_rVpoly; case/insub: i => // i; apply/defS/M2a. rewrite mxE (horner_coef_wide _ (size_poly _ _)) -/(rVpoly a). by apply: eq_bigr => i _; rewrite coef_rVpoly_ord !mxE. have M_0: M 0 by exists 0; split=> [i|]; rewrite ?mul0mx mxE. have M_D: propD M. move=> _ _ [a [Fa ->]] [b [Fb ->]]; exists (a + b). by rewrite mulmxDl !mxE; split=> // i /[1!mxE]; apply: memRD. have{M_0 M_D} Msum := big_ind _ M_0 M_D. rewrite horner_coef; apply: (Msum) => i _; case: i q`_i {Sq}(Sq i) => /=. elim: {q}(size q) => // n IHn i i_le_n y Sy. have [i_lt_m1 | m1_le_i] := ltnP i m1. apply/defM; exists (y *: delta_mx 0 (Ordinal i_lt_m1)); split=> [j|]. by apply/defS; rewrite !mxE /= mulr_natr; case: eqP. by rewrite -scalemxAl -rowE !mxE. rewrite -(subnK m1_le_i) exprD -[x ^+ m1]subr0 -(rootP px0) horner_coef. rewrite polySpred ?monic_neq0 // -/m1 big_ord_recr /= -lead_coefE. rewrite opprD addrC (monicP mon_p) mul1r subrK !mulrN -mulNr !mulr_sumr. apply: Msum => j _; rewrite [X in M X]mulrA mulrACA -exprD; apply: IHn. by rewrite -addnS addnC addnBA // leq_subLR leq_add. by rewrite -mulN1r; do 2!apply: (genM) => //; apply: genR. Qed. Lemma integral_root_monic u p : p \is monic -> root p u -> {in p : seq K, integralRange RtoK} -> integralOver RtoK u. Proof. move=> mon_p pu0 intRp; rewrite -[u]hornerX. apply: integral_horner_root mon_p pu0 intRp _. by apply/integral_poly => i; rewrite coefX; apply: integral_nat. Qed. Let integral0_RtoK := integral0 RtoK. Let integral1_RtoK := integral1 RtoK. Let monicXsubC_K := @monicXsubC K. Hint Resolve integral0_RtoK integral1_RtoK monicXsubC_K : core. Let XsubC0 (u : K) : root ('X - u%:P) u. Proof. by rewrite root_XsubC. Qed. Let intR_XsubC u : integralOver RtoK (- u) -> {in 'X - u%:P : seq K, integralRange RtoK}. Proof. by move=> intRu v; rewrite polyseqXsubC !inE => /pred2P[]->. Qed. Lemma integral_opp u : integralOver RtoK u -> integralOver RtoK (- u). Proof. by rewrite -{1}[u]opprK => /intR_XsubC/integral_root_monic; apply. Qed. Lemma integral_horner (p : {poly K}) u : {in p : seq K, integralRange RtoK} -> integralOver RtoK u -> integralOver RtoK p.[u]. Proof. by move=> ? /integral_opp/intR_XsubC/integral_horner_root; apply. Qed. Lemma integral_sub u v : integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u - v). Proof. move=> intRu /integral_opp/intR_XsubC/integral_horner/(_ intRu). by rewrite !hornerE. Qed. Lemma integral_add u v : integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u + v). Proof. by rewrite -{2}[v]opprK => intRu /integral_opp; apply: integral_sub. Qed. Lemma integral_mul u v : integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u * v). Proof. rewrite -{2}[v]hornerX -hornerZ => intRu; apply: integral_horner. by apply/integral_poly=> i; rewrite coefZ coefX mulr_natr mulrb; case: ifP. Qed. End IntegralOverComRing. Section IntegralOverField. Variables (F E : fieldType) (FtoE : {rmorphism F -> E}). Definition algebraicOver (fFtoE : F -> E) u := exists2 p, p != 0 & root (map_poly fFtoE p) u. Notation mk_mon p := ((lead_coef p)^-1 *: p). Lemma integral_algebraic u : algebraicOver FtoE u <-> integralOver FtoE u. Proof. split=> [] [p p_nz pu0]; last by exists p; rewrite ?monic_neq0. exists (mk_mon p); first by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0. by rewrite linearZ rootE hornerZ (rootP pu0) mulr0. Qed. Lemma algebraic_id a : algebraicOver FtoE (FtoE a). Proof. exact/integral_algebraic/integral_id. Qed. Lemma algebraic0 : algebraicOver FtoE 0. Proof. exact/integral_algebraic/integral0. Qed. Lemma algebraic1 : algebraicOver FtoE 1. Proof. exact/integral_algebraic/integral1. Qed. Lemma algebraic_opp x : algebraicOver FtoE x -> algebraicOver FtoE (- x). Proof. by move/integral_algebraic/integral_opp/integral_algebraic. Qed. Lemma algebraic_add x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x + y). Proof. move/integral_algebraic=> intFx /integral_algebraic intFy. exact/integral_algebraic/integral_add. Qed. Lemma algebraic_sub x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x - y). Proof. by move=> algFx /algebraic_opp; apply: algebraic_add. Qed. Lemma algebraic_mul x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x * y). Proof. move/integral_algebraic=> intFx /integral_algebraic intFy. exact/integral_algebraic/integral_mul. Qed. Lemma algebraic_inv u : algebraicOver FtoE u -> algebraicOver FtoE u^-1. Proof. have [-> | /expf_neq0 nz_u_n] := eqVneq u 0; first by rewrite invr0. case=> p nz_p pu0; exists (Poly (rev p)). apply/eqP=> /polyP/(_ 0); rewrite coef_Poly coef0 nth_rev ?size_poly_gt0 //. by apply/eqP; rewrite subn1 lead_coef_eq0. apply/eqP/(mulfI (nz_u_n (size p).-1)); rewrite mulr0 -(rootP pu0). rewrite (@horner_coef_wide _ (size p)); last first. by rewrite size_map_poly -(size_rev p) size_Poly. rewrite horner_coef mulr_sumr size_map_poly. rewrite [rhs in _ = rhs](reindex_inj rev_ord_inj) /=. apply: eq_bigr => i _; rewrite !coef_map coef_Poly nth_rev // mulrCA. by congr (_ * _); rewrite -{1}(subnKC (valP i)) addSn addnC exprD exprVn ?mulfK. Qed. Lemma algebraic_div x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x / y). Proof. by move=> algFx /algebraic_inv; apply: algebraic_mul. Qed. Lemma integral_inv x : integralOver FtoE x -> integralOver FtoE x^-1. Proof. by move/integral_algebraic/algebraic_inv/integral_algebraic. Qed. Lemma integral_div x y : integralOver FtoE x -> integralOver FtoE y -> integralOver FtoE (x / y). Proof. by move=> algFx /integral_inv; apply: integral_mul. Qed. Lemma integral_root p u : p != 0 -> root p u -> {in p : seq E, integralRange FtoE} -> integralOver FtoE u. Proof. move=> nz_p pu0 algFp. have mon_p1: mk_mon p \is monic. by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0. have p1u0: root (mk_mon p) u by rewrite rootE hornerZ (rootP pu0) mulr0. apply: integral_root_monic mon_p1 p1u0 _ => _ /(nthP 0)[i ltip <-]. rewrite coefZ mulrC; rewrite size_scale ?invr_eq0 ?lead_coef_eq0 // in ltip. by apply: integral_div; apply/algFp/mem_nth; rewrite -?polySpred. Qed. End IntegralOverField. (* Lifting term, formula, envs and eval to matrices. Wlog, and for the sake *) (* of simplicity, we only lift (tensor) envs to row vectors; we can always *) (* use mxvec/vec_mx to store and retrieve matrices. *) (* We don't provide definitions for addition, subtraction, scaling, etc, *) (* because they have simple matrix expressions. *) Module MatrixFormula. Section MatrixFormula. Variable F : fieldType. Local Notation False := GRing.False. Local Notation True := GRing.True. Local Notation And := GRing.And (only parsing). Local Notation Add := GRing.Add (only parsing). Local Notation Bool b := (GRing.Bool b%bool). Local Notation term := (GRing.term F). Local Notation form := (GRing.formula F). Local Notation eval := GRing.eval. Local Notation holds := GRing.holds. Local Notation qf_form := GRing.qf_form. Local Notation qf_eval := GRing.qf_eval. Definition eval_mx (e : seq F) := @map_mx term F (eval e). Definition mx_term := @map_mx F term GRing.Const. Lemma eval_mx_term e m n (A : 'M_(m, n)) : eval_mx e (mx_term A) = A. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Definition mulmx_term m n p (A : 'M[term]_(m, n)) (B : 'M_(n, p)) := \matrix_(i, k) (\big[Add/0]_j (A i j * B j k))%T. Lemma eval_mulmx e m n p (A : 'M[term]_(m, n)) (B : 'M_(n, p)) : eval_mx e (mulmx_term A B) = eval_mx e A *m eval_mx e B. Proof. apply/matrixP=> i k; rewrite !mxE /= ((big_morph (eval e)) 0 +%R) //=. by apply: eq_bigr => j _; rewrite /= !mxE. Qed. Local Notation morphAnd f := ((big_morph f) true andb). Let Schur m n (A : 'M[term]_(1 + m, 1 + n)) (a := A 0 0) := \matrix_(i, j) (drsubmx A i j - a^-1 * dlsubmx A i 0%R * ursubmx A 0%R j)%T. Fixpoint mxrank_form (r m n : nat) : 'M_(m, n) -> form := match m, n return 'M_(m, n) -> form with | m'.+1, n'.+1 => fun A : 'M_(1 + m', 1 + n') => let nzA k := A k.1 k.2 != 0 in let xSchur k := Schur (xrow k.1 0%R (xcol k.2 0%R A)) in let recf k := Bool (r > 0) /\ mxrank_form r.-1 (xSchur k) in GRing.Pick nzA recf (Bool (r == 0%N)) | _, _ => fun _ => Bool (r == 0%N) end%T. Lemma mxrank_form_qf r m n (A : 'M_(m, n)) : qf_form (mxrank_form r A). Proof. by elim: m r n A => [|m IHm] r [|n] A //=; rewrite GRing.Pick_form_qf /=. Qed. Lemma eval_mxrank e r m n (A : 'M_(m, n)) : qf_eval e (mxrank_form r A) = (\rank (eval_mx e A) == r). Proof. elim: m r n A => [|m IHm] r [|n] A /=; try by case r; rewrite unlock. rewrite GRing.eval_Pick !unlock /=; set pf := fun _ => _. rewrite -(@eq_pick _ pf) => [|k]; rewrite {}/pf ?mxE // eq_sym. case: pick => [[i j]|] //=; set B := _ - _; have:= mxrankE B. case: (Gaussian_elimination_ B) r => [[_ _] _] [|r] //= <-; rewrite {}IHm eqSS. by congr (\rank _ == r); apply/matrixP=> k l; rewrite !(mxE, big_ord1) !tpermR. Qed. Lemma eval_vec_mx e m n (u : 'rV_(m * n)) : eval_mx e (vec_mx u) = vec_mx (eval_mx e u). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma eval_mxvec e m n (A : 'M_(m, n)) : eval_mx e (mxvec A) = mxvec (eval_mx e A). Proof. by rewrite -{2}[A]mxvecK eval_vec_mx vec_mxK. Qed. Section Subsetmx. Variables (m1 m2 n : nat) (A : 'M[term]_(m1, n)) (B : 'M[term]_(m2, n)). Definition submx_form := \big[And/True]_(r < n.+1) (mxrank_form r (col_mx A B) ==> mxrank_form r B)%T. Lemma eval_col_mx e : eval_mx e (col_mx A B) = col_mx (eval_mx e A) (eval_mx e B). Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed. Lemma submx_form_qf : qf_form submx_form. Proof. by rewrite (morphAnd (@qf_form _)) ?big1 //= => r _; rewrite !mxrank_form_qf. Qed. Lemma eval_submx e : qf_eval e submx_form = (eval_mx e A <= eval_mx e B)%MS. Proof. rewrite (morphAnd (qf_eval e)) //= big_andE /=. apply/forallP/idP=> /= [|sAB d]; last first. rewrite !eval_mxrank eval_col_mx -addsmxE; apply/implyP=> /eqP <-. by rewrite mxrank_leqif_sup ?addsmxSr // addsmx_sub sAB /=. move/(_ (inord (\rank (eval_mx e (col_mx A B))))). rewrite inordK ?ltnS ?rank_leq_col // !eval_mxrank eqxx /= eval_col_mx. by rewrite -addsmxE mxrank_leqif_sup ?addsmxSr // addsmx_sub; case/andP. Qed. End Subsetmx. Section Env. Variable d : nat. Definition seq_of_rV (v : 'rV_d) : seq F := fgraph [ffun i => v 0 i]. Lemma size_seq_of_rV v : size (seq_of_rV v) = d. Proof. by rewrite tuple.size_tuple card_ord. Qed. Lemma nth_seq_of_rV x0 v (i : 'I_d) : nth x0 (seq_of_rV v) i = v 0 i. Proof. by rewrite nth_fgraph_ord ffunE. Qed. Definition row_var k : 'rV[term]_d := \row_i ('X_(k * d + i))%T. Definition row_env (e : seq 'rV_d) := flatten (map seq_of_rV e). Lemma nth_row_env e k (i : 'I_d) : (row_env e)`_(k * d + i) = e`_k 0 i. Proof. elim: e k => [|v e IHe] k; first by rewrite !nth_nil mxE. rewrite /row_env /= nth_cat size_seq_of_rV. case: k => [|k]; first by rewrite (valP i) nth_seq_of_rV. by rewrite mulSn -addnA -if_neg -leqNgt leq_addr addKn IHe. Qed. Lemma eval_row_var e k : eval_mx (row_env e) (row_var k) = e`_k :> 'rV_d. Proof. by apply/rowP=> i; rewrite !mxE /= nth_row_env. Qed. Definition Exists_row_form k (f : form) := foldr GRing.Exists f (codom (fun i : 'I_d => k * d + i)%N). Lemma Exists_rowP e k f : d > 0 -> ((exists v : 'rV[F]_d, holds (row_env (set_nth 0 e k v)) f) <-> holds (row_env e) (Exists_row_form k f)). Proof. move=> d_gt0; pose i_ j := Ordinal (ltn_pmod j d_gt0). have d_eq j: (j = j %/ d * d + i_ j)%N := divn_eq j d. split=> [[v f_v] | ]; last case/GRing.foldExistsP=> e' ee' f_e'. apply/GRing.foldExistsP; exists (row_env (set_nth 0 e k v)) => {f f_v}// j. rewrite [j]d_eq !nth_row_env nth_set_nth /=; case: eqP => // ->. by case/imageP; exists (i_ j). exists (\row_i e'`_(k * d + i)); apply: eq_holds f_e' => j /=. move/(_ j): ee'; rewrite [j]d_eq !nth_row_env nth_set_nth /=. case: eqP => [-> | ne_j_k -> //]; first by rewrite mxE. apply/mapP=> [[r lt_r_d]]; rewrite -d_eq => def_j; case: ne_j_k. by rewrite def_j divnMDl // divn_small ?addn0. Qed. End Env. End MatrixFormula. End MatrixFormula. Section ConjMx. Context {F : fieldType}. Definition conjmx (m n : nat) (V : 'M_(m, n)) (f : 'M[F]_n) : 'M_m := V *m f *m pinvmx V. Notation restrictmx V := (conjmx (row_base V)). Lemma stablemx_comp (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : stablemx W f -> stablemx V (conjmx W f) -> stablemx (V *m W) f. Proof. by move=> Wf /(submxMr W); rewrite -mulmxA mulmxKpV// mulmxA. Qed. Lemma stablemx_restrict m n (A : 'M[F]_n) (V : 'M_n) (W : 'M_(m, \rank V)): stablemx V A -> stablemx W (restrictmx V A) = stablemx (W *m row_base V) A. Proof. move=> A_stabV; rewrite mulmxA -[in RHS]mulmxA. rewrite -(submxMfree _ W (row_base_free V)) mulmxKpV //. by rewrite mulmx_sub ?stablemx_row_base. Qed. Lemma conjmxM (m n : nat) (V : 'M[F]_(m, n)) : {in [pred f | stablemx V f] &, {morph conjmx V : f g / f *m g}}. Proof. move=> f g; rewrite !inE => Vf Vg /=. by rewrite /conjmx 2!mulmxA mulmxA mulmxKpV ?stablemx_row_base. Qed. Lemma conjMmx (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : row_free (V *m W) -> stablemx W f -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> rfVW Wf VWf; apply: (row_free_inj rfVW); rewrite mulmxKpV ?stablemx_comp//. by rewrite mulmxA mulmxKpV// -[RHS]mulmxA mulmxKpV ?mulmxA. Qed. Lemma conjuMmx (m n : nat) (V : 'M[F]_m) (W : 'M_(m, n)) (f : 'M_n) : V \in unitmx -> row_free W -> stablemx W f -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Vu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree// -/(row_free V) row_free_unit. Qed. Lemma conjMumx (m n : nat) (V : 'M[F]_(m, n)) (W f : 'M_n) : W \in unitmx -> row_free V -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Wu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree ?row_free_unit. Qed. Lemma conjuMumx (n : nat) (V W f : 'M[F]_n) : V \in unitmx -> W \in unitmx -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. by move=> Vu Wu; rewrite conjuMmx ?stablemx_unit ?row_free_unit. Qed. Lemma conjmx_scalar (m n : nat) (V : 'M[F]_(m, n)) (a : F) : row_free V -> conjmx V a%:M = a%:M. Proof. by move=> rfV; rewrite /conjmx scalar_mxC mulmxKp. Qed. Lemma conj0mx (m n : nat) f : conjmx (0 : 'M[F]_(m, n)) f = 0. Proof. by rewrite /conjmx !mul0mx. Qed. Lemma conjmx0 (m n : nat) (V : 'M[F]_(m, n)) : conjmx V 0 = 0. Proof. by rewrite /conjmx mulmx0 mul0mx. Qed. Lemma conjumx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx V f = V *m f *m invmx V. Proof. by move=> uV; rewrite /conjmx pinvmxE. Qed. Lemma conj1mx (n : nat) (f : 'M[F]_n) : conjmx 1%:M f = f. Proof. by rewrite conjumx ?unitmx1// invmx1 mulmx1 mul1mx. Qed. Lemma conjVmx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) f = invmx V *m f *m V. Proof. by move=> Vunit; rewrite conjumx ?invmxK ?unitmx_inv. Qed. Lemma conjmxK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) (conjmx V f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulVmx ?conj1mx. Qed. Lemma conjmxVK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx V (conjmx (invmx V) f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulmxV ?conj1mx. Qed. Lemma horner_mx_conj m n p (V : 'M[F]_(n.+1, m.+1)) (f : 'M_m.+1) : row_free V -> stablemx V f -> horner_mx (conjmx V f) p = conjmx V (horner_mx f p). Proof. move=> V_free V_stab; rewrite/conjmx; elim/poly_ind: p => [|p c]. by rewrite !rmorph0 mulmx0 mul0mx. rewrite !(rmorphD, rmorphM)/= !(horner_mx_X, horner_mx_C) => ->. rewrite [_ * _]mulmxA [_ *m (V *m _)]mulmxA mulmxKpV ?horner_mx_stable//. apply: (row_free_inj V_free); rewrite [_ *m V]mulmxDl. pose stablemxE := (stablemxD, stablemxM, stablemxC, horner_mx_stable). by rewrite !mulmxKpV -?[V *m _ *m _]mulmxA ?stablemxE// mulmxDr -scalar_mxC. Qed. Lemma horner_mx_uconj n p (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \is a GRing.unit -> horner_mx (V *m f *m invmx V) p = V *m horner_mx f p *m invmx V. Proof. move=> V_unit; rewrite -!conjumx//. by rewrite horner_mx_conj ?row_free_unit ?stablemx_unit. Qed. Lemma horner_mx_uconjC n p (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \is a GRing.unit -> horner_mx (invmx V *m f *m V) p = invmx V *m horner_mx f p *m V. Proof. move=> V_unit; rewrite -[X in _ *m X](invmxK V). by rewrite horner_mx_uconj ?invmxK ?unitmx_inv. Qed. Lemma mxminpoly_conj m n (V : 'M[F]_(m.+1, n.+1)) (f : 'M_n.+1) : row_free V -> stablemx V f -> mxminpoly (conjmx V f) %| mxminpoly f. Proof. by move=> *; rewrite mxminpoly_min// horner_mx_conj// mx_root_minpoly conjmx0. Qed. Lemma mxminpoly_uconj n (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \in unitmx -> mxminpoly (conjmx V f) = mxminpoly f. Proof. have simp := (row_free_unit, stablemx_unit, unitmx_inv, unitmx1). move=> Vu; apply/eqP; rewrite -eqp_monic ?mxminpoly_monic// /eqp. apply/andP; split; first by rewrite mxminpoly_conj ?simp. by rewrite -[f in X in X %| _](conjmxK _ Vu) mxminpoly_conj ?simp. Qed. Section fixed_stablemx_space. Variables (m n : nat). Implicit Types (V : 'M[F]_(m, n)) (A : 'M[F]_n). Implicit Types (a : F) (p : {poly F}). Section Sub. Variable (k : nat). Implicit Types (W : 'M[F]_(k, m)). Lemma sub_kermxpoly_conjmx V f p W : stablemx V f -> row_free V -> (W <= kermxpoly (conjmx V f) p)%MS = (W *m V <= kermxpoly f p)%MS. Proof. case: n m => [|n'] [|m'] in V f W * => fV rfV; rewrite ?thinmx0//. by rewrite /row_free mxrank.unlock in rfV. by rewrite mul0mx !sub0mx. apply/sub_kermxP/sub_kermxP; rewrite horner_mx_conj//; last first. by move=> /(congr1 (mulmxr (pinvmx V)))/=; rewrite mul0mx !mulmxA. move=> /(congr1 (mulmxr V))/=; rewrite ![W *m _]mulmxA ?mul0mx mulmxKpV//. by rewrite -mulmxA mulmx_sub// horner_mx_stable//. Qed. Lemma sub_eigenspace_conjmx V f a W : stablemx V f -> row_free V -> (W <= eigenspace (conjmx V f) a)%MS = (W *m V <= eigenspace f a)%MS. Proof. by move=> fV rfV; rewrite !eigenspace_poly sub_kermxpoly_conjmx. Qed. End Sub. Lemma eigenpoly_conjmx V f : stablemx V f -> row_free V -> {subset eigenpoly (conjmx V f) <= eigenpoly f}. Proof. move=> fV rfV a /eigenpolyP [x]; rewrite sub_kermxpoly_conjmx//. move=> xV_le_fa x_neq0; apply/eigenpolyP. by exists (x *m V); rewrite ?mulmx_free_eq0. Qed. Lemma eigenvalue_conjmx V f : stablemx V f -> row_free V -> {subset eigenvalue (conjmx V f) <= eigenvalue f}. Proof. by move=> fV rfV a; rewrite ![_ \in _]eigenvalue_poly; apply: eigenpoly_conjmx. Qed. Lemma conjmx_eigenvalue a V f : (V <= eigenspace f a)%MS -> row_free V -> conjmx V f = a%:M. Proof. by move=> /eigenspaceP Vfa rfV; rewrite /conjmx Vfa -mul_scalar_mx mulmxKp. Qed. End fixed_stablemx_space. End ConjMx. Notation restrictmx V := (conjmx (row_base V)). Definition simmx_to_for {F : fieldType} {m n} (P : 'M_(m, n)) A (S : {pred 'M[F]_m}) := S (conjmx P A). Notation "A ~_ P '{' 'in' S '}'" := (simmx_to_for P A S) (at level 70, P at level 0, format "A ~_ P '{' 'in' S '}'") : ring_scope. Notation simmx_for P A B := (A ~_P {in PredOfSimpl.coerce (pred1 B)}). Notation "A ~_ P B" := (simmx_for P A B) (format "A ~_ P B"). Notation simmx_in S A B := (exists2 P, P \in S & A ~_P B). Notation "A '~_{in' S '}' B" := (simmx_in S A B) (at level 70, format "A '~_{in' S '}' B"). Notation simmx_in_to S A S' := (exists2 P, P \in S & A ~_P {in S'}). Notation "A '~_{in' S '}' '{' 'in' S' '}'" := (simmx_in_to S A S') (format "A '~_{in' S '}' '{' 'in' S' '}'"). Notation all_simmx_in S As S' := (exists2 P, P \in S & all [pred A | A ~_P {in S'}] As). Notation diagonalizable_for P A := (A ~_P {in is_diag_mx}). Notation diagonalizable_in S A := (A ~_{in S} {in is_diag_mx}). Notation diagonalizable A := (diagonalizable_in unitmx A). Notation codiagonalizable_in S As := (all_simmx_in S As is_diag_mx). Notation codiagonalizable As := (codiagonalizable_in unitmx As). Section Simmxity. Context {F : fieldType}. Lemma simmxPp m n {P : 'M[F]_(m, n)} {A B} : stablemx P A -> A ~_P B -> P *m A = B *m P. Proof. by move=> stablemxPA /eqP <-; rewrite mulmxKpV. Qed. Lemma simmxW m n {P : 'M[F]_(m, n)} {A B} : row_free P -> P *m A = B *m P -> A ~_P B. Proof. by rewrite /(_ ~__ _)/= /conjmx => fP ->; rewrite mulmxKp. Qed. Section Simmx. Context {n : nat}. Implicit Types (A B P : 'M[F]_n) (As : seq 'M[F]_n) (d : 'rV[F]_n). Lemma simmxP {P A B} : P \in unitmx -> reflect (P *m A = B *m P) (A ~_P B). Proof. move=> p_unit; apply: (iffP idP); first exact/simmxPp/stablemx_unit. by apply: simmxW; rewrite row_free_unit. Qed. Lemma simmxRL {P A B} : P \in unitmx -> reflect (B = P *m A *m invmx P) (A ~_P B). Proof. by move=> ?; apply: (iffP eqP); rewrite conjumx. Qed. Lemma simmxLR {P A B} : P \in unitmx -> reflect (A = conjmx (invmx P) B) (A ~_P B). Proof. by move=> Pu; rewrite conjVmx//; apply: (iffP (simmxRL Pu)) => ->; rewrite !mulmxA ?(mulmxK, mulmxKV, mulVmx, mulmxV, mul1mx, mulmx1). Qed. End Simmx. Lemma simmx_minpoly {n} {P A B : 'M[F]_n.+1} : P \in unitmx -> A ~_P B -> mxminpoly A = mxminpoly B. Proof. by move=> Pu /eqP<-; rewrite mxminpoly_uconj. Qed. Lemma diagonalizable_for_row_base m n (P : 'M[F]_(m, n)) (A : 'M_n) : diagonalizable_for (row_base P) A = is_diag_mx (restrictmx P A). Proof. by []. Qed. Lemma diagonalizable_forPp m n (P : 'M[F]_(m, n)) A : reflect (forall i j : 'I__, i != j :> nat -> conjmx P A i j = 0) (diagonalizable_for P A). Proof. exact: @is_diag_mxP. Qed. Lemma diagonalizable_forP n (P : 'M[F]_n) A : P \in unitmx -> reflect (forall i j : 'I__, i != j :> nat -> (P *m A *m invmx P) i j = 0) (diagonalizable_for P A). Proof. by move=> Pu; rewrite -conjumx//; exact: is_diag_mxP. Qed. Lemma diagonalizable_forPex {m} {n} {P : 'M[F]_(m, n)} {A} : reflect (exists D, A ~_P (diag_mx D)) (diagonalizable_for P A). Proof. by apply: (iffP (diag_mxP _)) => -[D]/eqP; exists D. Qed. Lemma diagonalizable_forLR n {P : 'M[F]_n} {A} : P \in unitmx -> reflect (exists D, A = conjmx (invmx P) (diag_mx D)) (diagonalizable_for P A). Proof. by move=> Punit; apply: (iffP diagonalizable_forPex) => -[D /(simmxLR Punit)]; exists D. Qed. Lemma diagonalizable_for_mxminpoly {n} {P A : 'M[F]_n.+1} (rs := undup [seq conjmx P A i i | i <- enum 'I_n.+1]) : P \in unitmx -> diagonalizable_for P A -> mxminpoly A = \prod_(r <- rs) ('X - r%:P). Proof. rewrite /rs => pu /(diagonalizable_forLR pu)[d {A rs}->]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by rewrite [in X in _ = X](@eq_map _ _ _ (d 0))// => i; rewrite conjmxVK// mxE eqxx. Qed. End Simmxity. Lemma diagonalizable_for_sum (F : fieldType) (m n : nat) (p_ : 'I_n -> nat) (V_ : forall i, 'M[F]_(p_ i, m)) (A : 'M[F]_m) : mxdirect (\sum_i <<V_ i>>) -> (forall i, stablemx (V_ i) A) -> (forall i, row_free (V_ i)) -> diagonalizable_for (\mxcol_i V_ i) A = [forall i, diagonalizable_for (V_ i) A]. Proof. move=> Vd VA rAV; have aVA : stablemx (\mxcol_i V_ i) A. rewrite (eqmx_stable _ (eqmx_col _)) stablemx_sums//. by move=> i; rewrite (eqmx_stable _ (genmxE _)). apply/diagonalizable_forPex/'forall_diagonalizable_forPex => /= [[D /(simmxPp aVA) +] i|/(_ _)/sigW DoA]. rewrite mxcol_mul -[D]submxrowK diag_mxrow mul_mxdiag_mxcol. move=> /eq_mxcolP/(_ i); set D0 := (submxrow _ _) => VMeq. by exists D0; apply/simmxW. exists (\mxrow_i tag (DoA i)); apply/simmxW. rewrite -row_leq_rank eqmx_col (mxdirectP Vd)/=. by under [leqRHS]eq_bigr do rewrite genmxE (eqP (rAV _)). rewrite mxcol_mul diag_mxrow mul_mxdiag_mxcol; apply: eq_mxcol => i. by case: DoA => /= k /(simmxPp); rewrite VA => /(_ isT) ->. Qed. Section Diag. Variable (F : fieldType). Lemma codiagonalizable1 n (A : 'M[F]_n) : codiagonalizable [:: A] <-> diagonalizable A. Proof. by split=> -[P Punit PA]; exists P; move: PA; rewrite //= andbT. Qed. Definition codiagonalizablePfull n (As : seq 'M[F]_n) : codiagonalizable As <-> exists m, exists2 P : 'M_(m, n), row_full P & all [pred A | diagonalizable_for P A] As. Proof. split => [[P Punit SPA]|[m [P Pfull SPA]]]. by exists n => //; exists P; rewrite ?row_full_unit. have Qfull := fullrowsub_unit Pfull. exists (rowsub (fullrankfun Pfull) P) => //; apply/allP => A AAs/=. have /allP /(_ _ AAs)/= /diagonalizable_forPex[d /simmxPp] := SPA. rewrite submx_full// => /(_ isT) PA_eq. apply/diagonalizable_forPex; exists (colsub (fullrankfun Pfull) d). apply/simmxP => //; apply/row_matrixP => i. rewrite !row_mul row_diag_mx -scalemxAl -rowE !row_rowsub !mxE. have /(congr1 (row (fullrankfun Pfull i))) := PA_eq. by rewrite !row_mul row_diag_mx -scalemxAl -rowE => ->. Qed. Lemma codiagonalizable_on m n (V_ : 'I_n -> 'M[F]_m) (As : seq 'M[F]_m) : (\sum_i V_ i :=: 1%:M)%MS -> mxdirect (\sum_i V_ i) -> (forall i, all (fun A => stablemx (V_ i) A) As) -> (forall i, codiagonalizable (map (restrictmx (V_ i)) As)) -> codiagonalizable As. Proof. move=> V1 Vdirect /(_ _)/allP AV /(_ _) /sig2W/= Pof. pose P_ i := tag (Pof i). have P_unit i : P_ i \in unitmx by rewrite /P_; case: {+}Pof. have P_diag i A : A \in As -> diagonalizable_for (P_ i *m row_base (V_ i)) A. move=> AAs; rewrite /P_; case: {+}Pof => /= P Punit. rewrite all_map => /allP/(_ A AAs); rewrite /= !/(diagonalizable_for _ _). by rewrite conjuMmx ?row_base_free ?stablemx_row_base ?AV. pose P := \mxcol_i (P_ i *m row_base (V_ i)). have P_full i : row_full (P_ i) by rewrite row_full_unit. have PrV i : (P_ i *m row_base (V_ i) :=: V_ i)%MS. exact/(eqmx_trans _ (eq_row_base _))/eqmxMfull. apply/codiagonalizablePfull; eexists _; last exists P; rewrite /=. - rewrite -sub1mx eqmx_col. by under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. apply/allP => A AAs /=; rewrite diagonalizable_for_sum. - by apply/forallP => i; apply: P_diag. - rewrite mxdirectE/=. under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. by under eq_bigr do rewrite genmxE PrV; rewrite -(mxdirectP Vdirect)//= V1. - by move=> i; rewrite (eqmx_stable _ (PrV _)) ?AV. - by move=> i; rewrite /row_free eqmxMfull ?eq_row_base ?row_full_unit. Qed. Lemma diagonalizable_diag {n} (d : 'rV[F]_n) : diagonalizable (diag_mx d). Proof. exists 1%:M; rewrite ?unitmx1// /(diagonalizable_for _ _). by rewrite conj1mx diag_mx_is_diag. Qed. Hint Resolve diagonalizable_diag : core. Lemma diagonalizable_scalar {n} (a : F) : diagonalizable (a%:M : 'M_n). Proof. by rewrite -diag_const_mx. Qed. Hint Resolve diagonalizable_scalar : core. Lemma diagonalizable0 {n} : diagonalizable (0 : 'M[F]_n). Proof. by rewrite (_ : 0 = 0%:M)//; apply/matrixP => i j; rewrite !mxE// mul0rn. Qed. Hint Resolve diagonalizable0 : core. Lemma diagonalizablePeigen {n} {A : 'M[F]_n} : diagonalizable A <-> exists2 rs, uniq rs & (\sum_(r <- rs) eigenspace A r :=: 1%:M)%MS. Proof. split=> [df|[rs urs rsP]]. suff [rs rsP] : exists rs, (\sum_(r <- rs) eigenspace A r :=: 1%:M)%MS. exists (undup rs); rewrite ?undup_uniq//; apply: eqmx_trans rsP. elim: rs => //= r rs IHrs; rewrite big_cons. case: ifPn => in_rs; rewrite ?big_cons; last exact: adds_eqmx. apply/(eqmx_trans IHrs)/eqmx_sym/addsmx_idPr. have rrs : (index r rs < size rs)%N by rewrite index_mem. rewrite (big_nth 0) big_mkord (sumsmx_sup (Ordinal rrs)) ?nth_index//. move: df => [P Punit /(diagonalizable_forLR Punit)[d ->]]. exists [seq d 0 i | i <- enum 'I_n]; rewrite big_image/=. apply: (@eqmx_trans _ _ _ _ _ _ P); apply/eqmxP; rewrite ?sub1mx ?submx1 ?row_full_unit//. rewrite submx_full ?row_full_unit//=. apply/row_subP => i; rewrite rowE (sumsmx_sup i)//. apply/eigenspaceP; rewrite conjVmx// !mulmxA mulmxK//. by rewrite -rowE row_diag_mx scalemxAl. have mxdirect_eigenspaces : mxdirect (\sum_(i < size rs) eigenspace A rs`_i). apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. rewrite (big_nth 0) big_mkord in rsP; apply/codiagonalizable1. apply/(codiagonalizable_on _ mxdirect_eigenspaces) => // i/=. case: n => [|n] in A {mxdirect_eigenspaces} rsP *. by rewrite thinmx0 sub0mx. by rewrite comm_mx_stable_eigenspace. apply/codiagonalizable1. rewrite (@conjmx_eigenvalue _ _ _ rs`_i); first exact: diagonalizable_scalar. by rewrite eq_row_base. by rewrite row_base_free. Qed. Lemma diagonalizableP n' (n := n'.+1) (A : 'M[F]_n) : diagonalizable A <-> exists2 rs, uniq rs & mxminpoly A %| \prod_(x <- rs) ('X - x%:P). Proof. split=> [[P Punit /diagonalizable_forPex[d /(simmxLR Punit)->]]|]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by eexists; [|by []]; rewrite undup_uniq. move=> + /ltac:(apply/diagonalizablePeigen) => -[rs rsu rsP]; exists rs => //. rewrite (big_nth 0) [X in (X :=: _)%MS](big_nth 0) !big_mkord in rsP *. rewrite (eq_bigr _ (fun _ _ => eigenspace_poly _ _)). apply: (eqmx_trans (eqmx_sym (kermxpoly_prod _ _)) (kermxpoly_min _)) => //. by move=> i j _ _; rewrite coprimep_XsubC root_XsubC nth_uniq. Qed. Lemma diagonalizable_conj_diag m n (V : 'M[F]_(m, n)) (d : 'rV[F]_n) : stablemx V (diag_mx d) -> row_free V -> diagonalizable (conjmx V (diag_mx d)). Proof. case: m n => [|m] [|n] in V d * => Vd rdV; rewrite ?thinmx0. - by []. - by []. - by exfalso; move: rdV; rewrite /row_free mxrank.unlock eqxx orbT. apply/diagonalizableP; pose u := undup [seq d 0 i | i <- enum 'I_n.+1]. exists u; first by rewrite undup_uniq. by rewrite (dvdp_trans (mxminpoly_conj (f:=diag_mx d) _ _))// mxminpoly_diag. Qed. Lemma codiagonalizableP n (As : seq 'M[F]_n) : {in As &, forall A B, comm_mx A B} /\ {in As, forall A, diagonalizable A} <-> codiagonalizable As. Proof. split => [cdAs|[P Punit /allP/= AsD]]/=; last first. split; last by exists P; rewrite // AsD. move=> A B AAs BAs; move=> /(_ _ _)/diagonalizable_forPex/sigW in AsD. have [[dA /simmxLR->//] [dB /simmxLR->//]] := (AsD _ AAs, AsD _ BAs). by rewrite /comm_mx -!conjmxM 1?diag_mxC// inE stablemx_unit ?unitmx_inv. move: cdAs => -[]; move/(rwP (all_comm_mxP _)) => cdAs cdAs'. have [k] := ubnP (size As); elim: k => [|k IHk]//= in n As cdAs cdAs' *. case: As cdAs cdAs' => [|A As]//=; first by exists 1%:M; rewrite ?unitmx1. rewrite ltnS all_comm_mx_cons => /andP[/allP/(_ _ _)/eqP AAsC AsC dAAs] Ask. have /diagonalizablePeigen [rs urs rs1] := dAAs _ (mem_head _ _). rewrite (big_nth 0) big_mkord in rs1. have eAB (i : 'I_(size rs)) B : B \in A :: As -> stablemx (eigenspace A rs`_i) B. case: n => [|n'] in B A As AAsC AsC {dAAs rs1 Ask} * => B_AAs. by rewrite thinmx0 sub0mx. rewrite comm_mx_stable_eigenspace//. by move: B_AAs; rewrite !inE => /predU1P [->//|/AAsC]. apply/(@codiagonalizable_on _ _ _ (_ :: _) rs1) => [|i|i /=]. - apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. - by apply/allP => B B_AAs; rewrite eAB. rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free//. set Bs := map _ _; suff [P Punit /= PBs] : codiagonalizable Bs. exists P; rewrite /= ?PBs ?andbT// /(diagonalizable_for _ _). by rewrite conjmx_scalar ?mx_scalar_is_diag// row_free_unit. apply: IHk; rewrite ?size_map/= ?ltnS//. apply/all_comm_mxP => _ _ /mapP[/= B BAs ->] /mapP[/= h hAs ->]. rewrite -!conjmxM ?inE ?stablemx_row_base ?eAB ?inE ?BAs ?hAs ?orbT//. by rewrite (all_comm_mxP _ AsC). move=> _ /mapP[/= B BAs ->]. have: stablemx (row_base (eigenspace A rs`_i)) B. by rewrite stablemx_row_base eAB// inE BAs orbT. have := dAAs B; rewrite inE BAs orbT => /(_ isT) [P Punit]. move=> /diagonalizable_forPex[D /(simmxLR Punit)->] sePD. have rAeP : row_free (row_base (eigenspace A rs`_i) *m invmx P). by rewrite /row_free mxrankMfree ?row_free_unit ?unitmx_inv// eq_row_base. rewrite -conjMumx ?unitmx_inv ?row_base_free => [|//|//|//]. apply/diagonalizable_conj_diag => //. by rewrite stablemx_comp// stablemx_unit ?unitmx_inv. Qed. End Diag.
Stopping.lean
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memLp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped process belongs to `ℒp` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable with respect to `f i`. Intuitively, the stopping time `τ` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → ι) := ∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i} theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] section MeasurableSet section Preorder variable [Preorder ι] {f : Filtration ι m} {τ : Ω → ι} protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω ≤ i} := hτ i theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (τ ω) have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i) end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ι] {τ : Ω → ι} {f : Filtration ι m} protected theorem measurableSet_eq_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} \ ⋃ (j ∈ Set.range τ) (_ : j < i), {ω | τ ω ≤ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and] constructor <;> intro h · simp only [h, lt_iff_le_not_ge, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] · exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hτ.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ classical rw [Set.iUnion_eq_if] split_ifs with hji · exact f.mono hji.le _ (hτ.measurableSet_le j) · exact @MeasurableSet.empty _ (f i) protected theorem measurableSet_eq_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω; simp [lt_iff_le_and_ne] rw [this] exact (hτ.measurableSet_le i).diff (hτ.measurableSet_eq_of_countable_range h_countable i) protected theorem measurableSet_lt_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt_of_countable_range h_countable i).compl protected theorem measurableSet_ge_of_countable {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range (Set.to_countable _) i end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} theorem IsStoppingTime.measurableSet_gt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i < τ ω} := by have : {ω | i < τ ω} = {ω | τ ω ≤ i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hτ.measurableSet_le i).compl section TopologicalSpace variable [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hτ : IsStoppingTime f τ) (i : ι) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] exact isMin_iff_forall_not_lt.mp hi_min (τ ω) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : ∃ seq : ℕ → ι, Monotone seq ∧ (∀ j, seq j ≤ i) ∧ Tendsto seq atTop (𝓝 i) ∧ ∀ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≤ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ · rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : ∃ a : ℕ, ∀ b : ℕ, b ≥ a → k ≤ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ · obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {ω | τ ω < i} = τ ⁻¹' Set.Iio i := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hτ.measurableSet_le (seq n)) theorem IsStoppingTime.measurableSet_lt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by obtain ⟨i', hi'_lub⟩ : ∃ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i rcases lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i | h_Iio_eq_Iic · rw [← hi'_eq_i] at hi'_lub ⊢ exact hτ.measurableSet_lt_of_isLUB i' hi'_lub · have h_lt_eq_preimage : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hτ.measurableSet_le i') theorem IsStoppingTime.measurableSet_ge (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt i).compl theorem IsStoppingTime.measurableSet_eq (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} ∩ {ω | τ ω ≥ i} := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i) theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω = i} := f.mono hle _ <| hτ.measurableSet_eq i theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω < i} := f.mono hle _ <| hτ.measurableSet_lt i end TopologicalSpace end LinearOrder section Countable theorem isStoppingTime_of_measurableSet_eq [Preorder ι] [Countable ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : ∀ i, MeasurableSet[f i] {ω | τ ω = i}) : IsStoppingTime f τ := by intro i rw [show {ω | τ ω ≤ i} = ⋃ k ≤ i, {ω | τ ω = k} by ext; simp] refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_ exact f.mono hk _ (hτ k) end Countable end MeasurableSet namespace IsStoppingTime protected theorem max [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => max (τ ω) (π ω) := by intro i simp_rw [max_le_iff, Set.setOf_and] exact (hτ i).inter (hπ i) protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i := hτ.max (isStoppingTime_const f i) protected theorem min [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => min (τ ω) (π ω) := by intro i simp_rw [min_le_iff, Set.setOf_or] exact (hτ i).union (hπ i) protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i := hτ.min (isStoppingTime_const f i) theorem add_const [AddGroup ι] [Preorder ι] [AddRightMono ι] [AddLeftMono ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {i : ι} (hi : 0 ≤ i) : IsStoppingTime f fun ω => τ ω + i := by intro j simp_rw [← le_sub_iff_add_le] exact f.mono (sub_le_self j hi) _ (hτ (j - i)) theorem add_const_nat {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) {i : ℕ} : IsStoppingTime f fun ω => τ ω + i := by refine isStoppingTime_of_measurableSet_eq fun j => ?_ by_cases hij : i ≤ j · simp_rw [eq_comm, ← Nat.sub_eq_iff_eq_add hij, eq_comm] exact f.mono (j.sub_le i) _ (hτ.measurableSet_eq (j - i)) · rw [not_le] at hij convert @MeasurableSet.empty _ (f.1 j) ext ω simp only [Set.mem_empty_iff_false, iff_false, Set.mem_setOf] omega -- generalize to certain countable type? theorem add {f : Filtration ℕ m} {τ π : Ω → ℕ} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f (τ + π) := by intro i rw [(_ : {ω | (τ + π) ω ≤ i} = ⋃ k ≤ i, {ω | π ω = k} ∩ {ω | τ ω + k ≤ i})] · exact MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun hk => (hπ.measurableSet_eq_le hk).inter (hτ.add_const_nat i) ext ω simp only [Pi.add_apply, Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_prop] refine ⟨fun h => ⟨π ω, by omega, rfl, h⟩, ?_⟩ rintro ⟨j, hj, rfl, h⟩ assumption section Preorder variable [Preorder ι] {f : Filtration ι m} {τ π : Ω → ι} /-- The associated σ-algebra with a stopping time. -/ protected def measurableSpace (hτ : IsStoppingTime f τ) : MeasurableSpace Ω where MeasurableSet' s := ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) measurableSet_empty i := (Set.empty_inter {ω | τ ω ≤ i}).symm ▸ @MeasurableSet.empty _ (f i) measurableSet_compl s hs i := by rw [(_ : sᶜ ∩ {ω | τ ω ≤ i} = (sᶜ ∪ {ω | τ ω ≤ i}ᶜ) ∩ {ω | τ ω ≤ i})] · refine MeasurableSet.inter ?_ ?_ · rw [← Set.compl_inter] exact (hs i).compl · exact hτ i · rw [Set.union_inter_distrib_right] simp only [Set.compl_inter_self, Set.union_empty] measurableSet_iUnion s hs i := by rw [forall_swap] at hs rw [Set.iUnion_inter] exact MeasurableSet.iUnion (hs i) protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] s ↔ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) := Iff.rfl theorem measurableSpace_mono (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (hle : τ ≤ π) : hτ.measurableSpace ≤ hπ.measurableSpace := by intro s hs i rw [(_ : s ∩ {ω | π ω ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | π ω ≤ i})] · exact (hs i).inter (hπ i) · ext simp only [Set.mem_inter_iff, iff_self_and, and_congr_left_iff, Set.mem_setOf_eq] intro hle' _ exact le_trans (hle _) hle' theorem measurableSpace_le_of_countable [Countable ι] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.iUnion fun i => f.le i _ (hs i) · ext ω; constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, hx, le_rfl⟩ · rintro ⟨_, hx, _⟩ exact hx theorem measurableSpace_le [IsCountablyGenerated (atTop : Filter ι)] [IsDirected ι (· ≤ ·)] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs cases isEmpty_or_nonempty ι · haveI : IsEmpty Ω := ⟨fun ω => IsEmpty.false (τ ω)⟩ apply Subsingleton.measurableSet · change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs obtain ⟨seq : ℕ → ι, h_seq_tendsto⟩ := (atTop : Filter ι).exists_seq_tendsto rw [(_ : s = ⋃ n, s ∩ {ω | τ ω ≤ seq n})] · exact MeasurableSet.iUnion fun i => f.le (seq i) _ (hs (seq i)) · ext ω; constructor <;> rw [Set.mem_iUnion] · intro hx suffices ∃ i, τ ω ≤ seq i from ⟨this.choose, hx, this.choose_spec⟩ rw [tendsto_atTop] at h_seq_tendsto exact (h_seq_tendsto (τ ω)).exists · rintro ⟨_, hx, _⟩ exact hx example {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le example {f : Filtration ℝ m} {τ : Ω → ℝ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le @[simp] theorem measurableSpace_const (f : Filtration ι m) (i : ι) : (isStoppingTime_const f i).measurableSpace = f i := by ext1 s change MeasurableSet[(isStoppingTime_const f i).measurableSpace] s ↔ MeasurableSet[f i] s rw [IsStoppingTime.measurableSet] constructor <;> intro h · specialize h i simpa only [le_refl, Set.setOf_true, Set.inter_univ] using h · intro j by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp only [hij, Set.setOf_false, Set.inter_empty, @MeasurableSet.empty _ (f.1 j)] theorem measurableSet_inter_eq_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω = i}) ↔ MeasurableSet[f i] (s ∩ {ω | τ ω = i}) := by have : ∀ j, {ω : Ω | τ ω = i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω = i} ∩ {_ω | i ≤ j} := by intro j ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] intro hxi rw [hxi] constructor <;> intro h · specialize h i simpa only [Set.inter_assoc, this, le_refl, Set.setOf_true, Set.inter_univ] using h · intro j rw [Set.inter_assoc, this] by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp [hij] theorem measurableSpace_le_of_le_const (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : hτ.measurableSpace ≤ f i := (measurableSpace_mono hτ _ hτ_le).trans (measurableSpace_const _ _).le theorem measurableSpace_le_of_le (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : hτ.measurableSpace ≤ m := (hτ.measurableSpace_le_of_le_const hτ_le).trans (f.le n) theorem le_measurableSpace_of_const_le (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, i ≤ τ ω) : f i ≤ hτ.measurableSpace := (measurableSpace_const _ _).symm.le.trans (measurableSpace_mono _ hτ hτ_le) end Preorder instance sigmaFinite_stopping_time {ι} [SemilatticeSup ι] [OrderBot ι] [(Filter.atTop : Filter ι).IsCountablyGenerated] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) : SigmaFinite (μ.trim hτ.measurableSpace_le) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance instance sigmaFinite_stopping_time_of_le {ι} [SemilatticeSup ι] [OrderBot ι] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} protected theorem measurableSet_le' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ i} := by intro j have : {ω : Ω | τ ω ≤ i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω ≤ min i j} := by ext1 ω; simp only [Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff] rw [this] exact f.mono (min_le_right i j) _ (hτ _) protected theorem measurableSet_gt' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i < τ ω} := by have : {ω : Ω | i < τ ω} = {ω : Ω | τ ω ≤ i}ᶜ := by ext1 ω; simp rw [this] exact (hτ.measurableSet_le' i).compl protected theorem measurableSet_eq' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq i protected theorem measurableSet_ge' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq' i).union (hτ.measurableSet_gt' i) protected theorem measurableSet_lt' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq' i) section Countable protected theorem measurableSet_eq_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq_of_countable_range h_countable i protected theorem measurableSet_eq_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range' (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq_of_countable_range' h_countable i).union (hτ.measurableSet_gt' i) protected theorem measurableSet_ge_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range' (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq_of_countable_range' h_countable i) protected theorem measurableSet_lt_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range' (Set.to_countable _) i protected theorem measurableSpace_le_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i ∈ Set.range τ, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.biUnion h_countable fun i _ => f.le i _ (hs i) · ext ω constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, by simpa using hx⟩ · rintro ⟨i, hx⟩ simp only [Set.mem_range, Set.iUnion_exists, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, exists_and_right] at hx exact hx.2.1 end Countable protected theorem measurable [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] τ := @measurable_of_Iic ι Ω _ _ _ hτ.measurableSpace _ _ _ _ fun i => hτ.measurableSet_le' i protected theorem measurable_of_le [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : Measurable[f i] τ := hτ.measurable.mono (measurableSpace_le_of_le_const _ hτ_le) le_rfl theorem measurableSpace_min (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : (hτ.min hπ).measurableSpace = hτ.measurableSpace ⊓ hπ.measurableSpace := by refine le_antisymm ?_ ?_ · exact le_inf (measurableSpace_mono _ hτ fun _ => min_le_left _ _) (measurableSpace_mono _ hπ fun _ => min_le_right _ _) · intro s change MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s → MeasurableSet[(hτ.min hπ).measurableSpace] s simp_rw [IsStoppingTime.measurableSet] have : ∀ i, {ω | min (τ ω) (π ω) ≤ i} = {ω | τ ω ≤ i} ∪ {ω | π ω ≤ i} := by intro i; ext1 ω; simp simp_rw [this, Set.inter_union_distrib_left] exact fun h i => (h.left i).union (h.right i) theorem measurableSet_min_iff (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[(hτ.min hπ).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s := by rw [measurableSpace_min hτ hπ]; rfl theorem measurableSpace_min_const (hτ : IsStoppingTime f τ) {i : ι} : (hτ.min_const i).measurableSpace = hτ.measurableSpace ⊓ f i := by rw [hτ.measurableSpace_min (isStoppingTime_const _ i), measurableSpace_const] theorem measurableSet_min_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) {i : ι} : MeasurableSet[(hτ.min_const i).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[f i] s := by rw [measurableSpace_min_const hτ]; apply MeasurableSpace.measurableSet_inf theorem measurableSet_inter_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) (hs : MeasurableSet[hτ.measurableSpace] s) : MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by simp_rw [IsStoppingTime.measurableSet] at hs ⊢ intro i have : s ∩ {ω | τ ω ≤ π ω} ∩ {ω | min (τ ω) (π ω) ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | min (τ ω) (π ω) ≤ i} ∩ {ω | min (τ ω) i ≤ min (min (τ ω) (π ω)) i} := by ext1 ω simp only [min_le_iff, Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff, le_refl, true_and, true_or] by_cases hτi : τ ω ≤ i · simp only [hτi, true_or, and_true, and_congr_right_iff] intro constructor <;> intro h · exact Or.inl h · rcases h with h | h · exact h · exact hτi.trans h simp only [hτi, false_or, and_false, false_and, iff_false, not_and, not_le, and_imp] refine fun _ hτ_le_π => lt_of_lt_of_le ?_ hτ_le_π rw [← not_le] exact hτi rw [this] refine ((hs i).inter ((hτ.min hπ) i)).inter ?_ apply @measurableSet_le _ _ _ _ _ (Filtration.seq f i) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const i).measurable_of_le fun _ => min_le_right _ _ · exact ((hτ.min hπ).min_const i).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_inter_le_iff [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) ↔ MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by constructor <;> intro h · have : s ∩ {ω | τ ω ≤ π ω} = s ∩ {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ π ω} := by rw [Set.inter_assoc, Set.inter_self] rw [this] exact measurableSet_inter_le _ hπ _ h · rw [measurableSet_min_iff hτ hπ] at h exact h.1 theorem measurableSet_inter_le_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ i}) ↔ MeasurableSet[(hτ.min_const i).measurableSpace] (s ∩ {ω | τ ω ≤ i}) := by rw [IsStoppingTime.measurableSet_min_iff hτ (isStoppingTime_const _ i), IsStoppingTime.measurableSpace_const, IsStoppingTime.measurableSet] refine ⟨fun h => ⟨h, ?_⟩, fun h j => h.1 j⟩ specialize h i rwa [Set.inter_assoc, Set.inter_self] at h theorem measurableSet_le_stopping_time [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j ≤ min (π ω) j} ∩ {ω | τ ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, min_le_iff, le_min_iff, le_refl, and_congr_left_iff] intro h simp only [h, or_self_iff, and_true] rw [Iff.comm, or_iff_left_iff_imp] exact h.trans rw [this] refine MeasurableSet.inter ?_ (hτ.measurableSet_le j) apply @measurableSet_le _ _ _ _ _ (Filtration.seq f j) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_stopping_time_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hπ.measurableSpace] {ω | τ ω ≤ π ω} := by suffices MeasurableSet[(hτ.min hπ).measurableSpace] {ω : Ω | τ ω ≤ π ω} by rw [measurableSet_min_iff hτ hπ] at this; exact this.2 rw [← Set.univ_inter {ω : Ω | τ ω ≤ π ω}, ← hτ.measurableSet_inter_le_iff hπ, Set.univ_inter] exact measurableSet_le_stopping_time hτ hπ theorem measurableSet_eq_stopping_time [AddGroup ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] [MeasurableSub₂ ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · obtain ⟨h', hσ_le⟩ := h obtain ⟨h_eq, hτ_le⟩ := h' rwa [min_eq_left hτ_le, min_eq_left hσ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ theorem measurableSet_eq_stopping_time_of_countable [Countable ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · obtain ⟨h', hπ_le⟩ := h obtain ⟨h_eq, hτ_le⟩ := h' rwa [min_eq_left hτ_le, min_eq_left hπ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun_of_countable · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ end LinearOrder end IsStoppingTime section LinearOrder /-! ## Stopped value and stopped process -/ /-- Given a map `u : ι → Ω → E`, its stopped value with respect to the stopping time `τ` is the map `x ↦ u (τ ω) ω`. -/ def stoppedValue (u : ι → Ω → β) (τ : Ω → ι) : Ω → β := fun ω => u (τ ω) ω theorem stoppedValue_const (u : ι → Ω → β) (i : ι) : (stoppedValue u fun _ => i) = u i := rfl variable [LinearOrder ι] /-- Given a map `u : ι → Ω → E`, the stopped process with respect to `τ` is `u i ω` if `i ≤ τ ω`, and `u (τ ω) ω` otherwise. Intuitively, the stopped process stops evolving once the stopping time has occurred. -/ def stoppedProcess (u : ι → Ω → β) (τ : Ω → ι) : ι → Ω → β := fun i ω => u (min i (τ ω)) ω theorem stoppedProcess_eq_stoppedValue {u : ι → Ω → β} {τ : Ω → ι} : stoppedProcess u τ = fun i => stoppedValue u fun ω => min i (τ ω) := rfl theorem stoppedValue_stoppedProcess {u : ι → Ω → β} {τ σ : Ω → ι} : stoppedValue (stoppedProcess u τ) σ = stoppedValue u fun ω => min (σ ω) (τ ω) := rfl theorem stoppedProcess_eq_of_le {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : i ≤ τ ω) : stoppedProcess u τ i ω = u i ω := by simp [stoppedProcess, min_eq_left h] theorem stoppedProcess_eq_of_ge {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : τ ω ≤ i) : stoppedProcess u τ i ω = u (τ ω) ω := by simp [stoppedProcess, min_eq_right h] section ProgMeasurable variable [MeasurableSpace ι] [TopologicalSpace ι] [OrderTopology ι] [SecondCountableTopology ι] [BorelSpace ι] [TopologicalSpace β] {u : ι → Ω → β} {τ : Ω → ι} {f : Filtration ι m} theorem progMeasurable_min_stopping_time [PseudoMetrizableSpace ι] (hτ : IsStoppingTime f τ) : ProgMeasurable f fun i ω => min i (τ ω) := by intro i let m_prod : MeasurableSpace (Set.Iic i × Ω) := Subtype.instMeasurableSpace.prod (f i) let m_set : ∀ t : Set (Set.Iic i × Ω), MeasurableSpace t := fun _ => @Subtype.instMeasurableSpace (Set.Iic i × Ω) _ m_prod let s := {p : Set.Iic i × Ω | τ p.2 ≤ i} have hs : MeasurableSet[m_prod] s := @measurable_snd (Set.Iic i) Ω _ (f i) _ (hτ i) have h_meas_fst : ∀ t : Set (Set.Iic i × Ω), Measurable[m_set t] fun x : t => ((x : Set.Iic i × Ω).fst : ι) := fun t => (@measurable_subtype_coe (Set.Iic i × Ω) m_prod _).fst.subtype_val apply Measurable.stronglyMeasurable refine measurable_of_restrict_of_restrict_compl hs ?_ ?_ · refine @Measurable.min _ _ _ _ _ (m_set s) _ _ _ _ _ (h_meas_fst s) ?_ refine @measurable_of_Iic ι s _ _ _ (m_set s) _ _ _ _ fun j => ?_ have h_set_eq : (fun x : s => τ (x : Set.Iic i × Ω).snd) ⁻¹' Set.Iic j = (fun x : s => (x : Set.Iic i × Ω).snd) ⁻¹' {ω | τ ω ≤ min i j} := by ext1 ω simp only [Set.mem_preimage, Set.mem_Iic, iff_and_self, le_min_iff, Set.mem_setOf_eq] exact fun _ => ω.prop rw [h_set_eq] suffices h_meas : @Measurable _ _ (m_set s) (f i) fun x : s ↦ (x : Set.Iic i × Ω).snd from h_meas (f.mono (min_le_left _ _) _ (hτ.measurableSet_le (min i j))) exact measurable_snd.comp (@measurable_subtype_coe _ m_prod _) · letI sc := sᶜ suffices h_min_eq_left : (fun x : sc => min (↑(x : Set.Iic i × Ω).fst) (τ (x : Set.Iic i × Ω).snd)) = fun x : sc => ↑(x : Set.Iic i × Ω).fst by simp +unfoldPartialApp only [sc, Set.restrict, h_min_eq_left] exact h_meas_fst _ ext1 ω rw [min_eq_left] have hx_fst_le : ↑(ω : Set.Iic i × Ω).fst ≤ i := (ω : Set.Iic i × Ω).fst.prop refine hx_fst_le.trans (le_of_lt ?_) convert ω.prop simp only [sc, s, not_le, Set.mem_compl_iff, Set.mem_setOf_eq] theorem ProgMeasurable.stoppedProcess [PseudoMetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : ProgMeasurable f (stoppedProcess u τ) := h.comp (progMeasurable_min_stopping_time hτ) fun _ _ => min_le_left _ _ theorem ProgMeasurable.adapted_stoppedProcess [PseudoMetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (h.stoppedProcess hτ).adapted theorem ProgMeasurable.stronglyMeasurable_stoppedProcess [PseudoMetrizableSpace ι] (hu : ProgMeasurable f u) (hτ : IsStoppingTime f τ) (i : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ i) := (hu.adapted_stoppedProcess hτ i).mono (f.le _) theorem stronglyMeasurable_stoppedValue_of_le (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : StronglyMeasurable[f n] (stoppedValue u τ) := by have : stoppedValue u τ = (fun p : Set.Iic n × Ω => u (↑p.fst) p.snd) ∘ fun ω => (⟨τ ω, hτ_le ω⟩, ω) := by ext1 ω; simp only [stoppedValue, Function.comp_apply] rw [this] refine StronglyMeasurable.comp_measurable (h n) ?_ exact (hτ.measurable_of_le hτ_le).subtype_mk.prodMk measurable_id theorem measurable_stoppedValue [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf_prog : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] (stoppedValue u τ) := by have h_str_meas : ∀ i, StronglyMeasurable[f i] (stoppedValue u fun ω => min (τ ω) i) := fun i => stronglyMeasurable_stoppedValue_of_le hf_prog (hτ.min_const i) fun _ => min_le_right _ _ intro t ht i suffices stoppedValue u τ ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} = (stoppedValue u fun ω => min (τ ω) i) ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} by rw [this]; exact ((h_str_meas i).measurable ht).inter (hτ.measurableSet_le i) ext1 ω simp only [stoppedValue, Set.mem_inter_iff, Set.mem_preimage, Set.mem_setOf_eq, and_congr_left_iff] intro h rw [min_eq_left h] end ProgMeasurable end LinearOrder section StoppedValueOfMemFinset variable {μ : Measure Ω} {τ : Ω → ι} {E : Type*} {p : ℝ≥0∞} {u : ι → Ω → E} theorem stoppedValue_eq_of_mem_finset [AddCommMonoid E] {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : stoppedValue u τ = ∑ i ∈ s, Set.indicator {ω | τ ω = i} (u i) := by ext y classical rw [stoppedValue, Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] suffices {i ∈ s | y ∈ {ω : Ω | τ ω = i}} = ({τ y} : Finset ι) by rw [this, Finset.sum_singleton] ext1 ω simp only [Set.mem_setOf_eq, Finset.mem_filter, Finset.mem_singleton] constructor <;> intro h · exact h.2.symm · refine ⟨?_, h.symm⟩; rw [h]; exact hbdd y theorem stoppedValue_eq' [Preorder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = ∑ i ∈ Finset.Iic N, Set.indicator {ω | τ ω = i} (u i) := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_Iic.mpr (hbdd ω) theorem stoppedProcess_eq_of_mem_finset [LinearOrder ι] [AddCommMonoid E] {s : Finset ι} (n : ι) (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ s with i < n, Set.indicator {ω | τ ω = i} (u i) := by ext ω rw [Pi.add_apply, Finset.sum_apply] rcases le_or_gt n (τ ω) with h | h · rw [stoppedProcess_eq_of_le h, Set.indicator_of_mem, Finset.sum_eq_zero, add_zero] · intro m hm refine Set.indicator_of_notMem ?_ _ rw [Finset.mem_filter] at hm exact (hm.2.trans_le h).ne' · exact h · rw [stoppedProcess_eq_of_ge (le_of_lt h), Finset.sum_eq_single_of_mem (τ ω)] · rw [Set.indicator_of_notMem, zero_add, Set.indicator_of_mem] <;> rw [Set.mem_setOf] exact not_le.2 h · rw [Finset.mem_filter] exact ⟨hbdd ω h, h⟩ · intro b _ hneq rw [Set.indicator_of_notMem] rw [Set.mem_setOf] exact hneq.symm theorem stoppedProcess_eq'' [LinearOrder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] (n : ι) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.Iio n, Set.indicator {ω | τ ω = i} (u i) := by have h_mem : ∀ ω, τ ω < n → τ ω ∈ Finset.Iio n := fun ω h => Finset.mem_Iio.mpr h rw [stoppedProcess_eq_of_mem_finset n h_mem] congr with i simp section StoppedValue variable [PartialOrder ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memLp_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : MemLp (stoppedValue u τ) p μ := by rw [stoppedValue_eq_of_mem_finset hbdd] refine memLp_finset_sum' _ fun i _ => MemLp.indicator ?_ (hu i) refine ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq_of_countable_range ?_ i) refine ((Finset.finite_toSet s).subset fun ω hω => ?_).countable obtain ⟨y, rfl⟩ := hω exact hbdd y theorem memLp_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : MemLp (stoppedValue u τ) p μ := memLp_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) theorem integrable_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : Integrable (stoppedValue u τ) μ := by simp_rw [← memLp_one_iff_integrable] at hu ⊢ exact memLp_stoppedValue_of_mem_finset hτ hu hbdd variable (ι) theorem integrable_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : Integrable (stoppedValue u τ) μ := integrable_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) end StoppedValue section StoppedProcess variable [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memLp_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : MemLp (stoppedProcess u τ n) p μ := by rw [stoppedProcess_eq_of_mem_finset n hbdd] refine MemLp.add ?_ ?_ · exact MemLp.indicator (ℱ.le n {a : Ω | n ≤ τ a} (hτ.measurableSet_ge n)) (hu n) · suffices MemLp (fun ω => ∑ i ∈ s with i < n, {a : Ω | τ a = i}.indicator (u i) ω) p μ by convert this using 1; ext1 ω; simp only [Finset.sum_apply] refine memLp_finset_sum _ fun i _ => MemLp.indicator ?_ (hu i) exact ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq i) theorem memLp_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, MemLp (u n) p μ) (n : ι) : MemLp (stoppedProcess u τ n) p μ := memLp_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h theorem integrable_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : Integrable (stoppedProcess u τ n) μ := by simp_rw [← memLp_one_iff_integrable] at hu ⊢ exact memLp_stoppedProcess_of_mem_finset hτ hu n hbdd theorem integrable_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) : Integrable (stoppedProcess u τ n) μ := integrable_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h end StoppedProcess end StoppedValueOfMemFinset section AdaptedStoppedProcess variable [TopologicalSpace β] [PseudoMetrizableSpace β] [LinearOrder ι] [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] {f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → ι} /-- The stopped process of an adapted process with continuous paths is adapted. -/ theorem Adapted.stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) : Adapted f (stoppedProcess u τ) := ((hu.progMeasurable_of_continuous hu_cont).stoppedProcess hτ).adapted /-- If the indexing order has the discrete topology, then the stopped process of an adapted process is adapted. -/ theorem Adapted.stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (hu.progMeasurable_of_discrete.stoppedProcess hτ).adapted theorem Adapted.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := (hu.progMeasurable_of_continuous hu_cont).stronglyMeasurable_stoppedProcess hτ n theorem Adapted.stronglyMeasurable_stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := hu.progMeasurable_of_discrete.stronglyMeasurable_stoppedProcess hτ n end AdaptedStoppedProcess section Nat /-! ### Filtrations indexed by `ℕ` -/ open Filtration variable {u : ℕ → Ω → β} {τ π : Ω → ℕ} theorem stoppedValue_sub_eq_sum [AddCommGroup β] (hle : τ ≤ π) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.Ico (τ ω) (π ω), (u (i + 1) - u i)) ω := by ext ω rw [Finset.sum_Ico_eq_sub _ (hle ω), Finset.sum_range_sub, Finset.sum_range_sub] simp [stoppedValue] theorem stoppedValue_sub_eq_sum' [AddCommGroup β] (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ ω, π ω ≤ N) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω ≤ i ∧ i < π ω} (u (i + 1) - u i)) ω := by rw [stoppedValue_sub_eq_sum hle] ext ω simp only [Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] refine Finset.sum_congr ?_ fun _ _ => rfl ext i simp only [Finset.mem_filter, Set.mem_setOf_eq, Finset.mem_range, Finset.mem_Ico] exact ⟨fun h => ⟨lt_trans h.2 (Nat.lt_succ_iff.2 <| hbdd _), h⟩, fun h => h.2⟩ section AddCommMonoid variable [AddCommMonoid β] theorem stoppedValue_eq {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = fun x => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω = i} (u i)) x := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_range_succ_iff.mpr (hbdd ω) theorem stoppedProcess_eq (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.range n, Set.indicator {ω | τ ω = i} (u i) := by rw [stoppedProcess_eq'' n] congr with i rw [Finset.mem_Iio, Finset.mem_range] theorem stoppedProcess_eq' (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n + 1 ≤ τ a} (u n) + ∑ i ∈ Finset.range (n + 1), Set.indicator {a | τ a = i} (u i) := by have : {a | n ≤ τ a}.indicator (u n) = {a | n + 1 ≤ τ a}.indicator (u n) + {a | τ a = n}.indicator (u n) := by ext x rw [add_comm, Pi.add_apply, ← Set.indicator_union_of_notMem_inter] · simp_rw [@eq_comm _ _ n, @le_iff_eq_or_lt _ _ n, Nat.succ_le_iff, Set.setOf_or] · rintro ⟨h₁, h₂⟩ rw [Set.mem_setOf] at h₁ h₂ exact (Nat.succ_le_iff.1 h₂).ne h₁.symm rw [stoppedProcess_eq, this, Finset.sum_range_succ_comm, ← add_assoc] end AddCommMonoid end Nat section PiecewiseConst variable [Preorder ι] {𝒢 : Filtration ι m} {τ η : Ω → ι} {i j : ι} {s : Set Ω} [DecidablePred (· ∈ s)] /-- Given stopping times `τ` and `η` which are bounded below, `Set.piecewise s τ η` is also a stopping time with respect to the same filtration. -/ theorem IsStoppingTime.piecewise_of_le (hτ_st : IsStoppingTime 𝒢 τ) (hη_st : IsStoppingTime 𝒢 η) (hτ : ∀ ω, i ≤ τ ω) (hη : ∀ ω, i ≤ η ω) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise τ η) := by intro n have : {ω | s.piecewise τ η ω ≤ n} = s ∩ {ω | τ ω ≤ n} ∪ sᶜ ∩ {ω | η ω ≤ n} := by ext1 ω simp only [Set.piecewise, Set.mem_setOf_eq] by_cases hx : ω ∈ s <;> simp [hx] rw [this] by_cases hin : i ≤ n · have hs_n : MeasurableSet[𝒢 n] s := 𝒢.mono hin _ hs exact (hs_n.inter (hτ_st n)).union (hs_n.compl.inter (hη_st n)) · have hτn : ∀ ω, ¬τ ω ≤ n := fun ω hτn => hin ((hτ ω).trans hτn) have hηn : ∀ ω, ¬η ω ≤ n := fun ω hηn => hin ((hη ω).trans hηn) simp [hτn, hηn, @MeasurableSet.empty _ _] theorem isStoppingTime_piecewise_const (hij : i ≤ j) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise (fun _ => i) fun _ => j) := (isStoppingTime_const 𝒢 i).piecewise_of_le (isStoppingTime_const 𝒢 j) (fun _ => le_rfl) (fun _ => hij) hs theorem stoppedValue_piecewise_const {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.piecewise (f i) (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] theorem stoppedValue_piecewise_const' {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.indicator (f i) + sᶜ.indicator (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] end PiecewiseConst section Condexp /-! ### Conditional expectation with respect to the σ-algebra generated by a stopping time -/ variable [LinearOrder ι] {μ : Measure Ω} {ℱ : Filtration ι m} {τ σ : Ω → ι} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : Ω → E} theorem condExp_stopping_time_ae_eq_restrict_eq_of_countable_range [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) (h_countable : (Set.range τ).Countable) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_countable_range h_countable))] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by refine condExp_ae_eq_restrict_of_measurableSpace_eq_on (hτ.measurableSpace_le_of_countable_range h_countable) (ℱ.le i) (hτ.measurableSet_eq_of_countable_range' h_countable i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] theorem condExp_stopping_time_ae_eq_restrict_eq_of_countable [Countable ι] [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le_of_countable)] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := condExp_stopping_time_ae_eq_restrict_eq_of_countable_range hτ (Set.to_countable _) i variable [(Filter.atTop : Filter ι).IsCountablyGenerated] theorem condExp_min_stopping_time_ae_eq_restrict_le_const (hτ : IsStoppingTime ℱ τ) (i : ι) [SigmaFinite (μ.trim (hτ.min_const i).measurableSpace_le)] : μ[f|(hτ.min_const i).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ i}] μ[f|hτ.measurableSpace] := by have : SigmaFinite (μ.trim hτ.measurableSpace_le) := haveI h_le : (hτ.min_const i).measurableSpace ≤ hτ.measurableSpace := by rw [IsStoppingTime.measurableSpace_min_const] exact inf_le_left sigmaFiniteTrim_mono _ h_le refine (condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (hτ.min_const i).measurableSpace_le (hτ.measurableSet_le' i) fun t => ?_).symm rw [Set.inter_comm _ t, hτ.measurableSet_inter_le_const_iff] variable [TopologicalSpace ι] [OrderTopology ι] theorem condExp_stopping_time_ae_eq_restrict_eq [FirstCountableTopology ι] [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le)] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by refine condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (ℱ.le i) (hτ.measurableSet_eq' i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] theorem condExp_min_stopping_time_ae_eq_restrict_le [MeasurableSpace ι] [SecondCountableTopology ι] [BorelSpace ι] (hτ : IsStoppingTime ℱ τ) (hσ : IsStoppingTime ℱ σ) [SigmaFinite (μ.trim (hτ.min hσ).measurableSpace_le)] : μ[f|(hτ.min hσ).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ σ x}] μ[f|hτ.measurableSpace] := by have : SigmaFinite (μ.trim hτ.measurableSpace_le) := haveI h_le : (hτ.min hσ).measurableSpace ≤ hτ.measurableSpace := by rw [IsStoppingTime.measurableSpace_min] · exact inf_le_left · simp_all only sigmaFiniteTrim_mono _ h_le refine (condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (hτ.min hσ).measurableSpace_le (hτ.measurableSet_le_stopping_time hσ) fun t => ?_).symm rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_le_iff]; simp_all only end Condexp end MeasureTheory
Chebyshev.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Data.Complex.Trigonometric import Mathlib.Data.Complex.Module import Mathlib.RingTheory.Polynomial.Chebyshev /-! # Multiple angle formulas in terms of Chebyshev polynomials This file gives the trigonometric characterizations of Chebyshev polynomials, for the real (`Real.cos`) and complex (`Complex.cos`) cosine and the real (`Real.cosh`) and complex (`Complex.cosh`) hyperbolic cosine. -/ namespace Polynomial.Chebyshev open Polynomial variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] @[simp, norm_cast] theorem complex_ofReal_eval_T : ∀ (x : ℝ) n, (((T ℝ n).eval x : ℝ) : ℂ) = (T ℂ n).eval (x : ℂ) := @algebraMap_eval_T ℝ ℂ _ _ _ @[simp, norm_cast] theorem complex_ofReal_eval_U : ∀ (x : ℝ) n, (((U ℝ n).eval x : ℝ) : ℂ) = (U ℂ n).eval (x : ℂ) := @algebraMap_eval_U ℝ ℂ _ _ _ @[simp, norm_cast] theorem complex_ofReal_eval_C : ∀ (x : ℝ) n, (((C ℝ n).eval x : ℝ) : ℂ) = (C ℂ n).eval (x : ℂ) := @algebraMap_eval_C ℝ ℂ _ _ _ @[simp, norm_cast] theorem complex_ofReal_eval_S : ∀ (x : ℝ) n, (((S ℝ n).eval x : ℝ) : ℂ) = (S ℂ n).eval (x : ℂ) := @algebraMap_eval_S ℝ ℂ _ _ _ /-! ### Complex versions -/ section Complex open Complex variable (θ : ℂ) /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the value `cos (n * θ)`. -/ @[simp] theorem T_complex_cos (n : ℤ) : (T ℂ n).eval (cos θ) = cos (n * θ) := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => simp only [T_add_two, eval_sub, eval_mul, eval_X, eval_ofNat, ih1, ih2, sub_eq_iff_eq_add, cos_add_cos] push_cast ring_nf | neg_add_one n ih1 ih2 => simp only [T_sub_one, eval_sub, eval_mul, eval_X, eval_ofNat, ih1, ih2, sub_eq_iff_eq_add', cos_add_cos] push_cast ring_nf /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the value `sin ((n + 1) * θ) / sin θ`. -/ @[simp] theorem U_complex_cos (n : ℤ) : (U ℂ n).eval (cos θ) * sin θ = sin ((n + 1) * θ) := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp [one_add_one_eq_two, sin_two_mul]; ring | add_two n ih1 ih2 => simp only [U_add_two, eval_sub, eval_mul, eval_X, eval_ofNat, sub_mul, mul_assoc, ih1, ih2, sub_eq_iff_eq_add, sin_add_sin] push_cast ring_nf | neg_add_one n ih1 ih2 => simp only [U_sub_one, eval_sub, eval_mul, eval_X, eval_ofNat, sub_mul, mul_assoc, ih1, ih2, sub_eq_iff_eq_add', sin_add_sin] push_cast ring_nf /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cos θ` to the value `2 * cos (n * θ)`. -/ @[simp] theorem C_two_mul_complex_cos (n : ℤ) : (C ℂ n).eval (2 * cos θ) = 2 * cos (n * θ) := by simp [C_eq_two_mul_T_comp_half_mul_X] /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cos θ` to the value `sin ((n + 1) * θ) / sin θ`. -/ @[simp] theorem S_two_mul_complex_cos (n : ℤ) : (S ℂ n).eval (2 * cos θ) * sin θ = sin ((n + 1) * θ) := by simp [S_eq_U_comp_half_mul_X] /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cosh θ` to the value `cosh (n * θ)`. -/ @[simp] theorem T_complex_cosh (n : ℤ) : (T ℂ n).eval (cosh θ) = cosh (n * θ) := calc (T ℂ n).eval (cosh θ) _ = (T ℂ n).eval (cos (θ * I)) := by rw [cos_mul_I] _ = cos (n * (θ * I)) := T_complex_cos (θ * I) n _ = cos (n * θ * I) := by rw [mul_assoc] _ = cosh (n * θ) := cos_mul_I (n * θ) /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cosh θ` to the value `sinh ((n + 1) * θ) / sinh θ`. -/ @[simp] theorem U_complex_cosh (n : ℤ) : (U ℂ n).eval (cosh θ) * sinh θ = sinh ((n + 1) * θ) := calc (U ℂ n).eval (cosh θ) * sinh θ _ = (U ℂ n).eval (cos (θ * I)) * sin (θ * I) * (-I) := by simp [cos_mul_I, sin_mul_I, mul_assoc] _ = sin ((n + 1) * (θ * I)) * (-I) := by rw [U_complex_cos] _ = sin ((n + 1) * θ * I) * (-I) := by rw [mul_assoc] _ = sinh ((n + 1) * θ) := by rw [sin_mul_I ((n + 1) * θ), mul_assoc, mul_neg, I_mul_I, neg_neg, mul_one] /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cosh θ` to the value `2 * cosh (n * θ)`. -/ @[simp] theorem C_two_mul_complex_cosh (n : ℤ) : (C ℂ n).eval (2 * cosh θ) = 2 * cosh (n * θ) := by simp [C_eq_two_mul_T_comp_half_mul_X] /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cosh θ` to the value `sinh ((n + 1) * θ) / sinh θ`. -/ @[simp] theorem S_two_mul_complex_cosh (n : ℤ) : (S ℂ n).eval (2 * cosh θ) * sinh θ = sinh ((n + 1) * θ) := by simp [S_eq_U_comp_half_mul_X] end Complex /-! ### Real versions -/ section Real open Real variable (θ : ℝ) (n : ℤ) /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the value `cos (n * θ)`. -/ @[simp] theorem T_real_cos : (T ℝ n).eval (cos θ) = cos (n * θ) := mod_cast T_complex_cos θ n /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the value `sin ((n + 1) * θ) / sin θ`. -/ @[simp] theorem U_real_cos : (U ℝ n).eval (cos θ) * sin θ = sin ((n + 1) * θ) := mod_cast U_complex_cos θ n /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cos θ` to the value `2 * cos (n * θ)`. -/ @[simp] theorem C_two_mul_real_cos : (C ℝ n).eval (2 * cos θ) = 2 * cos (n * θ) := mod_cast C_two_mul_complex_cos θ n /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cos θ` to the value `sin ((n + 1) * θ) / sin θ`. -/ @[simp] theorem S_two_mul_real_cos : (S ℝ n).eval (2 * cos θ) * sin θ = sin ((n + 1) * θ) := mod_cast S_two_mul_complex_cos θ n /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cosh θ` to the value `cosh (n * θ)`. -/ @[simp] theorem T_real_cosh (n : ℤ) : (T ℝ n).eval (cosh θ) = cosh (n * θ) := mod_cast T_complex_cosh θ n /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cosh θ` to the value `sinh ((n + 1) * θ) / sinh θ`. -/ @[simp] theorem U_real_cosh (n : ℤ) : (U ℝ n).eval (cosh θ) * sinh θ = sinh ((n + 1) * θ) := mod_cast U_complex_cosh θ n /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cosh θ` to the value `2 * cosh (n * θ)`. -/ @[simp] theorem C_two_mul_real_cosh (n : ℤ) : (C ℝ n).eval (2 * cosh θ) = 2 * cosh (n * θ) := mod_cast C_two_mul_complex_cosh θ n /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cosh θ` to the value `sinh ((n + 1) * θ) / sinh θ`. -/ @[simp] theorem S_two_mul_real_cosh (n : ℤ) : (S ℝ n).eval (2 * cosh θ) * sinh θ = sinh ((n + 1) * θ) := mod_cast S_two_mul_complex_cosh θ n end Real end Polynomial.Chebyshev
monoid.v
From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat seq. From mathcomp Require Import bigop fintype finfun. (******************************************************************************) (* Group-like structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines the following algebraic structures: *) (* *) (* magmaType == magma *) (* The HB class is called Magma. *) (* ChoiceMagma.type == join of magmaType and choiceType *) (* The HB class is called ChoiceMagma. *) (* semigroupType == associative magma *) (* The HB class is called Semigroup. *) (* baseUMagmaType == pointed magma *) (* The HB class is called BaseUMagma. *) (* ChoiceBaseUMagma.type == join of baseUMagmaType and choiceType *) (* The HB class is called ChoiceBaseUMagma. *) (* umagmaType == unitary magma *) (* The HB class is called UMagma. *) (* monoidType == monoid *) (* The HB class is called Monoid. *) (* baseGroupType == pointed magma with an inversion operator *) (* The HB class is called BaseGroup. *) (* groupType == group *) (* The HB class is called Group. *) (* *) (* and their joins with subType: *) (* *) (* subMagmaType V P == join of magmaType and subType (P : pred V) such *) (* that val is multiplicative *) (* The HB class is called SubMagma. *) (* subSemigroupType V P == join of semigroupType and subType (P : pred V) *) (* such that val is multiplicative *) (* The HB class is called SubSemigroup. *) (* subBaseUMagmaType V P == join of baseUMagmaType and subType (P : pred V) *) (* such that val is multiplicative and preserves 1 *) (* The HB class is called SubBaseUMagma. *) (* subUMagmaType V P == join of UMagmaType and subType (P : pred V) *) (* such that val is multiplicative and preserves 1 *) (* The HB class is called SubUMagma. *) (* subMonoidType V P == join of monoidType and subType (P : pred V) *) (* such that val is multiplicative and preserves 1 *) (* The HB class is called SubMonoid. *) (* subGroupType V P == join of groupType and subType (P : pred V) *) (* such that val is multiplicative and preserves 1 *) (* The HB class is called SubGroup. *) (* *) (* Morphisms between the above structures: *) (* *) (* Multiplicative.type G H == multiplicative functions between magmaType *) (* instances G and H *) (* UMagmaMorphism.type G H == multiplicative functions preserving 1 between *) (* baseUMagmaType instances G and H *) (* *) (* Closedness predicates for the algebraic structures: *) (* *) (* mulgClosed V == predicate closed under multiplication on G : magmaType *) (* The HB class is called MulClosed. *) (* umagmaClosed V == predicate closed under multiplication and containing 1 *) (* on G : baseUMagmaType *) (* The HB class is called UMagmaClosed. *) (* invgClosed V == predicate closed under inversion on G : baseGroupType *) (* The HB class is called InvClosed. *) (* groupClosed V == predicate closed under multiplication and inversion and *) (* containing 1 on G : baseGroupType *) (* The HB class is called InvClosed. *) (* *) (* Canonical properties of the algebraic structures: *) (* * magmaType (magmas): *) (* x * y == the product of x and y *) (* commute x y <-> x and y commute (i.e. x * y = y * x) *) (* mulg_closed S <-> collective predicate S is closed under *) (* multiplication *) (* *) (* * baseUMagmaType (pointed magmas): *) (* 1 == the unit of a unitary magma *) (* x ^+ n == x to the power n, with n in nat (non-negative), *) (* i.e. x * (x * .. (x * x)..) (n terms); x ^+ 1 is *) (* thus convertible to x, and x ^+ 2 to x * x *) (* \prod<range> e == iterated product for a baseUMagmaType (cf bigop.v)*) (* umagma_closed S <-> collective predicate S is closed under *) (* multiplication and contains 1 *) (* *) (* * monoidType (monoids): *) (* monoid_closed S := umagma_closed S *) (* *) (* * baseGroupType (pointed magmas with an inversion operator): *) (* x ^-1 == the inverse of x *) (* x / y == x * (y ^- 1) *) (* x ^- n == (x ^+ n)^-1 *) (* x ^ y := y^-1 * (x * y) *) (* == the conjugate of x by y *) (* [~ x, y] := x^-1 * (y^-1 * (x * y) *) (* == the commutator of x and y *) (* invg_closed S <-> collective predicate S is closed under inversion *) (* divg_closed S <-> collective predicate S is closed under division *) (* group_closed S <-> collective predicate S is closed under division *) (* and contains 1 *) (* *) (* In addition to this structure hierarchy, we also develop a separate, *) (* *) (* * Multiplicative (magma morphisms): *) (* {multiplicative U -> V} == the interface type for magma morphisms, i.e. *) (* functions from U to V which maps * in U to * in *) (* V; both U and V must have magmaType instances *) (* := GRing.RMorphism.type R S *) (* *) (* * UMagmaMorphism (unitary magma morphisms): *) (* monoid_morphism f <-> f of type U -> V is a multiplicative monoid *) (* morphism, i.e., f maps 1 and * in U to 1 and *) (* * in V, respectively. U and V must have *) (* canonical baseUMagmaType instances. *) (*Algebra.UMagmaMorphism.type == the interface type for unitary magma *) (* morphisms; both U and V must have magmaType *) (* instances *) (* *) (* Notations are defined in scope group_scope (delimiter %g) *) (* This library also extends the conventional suffixes described in library *) (* ssrbool.v with the following: *) (* 1 -- unitary magma 1, as in mulg1 : x * 1 = x *) (* M -- magma multiplication, as in conjgM : x ^ (y * z) = (x ^ y) ^ z *) (* Mn -- ring by nat multiplication, as in expgMn : *) (* (x * y) ^+ n = x ^+ n * y ^+ n *) (* V -- group inverse, as in expVgn : (x^-1) ^+ n = x ^- n *) (* F -- group division, as in invgF : (x / y)^-1 = y / x *) (* X -- unitary magma exponentiation, as in conjXg : *) (* (x ^+ n) ^ y = (x ^ y) ^+ n *) (* J -- group conjugation, as in conjJg : (x ^ y) ^ z = (x ^ z) ^ y ^ z *) (* R -- group commutator, as in conjRg : [~ x, y] ^ z = [~ x ^ z, y ^ z] *) (* The operator suffixes D, B, M and X are also used for the corresponding *) (* operations on nat, as in expgnDr : x ^+ (m + n) = x ^+ m * x ^+ n. For the *) (* binary power operator, a trailing "n" suffix is used to indicate the *) (* operator suffix applies to the left-hand group argument, as in *) (* expg1n : 1 ^+ n = 1 vs. expg1 : x ^+ 1 = x. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "*%g" (at level 0). Reserved Notation "\1" (at level 0). Reserved Notation "f \* g" (at level 40, left associativity). Reserved Notation "'{' 'multiplicative' G '->' H '}'" (at level 0, G at level 98, H at level 99, format "{ 'multiplicative' G -> H }"). Declare Scope group_scope. Delimit Scope group_scope with g. Local Open Scope group_scope. HB.mixin Record hasMul G := { mul : G -> G -> G }. #[short(type="magmaType")] HB.structure Definition Magma := {G of hasMul G}. Bind Scope group_scope with Magma.sort. HB.structure Definition ChoiceMagma := {G of Magma G & Choice G}. Bind Scope group_scope with ChoiceMagma.sort. Local Notation "*%g" := (@mul _) : function_scope. Local Notation "x * y" := (mul x y) : group_scope. Section MagmaTheory. Variable G : magmaType. Implicit Types x y : G. Definition commute x y := x * y = y * x. Lemma commute_refl x : commute x x. Proof. by []. Qed. Lemma commute_sym x y : commute x y -> commute y x. Proof. by []. Qed. Section ClosedPredicates. Variable S : {pred G}. Definition mulg_closed := {in S &, forall u v, u * v \in S}. End ClosedPredicates. End MagmaTheory. HB.mixin Record Magma_isSemigroup G of Magma G := { mulgA : associative (@mul G) }. #[short(type="semigroupType")] HB.structure Definition Semigroup := {G of Magma_isSemigroup G & ChoiceMagma G}. HB.factory Record isSemigroup G of Choice G := { mul : G -> G -> G; mulgA : associative mul }. HB.builders Context G of isSemigroup G. HB.instance Definition _ := hasMul.Build G mul. HB.instance Definition _ := Magma_isSemigroup.Build G mulgA. HB.end. Bind Scope group_scope with Semigroup.sort. Section SemigroupTheory. Variable G : semigroupType. Implicit Types x y : G. Lemma commuteM x y z : commute x y -> commute x z -> commute x (y * z). Proof. by move=> cxy cxz; rewrite /commute -mulgA -cxz !mulgA cxy. Qed. End SemigroupTheory. HB.mixin Record hasOne G := { one : G }. #[short(type="baseUMagmaType")] HB.structure Definition BaseUMagma := {G of hasOne G & Magma G}. Bind Scope group_scope with BaseUMagma.sort. HB.structure Definition ChoiceBaseUMagma := {G of BaseUMagma G & Choice G}. Bind Scope group_scope with ChoiceBaseUMagma.sort. Local Notation "1" := (@one _) : group_scope. Local Notation "s `_ i" := (nth 1 s i) : group_scope. Local Notation "\prod_ ( i <- r | P ) F" := (\big[*%g/1]_(i <- r | P) F). Local Notation "\prod_ ( i | P ) F" := (\big[*%g/1]_(i | P) F). Local Notation "\prod_ ( i 'in' A ) F" := (\big[*%g/1]_(i in A) F). Local Notation "\prod_ ( m <= i < n ) F" := (\big[*%g/1%g]_(m <= i < n) F%g). Definition natexp (G : baseUMagmaType) (x : G) n : G := iterop n *%g x 1. Arguments natexp : simpl never. Local Notation "x ^+ n" := (natexp x n) : group_scope. Section baseUMagmaTheory. Variable G : baseUMagmaType. Implicit Types x : G. Lemma expg0 x : x ^+ 0 = 1. Proof. by []. Qed. Lemma expg1 x : x ^+ 1 = x. Proof. by []. Qed. Lemma expg2 x : x ^+ 2 = x * x. Proof. by []. Qed. Lemma expgSS x n : x ^+ n.+2 = x * x ^+ n.+1. Proof. by []. Qed. Lemma expgb x (b : bool) : x ^+ b = (if b then x else 1). Proof. by case: b. Qed. Section ClosedPredicates. Variable S : {pred G}. Definition umagma_closed := 1 \in S /\ mulg_closed S. End ClosedPredicates. End baseUMagmaTheory. HB.mixin Record BaseUMagma_isUMagma G of BaseUMagma G := { mul1g : left_id one (@mul G); mulg1 : right_id one (@mul G) }. HB.factory Record Magma_isUMagma G of Magma G := { one : G; mul1g : left_id one (@mul G); mulg1 : right_id one (@mul G) }. HB.builders Context G of Magma_isUMagma G. HB.instance Definition _ := hasOne.Build G one. #[warning="-HB.no-new-instance"] HB.instance Definition _ := BaseUMagma_isUMagma.Build G mul1g mulg1. HB.end. #[short(type="umagmaType")] HB.structure Definition UMagma := {G of Magma_isUMagma G & ChoiceMagma G}. Bind Scope group_scope with UMagma.sort. Section UMagmaTheory. Variable G : umagmaType. Implicit Types x y : G. Lemma expgS x n : x ^+ n.+1 = x * x ^+ n. Proof. by case: n => //=; rewrite mulg1. Qed. Lemma expg1n n : 1 ^+ n = 1 :> G. Proof. by elim: n => // n IHn; rewrite expgS mul1g. Qed. Lemma commute1 x : commute x 1. Proof. by rewrite /commute mulg1 mul1g. Qed. End UMagmaTheory. #[short(type="monoidType")] HB.structure Definition Monoid := {G of Magma_isUMagma G & Semigroup G}. HB.factory Record Semigroup_isMonoid G of Semigroup G := { one : G; mul1g : left_id one mul; mulg1 : right_id one mul }. HB.builders Context G of Semigroup_isMonoid G. HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1. HB.end. HB.factory Record UMagma_isMonoid G of UMagma G := { mulgA : associative (@mul G) }. HB.builders Context G of UMagma_isMonoid G. HB.instance Definition _ := Magma_isSemigroup.Build G mulgA. HB.end. HB.factory Record isMonoid G of Choice G := { mul : G -> G -> G; one : G; mulgA : associative mul; mul1g : left_id one mul; mulg1 : right_id one mul }. HB.builders Context G of isMonoid G. HB.instance Definition _ := hasMul.Build G mul. HB.instance Definition _ := Magma_isSemigroup.Build G mulgA. HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1. HB.end. #[export] HB.instance Definition _ (G : monoidType) := Monoid.isLaw.Build G 1 *%g mulgA mul1g mulg1. Bind Scope group_scope with Monoid.sort. Section MonoidTheory. Variable G : monoidType. Implicit Types x y : G. Lemma expgSr x n : x ^+ n.+1 = x ^+ n * x. Proof. elim: n => [|n IHn]; first by rewrite mul1g. by rewrite expgS [in LHS]IHn expgS mulgA. Qed. Lemma expgnDr x m n : x ^+ (m + n) = x ^+ m * x ^+ n. Proof. elim: m => [|m IHm]; first by rewrite mul1g. by rewrite 2!expgS IHm mulgA. Qed. Lemma expgnA x m n : x ^+ (m * n) = x ^+ m ^+ n. Proof. by rewrite mulnC; elim: n => //= n IHn; rewrite expgS expgnDr IHn. Qed. Lemma expgnAC x m n : x ^+ m ^+ n = x ^+ n ^+ m. Proof. by rewrite -2!expgnA mulnC. Qed. Lemma iter_mulg n x y : iter n ( *%g x) y = x ^+ n * y. Proof. by elim: n => [|n IHn]; rewrite ?mul1g //= IHn expgS mulgA. Qed. Lemma iter_mulg_1 n x : iter n ( *%g x) 1 = x ^+ n. Proof. by rewrite iter_mulg mulg1. Qed. Lemma prodg_const (I : finType) (A : pred I) x : \prod_(i in A) x = x ^+ #|A|. Proof. by rewrite big_const -Monoid.iteropE. Qed. Lemma prodg_const_nat n m x : \prod_(n <= i < m) x = x ^+ (m - n). Proof. by rewrite big_const_nat -Monoid.iteropE. Qed. Lemma prodgXr x I r P (F : I -> nat) : \prod_(i <- r | P i) x ^+ F i = x ^+ (\sum_(i <- r | P i) F i). Proof. by rewrite (big_morph _ (expgnDr _) (erefl _)). Qed. Lemma commute_prod (I : Type) (s : seq I) (P : pred I) (F : I -> G) x : (forall i, P i -> commute x (F i)) -> commute x (\prod_(i <- s | P i) F i). Proof. exact: (big_ind _ (commute1 x) (@commuteM _ x)). Qed. Lemma prodgM_commute {I : eqType} r (P : pred I) (F H : I -> G) : (forall i j, P i -> P j -> commute (F i) (H j)) -> \prod_(i <- r | P i) (F i * H i) = \prod_(i <- r | P i) F i * \prod_(i <- r | P i) H i. Proof. move=> FH; elim: r => [|i r IHr]; rewrite !(big_nil, big_cons) ?mulg1//. case: ifPn => // Pi; rewrite IHr !mulgA; congr (_ * _); rewrite -!mulgA. by rewrite commute_prod // => j Pj; apply/commute_sym/FH. Qed. Lemma prodgMl_commute {I : finType} (A : pred I) (x : G) F : (forall i, A i -> commute x (F i)) -> \prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i. Proof. by move=> xF; rewrite prodgM_commute ?prodg_const// => i j _ /xF. Qed. Lemma prodgMr_commute {I : finType} (A : pred I) (x : G) F : (forall i, A i -> commute x (F i)) -> \prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|. Proof. by move=> xF; rewrite prodgM_commute ?prodg_const// => i j /xF. Qed. Lemma commuteX x y n : commute x y -> commute x (y ^+ n). Proof. by move=> cxy; case: n; [apply: commute1 | elim=> // n; apply: commuteM]. Qed. Lemma commuteX2 x y m n : commute x y -> commute (x ^+ m) (y ^+ n). Proof. by move=> cxy; apply/commuteX/commute_sym/commuteX. Qed. Lemma expgMn x y n : commute x y -> (x * y) ^+ n = x ^+ n * y ^+ n. Proof. move=> cxy; elim: n => [|n IHn]; first by rewrite mulg1. by rewrite !expgS IHn -mulgA (mulgA y) (commuteX _ (commute_sym cxy)) !mulgA. Qed. End MonoidTheory. Notation monoid_closed := umagma_closed. HB.mixin Record hasInv G := { inv : G -> G }. #[short(type="baseGroupType")] HB.structure Definition BaseGroup := {G of hasInv G & BaseUMagma G}. Bind Scope group_scope with BaseGroup.sort. HB.mixin Record Monoid_isGroup G of BaseGroup G := { mulVg : left_inverse one inv (@mul G); mulgV : right_inverse one inv (@mul G) }. #[short(type="groupType")] HB.structure Definition Group := {G of Monoid_isGroup G & BaseGroup G & Monoid G}. HB.factory Record isGroup G of Choice G := { one : G; inv : G -> G; mul : G -> G -> G; mulgA : associative mul; mul1g : left_id one mul; mulg1 : right_id one mul; mulVg : left_inverse one inv mul; mulgV : right_inverse one inv mul }. HB.builders Context G of isGroup G. HB.instance Definition _ := hasMul.Build G mul. HB.instance Definition _ := Magma_isSemigroup.Build G mulgA. HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1. HB.instance Definition _ := hasInv.Build G inv. HB.instance Definition _ := Monoid_isGroup.Build G mulVg mulgV. HB.end. Bind Scope group_scope with Group.sort. Local Notation "x ^-1" := (inv x) : group_scope. Local Notation "x / y" := (x * y^-1) : group_scope. Local Notation "x ^- n" := ((x ^+ n)^-1) : group_scope. Definition conjg (G : groupType) (x y : G) := y^-1 * (x * y). Local Notation "x ^ y" := (conjg x y) : group_scope. Definition commg (G : groupType) (x y : G) := x^-1 * (conjg x y). Local Notation "[~ x , y ]" := (commg x y) : group_scope. Section GroupTheory. Variable G : groupType. Implicit Types x y : G. Definition divgg := @mulgV G. Lemma mulKg : @left_loop G G (@inv G) *%g. Proof. by move=> x y; rewrite mulgA mulVg mul1g. Qed. Lemma mulVKg : @rev_left_loop G G (@inv G) *%g. Proof. by move=> x y ; rewrite mulgA mulgV mul1g. Qed. Lemma mulgK : @right_loop G G (@inv G) *%g. Proof. by move=> x y; rewrite -mulgA mulgV mulg1. Qed. Lemma mulgVK : @rev_right_loop G G (@inv G) *%g. Proof. by move=> x y ; rewrite -mulgA mulVg mulg1. Qed. Definition divgK := mulgVK. Lemma mulgI : @right_injective G G G *%g. Proof. by move=> x; apply: can_inj (mulKg x). Qed. Lemma mulIg : @left_injective G G G *%g. Proof. by move=> x; apply: can_inj (mulgK x). Qed. Lemma invgK : @involutive G (@inv G). Proof. by move=> x; rewrite -[LHS](mulVKg x) divgg mulg1. Qed. Lemma invg_inj : @injective G G (@inv G). Proof. exact: inv_inj invgK. Qed. Lemma divgI : @right_injective G G G (fun x y => x / y). Proof. by move=> x y z /mulgI/invg_inj. Qed. Lemma divIg : @left_injective G G G (fun x y => x / y). Proof. by move=> x y z /mulIg. Qed. Lemma invg1 : 1 ^-1 = 1 :> G. Proof. by rewrite -[LHS]mul1g divgg. Qed. Lemma invg_eq1 x : (x ^-1 == 1) = (x == 1). Proof. by rewrite (inv_eq invgK) invg1. Qed. Lemma divg1 x : x / 1 = x. Proof. by rewrite invg1 mulg1. Qed. Lemma div1g x : 1 / x = x^-1. Proof. by rewrite mul1g. Qed. Lemma invgF x y : (x / y)^-1 = y / x. Proof. by apply/(canRL (mulgK x))/(@divIg y); rewrite -mulgA mulVg divgg. Qed. Lemma invgM : {morph (@inv G): x y / x * y >-> y * x : G}. Proof. by move=> x y; rewrite -[y in LHS]invgK invgF. Qed. Lemma prodgV I r (P : pred I) (E : I -> G) : \prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- rev r | P i) E i)^-1. Proof. elim: r => [|x r IHr]; first by rewrite !big_nil invg1. rewrite big_cons rev_cons big_rcons/= IHr. by case: ifP => _; rewrite ?mulg1// invgM. Qed. Lemma divKg x y : commute x y -> x / (x / y) = y. Proof. by move=> xyC; rewrite invgF mulgA xyC mulgK. Qed. (* TOTHINK : This does not have the same form as addrKA in ssralg.v *) Lemma mulgKA z x y : (x * z) / (y * z) = x / y. Proof. by rewrite invgM mulgA mulgK. Qed. Lemma divgKA z x y : (x / z) * (z * y) = x * y. Proof. by rewrite mulgA mulgVK. Qed. Lemma mulg1_eq x y : x * y = 1 -> x^-1 = y. Proof. by rewrite -[x^-1]mulg1 => <-; rewrite mulKg. Qed. Lemma divg1_eq x y : x / y = 1 -> x = y. Proof. by move/mulg1_eq/invg_inj. Qed. Lemma divg_eq x y z : (x / z == y) = (x == y * z). Proof. exact: can2_eq (divgK z) (mulgK z) x y. Qed. Lemma divg_eq1 x y : (x / y == 1) = (x == y). Proof. by rewrite divg_eq mul1g. Qed. Lemma mulg_eq1 x y : (x * y == 1) = (x == y^-1). Proof. by rewrite -[y in LHS]invgK divg_eq1. Qed. Lemma eqg_inv x y : (x^-1 == y^-1) = (x == y). Proof. exact: can_eq invgK x y. Qed. Lemma eqg_invLR x y : (x^-1 == y) = (x == y^-1). Proof. exact: inv_eq invgK x y. Qed. Lemma commuteV x y : commute x y -> commute x y^-1. Proof. by move=> cxy; apply: (@mulIg y); rewrite mulgVK -mulgA cxy mulKg. Qed. Lemma expVgn x n : (x^-1) ^+ n = x ^- n. Proof. apply/esym/mulg1_eq; rewrite -expgMn; first by rewrite divgg expg1n. exact/commuteV. Qed. Lemma expgnFr x m n : n <= m -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. by move=> lenm; rewrite -[in RHS](subnK lenm) expgnDr mulgK. Qed. Lemma expgnFl x y n : commute x y -> (x / y) ^+ n = x ^+ n / y ^+ n. Proof. by move=> xyC; rewrite expgMn 1?expVgn; last exact/commuteV. Qed. Lemma conjgE x y : x ^ y = y^-1 * (x * y). Proof. by []. Qed. Lemma conjgC x y : x * y = y * x ^ y. Proof. by rewrite mulVKg. Qed. Lemma conjgCV x y : x * y = y ^ x^-1 * x. Proof. by rewrite -mulgA mulgVK invgK. Qed. Lemma conjg1 x : x ^ 1 = x. Proof. by rewrite conjgE commute1 mulKg. Qed. Lemma conj1g x : 1 ^ x = 1. Proof. by rewrite conjgE mul1g mulVg. Qed. Lemma conjMg x y z : (x * y) ^ z = x ^ z * y ^ z. Proof. by rewrite !conjgE !mulgA mulgK. Qed. Lemma conjgM x y z : x ^ (y * z) = (x ^ y) ^ z. Proof. by rewrite !conjgE invgM !mulgA. Qed. Lemma conjVg x y : x^-1 ^ y = (x ^ y)^-1. Proof. by rewrite !conjgE !invgM invgK mulgA. Qed. Lemma conjJg x y z : (x ^ y) ^ z = (x ^ z) ^ y ^ z. Proof. by rewrite 2!conjMg conjVg. Qed. Lemma conjXg x y n : (x ^+ n) ^ y = (x ^ y) ^+ n. Proof. by elim: n => [|n IHn]; rewrite ?conj1g // !expgS conjMg IHn. Qed. Lemma conjgK : @right_loop G G (@inv G) (@conjg G). Proof. by move=> y x; rewrite -conjgM mulgV conjg1. Qed. Lemma conjgKV : @rev_right_loop G G (@inv G) (@conjg G). Proof. by move=> y x; rewrite -conjgM mulVg conjg1. Qed. Lemma conjg_inj : @left_injective G G G (@conjg G). Proof. by move=> y; apply: can_inj (conjgK y). Qed. Lemma conjg_eq1 x y : (x ^ y == 1) = (x == 1). Proof. by rewrite (can2_eq (conjgK _) (conjgKV _)) conj1g. Qed. Lemma commgEl x y : [~ x, y] = x^-1 * x ^ y. Proof. by []. Qed. Lemma commgEr x y : [~ x, y] = y^-1 ^ x * y. Proof. by rewrite -!mulgA. Qed. Lemma commgC x y : x * y = y * x * [~ x, y]. Proof. by rewrite -mulgA !mulVKg. Qed. Lemma commgCV x y : x * y = [~ x^-1, y^-1] * (y * x). Proof. by rewrite commgEl !mulgA !invgK !mulgVK. Qed. Lemma conjRg x y z : [~ x, y] ^ z = [~ x ^ z, y ^ z]. Proof. by rewrite !conjMg !conjVg. Qed. Lemma invgR x y : [~ x, y]^-1 = [~ y, x]. Proof. by rewrite commgEr conjVg invgM invgK. Qed. Lemma commgP x y : reflect (commute x y) ([~ x, y] == 1). Proof. rewrite [[~ x, y]]mulgA -invgM mulg_eq1 eqg_inv eq_sym; apply: eqP. Qed. Lemma conjg_fix x y : x ^ y == x = ([~ x, y] == 1). Proof. by rewrite mulg_eq1 eqg_inv. Qed. Lemma conjg_fixP x y : reflect (x ^ y = x) ([~ x, y] == 1). Proof. by rewrite -conjg_fix; apply: eqP. Qed. Lemma commg1_sym x y : ([~ x, y] == 1) = ([~ y, x] == 1). Proof. by rewrite -invgR (inv_eq invgK) invg1. Qed. Lemma commg1 x : [~ x, 1] = 1. Proof. exact/eqP/commgP/commute1. Qed. Lemma comm1g x : [~ 1, x] = 1. Proof. by rewrite -invgR commg1 invg1. Qed. Lemma commgg x : [~ x, x] = 1. Proof. exact/eqP/commgP. Qed. Lemma commgXg x n : [~ x, x ^+ n] = 1. Proof. exact/eqP/commgP/commuteX. Qed. Lemma commgVg x : [~ x, x^-1] = 1. Proof. exact/eqP/commgP/commuteV. Qed. Lemma commgXVg x n : [~ x, x ^- n] = 1. Proof. exact/eqP/commgP/commuteV/commuteX. Qed. Section ClosedPredicates. Variable S : {pred G}. Definition invg_closed := {in S, forall u, u^-1 \in S}. Definition divg_closed := {in S &, forall u v, u / v \in S}. Definition group_closed := 1 \in S /\ divg_closed. Lemma group_closedV : group_closed -> invg_closed. Proof. by move=> [S1 SB] x /(SB 1)-/(_ S1); rewrite div1g. Qed. Lemma group_closedM : group_closed -> mulg_closed S. Proof. move=> /[dup]-[S1 SB] /group_closedV SV x y xS /SV yS. rewrite -[y]invgK; exact: SB. Qed. End ClosedPredicates. End GroupTheory. (* Morphism hierarchy. *) HB.mixin Record isMultiplicative (G H : magmaType) (apply : G -> H) := { gmulfM : {morph apply : x y / x * y} }. HB.structure Definition Multiplicative (G H : magmaType) := {f of isMultiplicative G H f}. (* TODO: define pointedTypes and generalize this to pointedTypes. *) HB.mixin Record Multiplicative_isUMagmaMorphism (G H : baseUMagmaType) (f : G -> H) := { gmulf1 : f 1 = 1 }. HB.structure Definition UMagmaMorphism (G H : baseUMagmaType) := {f of Multiplicative_isUMagmaMorphism G H f & isMultiplicative G H f}. Definition monoid_morphism (G H : baseUMagmaType) (f : G -> H) : Prop := (f 1 = 1) * {morph f : x y / x * y}. HB.factory Record isUMagmaMorphism (G H : baseUMagmaType) (f : G -> H) := { monoid_morphism_subproof : monoid_morphism f }. HB.builders Context G H apply of isUMagmaMorphism G H apply. HB.instance Definition _ := isMultiplicative.Build G H apply monoid_morphism_subproof.2. HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build G H apply monoid_morphism_subproof.1. HB.end. HB.factory Record isGroupMorphism (G H : groupType) (f : G -> H) := { gmulfF : {morph f : x y / x / y} }. HB.builders Context G H apply of isGroupMorphism G H apply. Local Lemma gmulf1 : apply 1 = 1. Proof. by rewrite -[1]divg1 gmulfF divgg. Qed. Local Lemma gmulfM : {morph apply : x y / x * y}. Proof. move=> x y; rewrite -[y in LHS] invgK -[y^-1]mul1g. by rewrite !gmulfF gmulf1 div1g invgK. Qed. HB.instance Definition _ := isMultiplicative.Build G H apply gmulfM. HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build G H apply gmulf1. HB.end. Module MultiplicativeExports. Notation "{ 'multiplicative' U -> V }" := (Multiplicative.type U%type V%type) : type_scope. End MultiplicativeExports. HB.export MultiplicativeExports. (* FIXME: The instance below makes sure that the join instance between *) (* Multiplicative.type and UMagmaMorphism.type is declared in both directions.*) (* HB should do this automatically. *) #[non_forgetful_inheritance] HB.instance Definition _ G H (f : UMagmaMorphism.type G H) := UMagmaMorphism.on (Multiplicative.sort f). Section LiftedMagma. Variables (T : Type) (G : magmaType). Definition mul_fun (f g : T -> G) x := f x * g x. End LiftedMagma. Section LiftedBaseUMagma. Variables (T : Type) (G : baseUMagmaType). Definition one_fun : T -> G := fun=> 1. End LiftedBaseUMagma. Local Notation "\1" := (one_fun _) : function_scope. Local Notation "f \* g" := (mul_fun f g) : function_scope. Arguments one_fun {_} G _ /. Arguments mul_fun {_ _} f g _ /. Section MorphismTheory. Section Magma. Variables (G H : magmaType) (f : {multiplicative G -> H}). Lemma can2_gmulfM f' : cancel f f' -> cancel f' f -> {morph f' : x y / x * y}. Proof. by move=> fK f'K x y; apply: (canLR fK); rewrite gmulfM !f'K. Qed. Lemma gmulf_commute x y : commute x y -> commute (f x) (f y). Proof. by move=> xy; rewrite /commute -!gmulfM xy. Qed. End Magma. Section UMagma. Variables (G H : umagmaType) (f : UMagmaMorphism.type G H). Lemma gmulf_eq1 x : injective f -> (f x == 1) = (x == 1). Proof. by move=> /inj_eq <-; rewrite gmulf1. Qed. Lemma can2_gmulf1 f' : cancel f f' -> cancel f' f -> f' 1 = 1. Proof. by move=> fK f'K; apply: (canLR fK); rewrite gmulf1. Qed. Lemma gmulfXn n : {morph f : x / x ^+ n}. Proof. by elim: n => [|[|n] IHn] x /=; rewrite ?(gmulf1, gmulfM) // IHn. Qed. Lemma gmulf_prod I r (P : pred I) E : f (\prod_(i <- r | P i) E i) = \prod_(i <- r | P i) f (E i). Proof. exact: (big_morph f gmulfM gmulf1). Qed. End UMagma. Section Group. Variables (G H : groupType) (f : UMagmaMorphism.type G H). Lemma gmulfV : {morph f : x / x^-1}. Proof. by move=> x; apply/divg1_eq; rewrite invgK -gmulfM mulVg gmulf1. Qed. Lemma gmulfF : {morph f : x y / x / y}. Proof. by move=> x y; rewrite gmulfM gmulfV. Qed. Lemma gmulf_inj : (forall x, f x = 1 -> x = 1) -> injective f. Proof. by move=> fI x y xy; apply/divg1_eq/fI; rewrite gmulfF xy divgg. Qed. Lemma gmulfXVn n : {morph f : x / x ^- n}. Proof. by move=> x /=; rewrite gmulfV gmulfXn. Qed. Lemma gmulfJ : {morph f : x y / x ^ y}. Proof. by move=> x y; rewrite !gmulfM/= gmulfV. Qed. Lemma gmulfR : {morph f : x y / [~ x, y]}. Proof. by move=> x y; rewrite !gmulfM/= !gmulfV. Qed. End Group. Section MulFun. Variables (G H K : magmaType). Variables (f g : {multiplicative H -> K}) (h : {multiplicative G -> H}). Fact idfun_gmulfM : {morph @idfun G : x y / x * y}. Proof. by []. Qed. HB.instance Definition _ := isMultiplicative.Build G G idfun idfun_gmulfM. Fact comp_gmulfM : {morph f \o h : x y / x * y}. Proof. by move=> x y /=; rewrite !gmulfM. Qed. HB.instance Definition _ := isMultiplicative.Build G K (f \o h) comp_gmulfM. End MulFun. Section Mul1Fun. Variables (G : magmaType) (H : umagmaType). Fact idfun_gmulf1 : idfun 1 = 1 :> H. Proof. by []. Qed. HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build H H idfun idfun_gmulf1. Fact one_fun_gmulfM : {morph @one_fun G H : x y / x * y}. Proof. by move=> x y; rewrite mulg1. Qed. HB.instance Definition _ := isMultiplicative.Build G H (@one_fun G H) one_fun_gmulfM. End Mul1Fun. Section Mul11Fun. Variables (G H K : umagmaType). Variables (f g : UMagmaMorphism.type H K) (h : UMagmaMorphism.type G H). Fact comp_gmulf1 : (f \o h) 1 = 1. Proof. by rewrite /= !gmulf1. Qed. #[warning="-HB.no-new-instance"] HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build G K (f \o h) comp_gmulf1. Fact one_fun_gmulf1 : @one_fun G H 1 = 1. Proof. by []. Qed. HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build G H (@one_fun G H) one_fun_gmulf1. Fact mul_fun_gmulf1 : (f \* g) 1 = 1. Proof. by rewrite /= !gmulf1 mulg1. Qed. End Mul11Fun. End MorphismTheory. (* Mixins for stability properties *) HB.mixin Record isMulClosed (G : magmaType) (S : {pred G}) := { gpredM : mulg_closed S }. HB.mixin Record isMul1Closed (G : baseUMagmaType) (S : {pred G}) := { gpred1 : 1 \in S }. HB.mixin Record isInvClosed (G : groupType) (S : {pred G}) := { gpredVr : invg_closed S }. (* Structures for stability properties *) #[short(type="mulgClosed")] HB.structure Definition MulClosed G := {S of isMulClosed G S}. #[short(type="umagmaClosed")] HB.structure Definition UMagmaClosed G := {S of isMul1Closed G S & isMulClosed G S}. #[short(type="invgClosed")] HB.structure Definition InvClosed G := {S of isInvClosed G S}. #[short(type="groupClosed")] HB.structure Definition GroupClosed G := {S of isInvClosed G S & isMul1Closed G S & isMulClosed G S}. Section UMagmaPred. Variables (G : baseUMagmaType). Section UMagma. Variables S : umagmaClosed G. Lemma gpred_prod I r (P : pred I) F : (forall i, P i -> F i \in S) -> \prod_(i <- r | P i) F i \in S. Proof. by move=> IH; elim/big_ind: _; [apply: gpred1 | apply: gpredM |]. Qed. Lemma gpredXn n : {in S, forall u, u ^+ n \in S}. Proof. by move=> x xS; elim: n => [|[//|n] IHn]; [exact: gpred1 | exact: gpredM]. Qed. End UMagma. End UMagmaPred. Section GroupPred. Variables (G : groupType). Lemma gpredV (S : invgClosed G) : {mono (@inv G): u / u \in S}. Proof. by move=> u; apply/idP/idP=> /gpredVr; rewrite ?invgK; apply. Qed. Section Group. Variables S : groupClosed G. Lemma gpredF : {in S &, forall u v, u / v \in S}. Proof. by move=> x y xS yS; rewrite gpredM// gpredV. Qed. Lemma gpredFC u v : u / v \in S = (v / u \in S). Proof. by rewrite -gpredV invgF. Qed. Lemma gpredXNn n: {in S, forall u, u ^- n \in S}. Proof. by move=> x xS; apply/gpredVr/gpredXn. Qed. Lemma gpredMr x y : x \in S -> (y * x \in S) = (y \in S). Proof. move=> Sx; apply/idP/idP => [Sxy|/gpredM-> //]. by rewrite -(mulgK x y) gpredF. Qed. Lemma gpredMl x y : x \in S -> (x * y \in S) = (y \in S). Proof. move=> Sx; apply/idP/idP => [Sxy|/(gpredM x y Sx)//]. by rewrite -(mulKg x y) gpredM// gpredV. Qed. Lemma gpredFr x y : x \in S -> (y / x \in S) = (y \in S). Proof. by rewrite -gpredV; apply: gpredMr. Qed. Lemma gpredFl x y : x \in S -> (x / y \in S) = (y \in S). Proof. by rewrite -(gpredV S y); apply: gpredMl. Qed. Lemma gpredJ x y : x \in S -> y \in S -> x ^ y \in S. Proof. by move=> xS yS; apply/gpredM; [apply/gpredVr|apply/gpredM]. Qed. Lemma gpredR x y : x \in S -> y \in S -> [~ x, y] \in S. Proof. by move=> xS yS; apply/gpredM; [apply/gpredVr|apply/gpredJ]. Qed. End Group. End GroupPred. HB.mixin Record isSubMagma (G : magmaType) (S : pred G) H of SubType G S H & Magma H := { valM_subproof : {morph (val : H -> G) : x y / x * y} }. #[short(type="subMagmaType")] HB.structure Definition SubMagma (G : magmaType) S := { H of SubChoice G S H & Magma H & isSubMagma G S H }. Section subMagma. Context (G : magmaType) (S : pred G) (H : subMagmaType S). Notation val := (val : H -> G). HB.instance Definition _ := isMultiplicative.Build H G val valM_subproof. Lemma valM : {morph val : x y / x * y}. Proof. exact: gmulfM. Qed. End subMagma. HB.factory Record SubChoice_isSubMagma (G : magmaType) S H of SubChoice G S H := { mulg_closed_subproof : mulg_closed S }. HB.builders Context G S H of SubChoice_isSubMagma G S H. HB.instance Definition _ := isMulClosed.Build G S mulg_closed_subproof. Let inH v Sv : H := Sub v Sv. Let mulH (u1 u2 : H) := inH (gpredM _ _ (valP u1) (valP u2)). HB.instance Definition _ := hasMul.Build H mulH. Lemma valM : {morph (val : H -> G) : x y / x * y}. Proof. by move=> x y; rewrite SubK. Qed. HB.instance Definition _ := isSubMagma.Build G S H valM. HB.end. #[short(type="subSemigroupType")] HB.structure Definition SubSemigroup (G : semigroupType) S := { H of SubMagma G S H & Semigroup H}. HB.factory Record SubChoice_isSubSemigroup (G : semigroupType) S H of SubChoice G S H := { mulg_closed_subproof : mulg_closed S }. HB.builders Context G S H of SubChoice_isSubSemigroup G S H. HB.instance Definition _ := SubChoice_isSubMagma.Build G S H mulg_closed_subproof. Lemma mulgA : associative (@mul H). Proof. by move=> x y z; apply/val_inj; rewrite !valM mulgA. Qed. HB.instance Definition _ := isSemigroup.Build H mulgA. HB.end. HB.mixin Record isSubBaseUMagma (G : baseUMagmaType) (S : pred G) H of SubMagma G S H & BaseUMagma H := { val1_subproof : (val : H -> G) 1 = 1 }. #[short(type="subBaseUMagmaType")] HB.structure Definition SubBaseUMagma (G : umagmaType) S := { H of SubMagma G S H & BaseUMagma H & isSubBaseUMagma G S H}. #[short(type="subUMagmaType")] HB.structure Definition SubUMagma (G : umagmaType) S := { H of SubMagma G S H & UMagma H & isSubBaseUMagma G S H}. Section subUMagma. Context (G : umagmaType) (S : pred G) (H : subUMagmaType S). Notation val := (val : H -> G). HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build H G val val1_subproof. Lemma val1 : val 1 = 1. Proof. exact: gmulf1. Qed. End subUMagma. HB.factory Record SubChoice_isSubUMagma (G : umagmaType) S H of SubChoice G S H := { umagma_closed_subproof : umagma_closed S }. HB.builders Context G S H of SubChoice_isSubUMagma G S H. HB.instance Definition _ := SubChoice_isSubMagma.Build G S H (snd umagma_closed_subproof). Let inH v Sv : H := Sub v Sv. Let oneH := inH (fst umagma_closed_subproof). HB.instance Definition _ := hasOne.Build H oneH. Lemma val1 : (val : H -> G) 1 = 1. Proof. exact/SubK. Qed. HB.instance Definition _ := isSubBaseUMagma.Build G S H val1. Lemma mul1g : left_id 1 (@mul H). Proof. by move=> x; apply/val_inj; rewrite valM val1 mul1g. Qed. Lemma mulg1 : right_id 1 (@mul H). Proof. by move=> x; apply/val_inj; rewrite valM val1 mulg1. Qed. HB.instance Definition _ := BaseUMagma_isUMagma.Build H mul1g mulg1. HB.end. #[short(type="subMonoidType")] HB.structure Definition SubMonoid (G : monoidType) S := { H of SubUMagma G S H & Monoid H}. HB.factory Record SubChoice_isSubMonoid (G : monoidType) S H of SubChoice G S H := { monoid_closed_subproof : monoid_closed S }. HB.builders Context G S H of SubChoice_isSubMonoid G S H. HB.instance Definition _ := SubChoice_isSubUMagma.Build G S H monoid_closed_subproof. HB.instance Definition _ := SubChoice_isSubSemigroup.Build G S H (snd monoid_closed_subproof). HB.end. #[short(type="subGroupType")] HB.structure Definition SubGroup (G : groupType) S := { H of SubUMagma G S H & Group H}. HB.factory Record SubChoice_isSubGroup (G : groupType) S H of SubChoice G S H := { group_closed_subproof : group_closed S }. HB.builders Context G S H of SubChoice_isSubGroup G S H. Lemma umagma_closed : umagma_closed S. Proof. split; first exact/(fst group_closed_subproof). exact/group_closedM/group_closed_subproof. Qed. HB.instance Definition _ := SubChoice_isSubMonoid.Build G S H umagma_closed. HB.instance Definition _ := isInvClosed.Build G S (group_closedV group_closed_subproof). Let inH v Sv : H := Sub v Sv. Let invH (u : H) := inH (gpredVr _ (valP u)). HB.instance Definition _ := hasInv.Build H invH. Lemma mulVg : left_inverse 1%g invH *%g. Proof. by move=> x; apply/val_inj; rewrite valM SubK mulVg val1. Qed. Lemma mulgV : right_inverse 1%g invH *%g. Proof. by move=> x; apply/val_inj; rewrite valM SubK mulgV val1. Qed. HB.instance Definition _ := Monoid_isGroup.Build H mulVg mulgV. HB.end. (* Lifting Structure from the codomain of finfuns. *) Section FinFunMagma. Variable (aT : finType) (rT : magmaType). Implicit Types f g : {ffun aT -> rT}. Definition ffun_mul f g := [ffun a => f a * g a]. HB.instance Definition _ := hasMul.Build {ffun aT -> rT} ffun_mul. End FinFunMagma. (* FIXME: HB.saturate *) HB.instance Definition _ (aT : finType) (rT : ChoiceMagma.type) := Magma.on {ffun aT -> rT}. Section FinFunSemigroup. Variable (aT : finType) (rT : semigroupType). Implicit Types f g : {ffun aT -> rT}. Fact ffun_mulgA : associative (@ffun_mul aT rT). Proof. by move=> f1 f2 f3; apply/ffunP=> a; rewrite !ffunE mulgA. Qed. HB.instance Definition _ := isSemigroup.Build {ffun aT -> rT} ffun_mulgA. End FinFunSemigroup. Section FinFunBaseUMagma. Variable (aT : finType) (rT : baseUMagmaType). Implicit Types f g : {ffun aT -> rT}. Definition ffun_one := [ffun a : aT => (1 : rT)]. HB.instance Definition _ := hasOne.Build {ffun aT -> rT} ffun_one. End FinFunBaseUMagma. (* FIXME: HB.saturate *) HB.instance Definition _ (aT : finType) (rT : ChoiceBaseUMagma.type) := BaseUMagma.on {ffun aT -> rT}. Section FinFunUMagma. Variable (aT : finType) (rT : umagmaType). Implicit Types f g : {ffun aT -> rT}. Fact ffun_mul1g : left_id (@ffun_one aT rT) *%g. Proof. by move=> f; apply/ffunP => a; rewrite !ffunE mul1g. Qed. Fact ffun_mulg1 : right_id (@ffun_one aT rT) *%g. Proof. by move=> f; apply/ffunP => a; rewrite !ffunE mulg1. Qed. HB.instance Definition _ := Magma_isUMagma.Build {ffun aT -> rT} ffun_mul1g ffun_mulg1. End FinFunUMagma. (* FIXME: HB.saturate *) HB.instance Definition _ (aT : finType) (rT : monoidType) := UMagma.on {ffun aT -> rT}. Section FinFunBaseGroup. Variable (aT : finType) (rT : baseGroupType). Implicit Types f g : {ffun aT -> rT}. Definition ffun_inv f := [ffun a => (f a)^-1]. HB.instance Definition _ := hasInv.Build {ffun aT -> rT} ffun_inv. End FinFunBaseGroup. Section FinFunGroup. Variable (aT : finType) (rT : groupType). Implicit Types f g : {ffun aT -> rT}. Fact ffun_mulVg : left_inverse (@ffun_one aT rT) (@ffun_inv _ _) (@ffun_mul _ _). Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE mulVg. Qed. Fact ffun_mulgV : right_inverse (@ffun_one aT rT) (@ffun_inv _ _) (@ffun_mul _ _). Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE mulgV. Qed. HB.instance Definition _ := Monoid_isGroup.Build {ffun aT -> rT} ffun_mulVg ffun_mulgV. End FinFunGroup. (* External direct product *) Section PairMagma. Variables G H : magmaType. Definition mul_pair (x y : G * H) := (x.1 * y.1, x.2 * y.2). HB.instance Definition _ := hasMul.Build (G * H)%type mul_pair. Fact fst_is_multiplicative : {morph fst : x y / x * y}. Proof. by []. Qed. HB.instance Definition _ := isMultiplicative.Build _ _ fst fst_is_multiplicative. Fact snd_is_multiplicative : {morph snd : x y / x * y}. Proof. by []. Qed. HB.instance Definition _ := isMultiplicative.Build _ _ snd snd_is_multiplicative. End PairMagma. Section PairSemigroup. Variables G H : semigroupType. Lemma pair_mulgA : associative (@mul (G * H)%type). Proof. by move=> x y z; congr (_, _); apply/mulgA. Qed. HB.instance Definition _ := Magma_isSemigroup.Build (G * H)%type pair_mulgA. End PairSemigroup. Section PairBaseUMagma. Variables G H : baseUMagmaType. Definition one_pair : G * H := (1, 1). HB.instance Definition _ := hasOne.Build (G * H)%type one_pair. Fact fst_is_umagma_morphism : fst (1 : G * H) = 1. Proof. by []. Qed. HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build _ _ fst fst_is_umagma_morphism. Fact snd_is_umagma_morphism : snd (1 : G * H) = 1. Proof. by []. Qed. HB.instance Definition _ := Multiplicative_isUMagmaMorphism.Build _ _ snd snd_is_umagma_morphism. End PairBaseUMagma. Section PairUMagma. Variables G H : umagmaType. Lemma pair_mul1g : left_id (@one_pair G H) *%g. Proof. by move=> [x y]; congr (_, _); rewrite mul1g. Qed. Lemma pair_mulg1 : right_id (@one_pair G H) *%g. Proof. by move=> [x y]; congr (_, _); rewrite mulg1. Qed. HB.instance Definition _ := BaseUMagma_isUMagma.Build (G * H)%type pair_mul1g pair_mulg1. End PairUMagma. (* FIXME: HB.saturate *) HB.instance Definition _ (G H : ChoiceMagma.type) := Magma.on (G * H)%type. HB.instance Definition _ (G H : ChoiceBaseUMagma.type) := BaseUMagma.on (G * H)%type. HB.instance Definition _ (G H : monoidType) := Semigroup.on (G * H)%type. (* /FIXME *) Section PairBaseGroup. Variables G H : baseGroupType. Definition inv_pair (u : G * H) := (u.1 ^-1, u.2 ^-1). HB.instance Definition _ := hasInv.Build (G * H)%type inv_pair. End PairBaseGroup. Section PairGroup. Variables G H : groupType. Lemma pair_mulVg : left_inverse one (@inv_pair G H) mul. Proof. by move=> x; congr (_, _); apply/mulVg. Qed. Lemma pair_mulgV : right_inverse one (@inv_pair G H) mul. Proof. by move=> x; congr (_, _); apply/mulgV. Qed. HB.instance Definition _ := Monoid_isGroup.Build (G * H)%type pair_mulVg pair_mulgV. End PairGroup.
BigOperators.lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.List.MinMax import Mathlib.Algebra.Tropical.Basic import Mathlib.Order.ConditionallyCompleteLattice.Finset import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Tropicalization of finitary operations This file provides the "big-op" or notation-based finitary operations on tropicalized types. This allows easy conversion between sums to Infs and prods to sums. Results here are important for expressing that evaluation of tropical polynomials are the minimum over a finite piecewise collection of linear functions. ## Main declarations * `untrop_sum` ## Implementation notes No concrete (semi)ring is used here, only ones with inferable order/lattice structure, to support `Real`, `Rat`, `EReal`, and others (`ERat` is not yet defined). Minima over `List α` are defined as producing a value in `WithTop α` so proofs about lists do not directly transfer to minima over multisets or finsets. -/ variable {R S : Type*} open Tropical Finset theorem List.trop_sum [AddMonoid R] (l : List R) : trop l.sum = List.prod (l.map trop) := by induction' l with hd tl IH · simp · simp [← IH] theorem Multiset.trop_sum [AddCommMonoid R] (s : Multiset R) : trop s.sum = Multiset.prod (s.map trop) := Quotient.inductionOn s (by simpa using List.trop_sum) theorem trop_sum [AddCommMonoid R] (s : Finset S) (f : S → R) : trop (∑ i ∈ s, f i) = ∏ i ∈ s, trop (f i) := by convert Multiset.trop_sum (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem List.untrop_prod [AddMonoid R] (l : List (Tropical R)) : untrop l.prod = List.sum (l.map untrop) := by induction' l with hd tl IH · simp · simp [← IH] theorem Multiset.untrop_prod [AddCommMonoid R] (s : Multiset (Tropical R)) : untrop s.prod = Multiset.sum (s.map untrop) := Quotient.inductionOn s (by simpa using List.untrop_prod) theorem untrop_prod [AddCommMonoid R] (s : Finset S) (f : S → Tropical R) : untrop (∏ i ∈ s, f i) = ∑ i ∈ s, untrop (f i) := by convert Multiset.untrop_prod (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem List.trop_minimum [LinearOrder R] (l : List R) : trop l.minimum = List.sum (l.map (trop ∘ WithTop.some)) := by induction' l with hd tl IH · simp · simp [List.minimum_cons, ← IH] theorem Multiset.trop_inf [LinearOrder R] [OrderTop R] (s : Multiset R) : trop s.inf = Multiset.sum (s.map trop) := by induction' s using Multiset.induction with s x IH · simp · simp [← IH] theorem Finset.trop_inf [LinearOrder R] [OrderTop R] (s : Finset S) (f : S → R) : trop (s.inf f) = ∑ i ∈ s, trop (f i) := by convert Multiset.trop_inf (s.val.map f) simp only [Multiset.map_map, Function.comp_apply] rfl theorem trop_sInf_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → WithTop R) : trop (sInf (f '' s)) = ∑ i ∈ s, trop (f i) := by rcases s.eq_empty_or_nonempty with (rfl | h) · simp only [Set.image_empty, coe_empty, sum_empty, WithTop.sInf_empty, trop_top] rw [← inf'_eq_csInf_image _ h, inf'_eq_inf, s.trop_inf] theorem trop_iInf [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S → WithTop R) : trop (⨅ i : S, f i) = ∑ i : S, trop (f i) := by rw [iInf, ← Set.image_univ, ← coe_univ, trop_sInf_image] theorem Multiset.untrop_sum [LinearOrder R] [OrderTop R] (s : Multiset (Tropical R)) : untrop s.sum = Multiset.inf (s.map untrop) := by induction' s using Multiset.induction with s x IH · simp · simp only [sum_cons, untrop_add, map_cons, inf_cons, ← IH] theorem Finset.untrop_sum' [LinearOrder R] [OrderTop R] (s : Finset S) (f : S → Tropical R) : untrop (∑ i ∈ s, f i) = s.inf (untrop ∘ f) := by convert Multiset.untrop_sum (s.val.map f) simp only [Multiset.map_map, Function.comp_apply, inf_def] theorem untrop_sum_eq_sInf_image [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → Tropical (WithTop R)) : untrop (∑ i ∈ s, f i) = sInf (untrop ∘ f '' s) := by rcases s.eq_empty_or_nonempty with (rfl | h) · simp only [Set.image_empty, coe_empty, sum_empty, WithTop.sInf_empty, untrop_zero] · rw [← inf'_eq_csInf_image _ h, inf'_eq_inf, Finset.untrop_sum'] theorem untrop_sum [ConditionallyCompleteLinearOrder R] [Fintype S] (f : S → Tropical (WithTop R)) : untrop (∑ i : S, f i) = ⨅ i : S, untrop (f i) := by rw [iInf, ← Set.image_univ, ← coe_univ, untrop_sum_eq_sInf_image, Function.comp_def] /-- Note we cannot use `i ∈ s` instead of `i : s` here as it is simply not true on conditionally complete lattices! -/ theorem Finset.untrop_sum [ConditionallyCompleteLinearOrder R] (s : Finset S) (f : S → Tropical (WithTop R)) : untrop (∑ i ∈ s, f i) = ⨅ i : s, untrop (f i) := by simpa [← _root_.untrop_sum] using (sum_attach _ _).symm
BinaryProducts.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Basic /-! # Preserving binary products Constructions to relate the notions of preserving binary products and reflecting binary products to concrete binary fans. In particular, we show that `ProdComparison G X Y` is an isomorphism iff `G` preserves the product of `X` and `Y`. -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) namespace CategoryTheory.Limits section variable {P X Y Z : C} (f : P ⟶ X) (g : P ⟶ Y) /-- The map of a binary fan is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `BinaryFan.mk` with `Functor.mapCone`. -/ def isLimitMapConeBinaryFanEquiv : IsLimit (G.mapCone (BinaryFan.mk f g)) ≃ IsLimit (BinaryFan.mk (G.map f) (G.map g)) := (IsLimit.postcomposeHomEquiv (diagramIsoPair _) _).symm.trans (IsLimit.equivIsoLimit (Cones.ext (Iso.refl _) (by rintro (_ | _) <;> simp))) /-- The property of preserving products expressed in terms of binary fans. -/ def mapIsLimitOfPreservesOfIsLimit [PreservesLimit (pair X Y) G] (l : IsLimit (BinaryFan.mk f g)) : IsLimit (BinaryFan.mk (G.map f) (G.map g)) := isLimitMapConeBinaryFanEquiv G f g (isLimitOfPreserves G l) /-- The property of reflecting products expressed in terms of binary fans. -/ def isLimitOfReflectsOfMapIsLimit [ReflectsLimit (pair X Y) G] (l : IsLimit (BinaryFan.mk (G.map f) (G.map g))) : IsLimit (BinaryFan.mk f g) := isLimitOfReflects G ((isLimitMapConeBinaryFanEquiv G f g).symm l) variable (X Y) variable [HasBinaryProduct X Y] /-- If `G` preserves binary products and `C` has them, then the binary fan constructed of the mapped morphisms of the binary product cone is a limit. -/ def isLimitOfHasBinaryProductOfPreservesLimit [PreservesLimit (pair X Y) G] : IsLimit (BinaryFan.mk (G.map (Limits.prod.fst : X ⨯ Y ⟶ X)) (G.map Limits.prod.snd)) := mapIsLimitOfPreservesOfIsLimit G _ _ (prodIsProd X Y) variable [HasBinaryProduct (G.obj X) (G.obj Y)] /-- If the product comparison map for `G` at `(X,Y)` is an isomorphism, then `G` preserves the pair of `(X,Y)`. -/ lemma PreservesLimitPair.of_iso_prod_comparison [i : IsIso (prodComparison G X Y)] : PreservesLimit (pair X Y) G := by apply preservesLimit_of_preserves_limit_cone (prodIsProd X Y) apply (isLimitMapConeBinaryFanEquiv _ _ _).symm _ refine @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (pair (G.obj X) (G.obj Y))) ?_ apply i variable [PreservesLimit (pair X Y) G] /-- If `G` preserves the product of `(X,Y)`, then the product comparison map for `G` at `(X,Y)` is an isomorphism. -/ def PreservesLimitPair.iso : G.obj (X ⨯ Y) ≅ G.obj X ⨯ G.obj Y := IsLimit.conePointUniqueUpToIso (isLimitOfHasBinaryProductOfPreservesLimit G X Y) (limit.isLimit _) @[simp] theorem PreservesLimitPair.iso_hom : (PreservesLimitPair.iso G X Y).hom = prodComparison G X Y := rfl @[simp, reassoc] theorem PreservesLimitPair.iso_inv_fst : (PreservesLimitPair.iso G X Y).inv ≫ G.map prod.fst = prod.fst := by rw [← Iso.cancel_iso_hom_left (PreservesLimitPair.iso G X Y), ← Category.assoc, Iso.hom_inv_id] simp @[simp, reassoc] theorem PreservesLimitPair.iso_inv_snd : (PreservesLimitPair.iso G X Y).inv ≫ G.map prod.snd = prod.snd := by rw [← Iso.cancel_iso_hom_left (PreservesLimitPair.iso G X Y), ← Category.assoc, Iso.hom_inv_id] simp instance : IsIso (prodComparison G X Y) := by rw [← PreservesLimitPair.iso_hom] infer_instance /-- If the product comparison maps of `G` at every pair `(X,Y)` is an isomorphism, then `G` preserves binary products. -/ lemma preservesBinaryProducts_of_isIso_prodComparison [HasBinaryProducts C] [HasBinaryProducts D] [i : ∀ {X Y : C}, IsIso (prodComparison G X Y)] : PreservesLimitsOfShape (Discrete WalkingPair) G where preservesLimit := by intro K have : PreservesLimit (pair (K.obj ⟨WalkingPair.left⟩) (K.obj ⟨WalkingPair.right⟩)) G := PreservesLimitPair.of_iso_prod_comparison .. apply preservesLimit_of_iso_diagram G (diagramIsoPair K).symm end section variable {P X Y Z : C} (f : X ⟶ P) (g : Y ⟶ P) /-- The map of a binary cofan is a colimit iff the cofork consisting of the mapped morphisms is a colimit. This essentially lets us commute `BinaryCofan.mk` with `Functor.mapCocone`. -/ def isColimitMapCoconeBinaryCofanEquiv : IsColimit (Functor.mapCocone G (BinaryCofan.mk f g)) ≃ IsColimit (BinaryCofan.mk (G.map f) (G.map g)) := (IsColimit.precomposeHomEquiv (diagramIsoPair _).symm _).symm.trans (IsColimit.equivIsoColimit (Cocones.ext (Iso.refl _) (by rintro (_ | _) <;> simp))) /-- The property of preserving coproducts expressed in terms of binary cofans. -/ def mapIsColimitOfPreservesOfIsColimit [PreservesColimit (pair X Y) G] (l : IsColimit (BinaryCofan.mk f g)) : IsColimit (BinaryCofan.mk (G.map f) (G.map g)) := isColimitMapCoconeBinaryCofanEquiv G f g (isColimitOfPreserves G l) /-- The property of reflecting coproducts expressed in terms of binary cofans. -/ def isColimitOfReflectsOfMapIsColimit [ReflectsColimit (pair X Y) G] (l : IsColimit (BinaryCofan.mk (G.map f) (G.map g))) : IsColimit (BinaryCofan.mk f g) := isColimitOfReflects G ((isColimitMapCoconeBinaryCofanEquiv G f g).symm l) variable (X Y) variable [HasBinaryCoproduct X Y] /-- If `G` preserves binary coproducts and `C` has them, then the binary cofan constructed of the mapped morphisms of the binary product cocone is a colimit. -/ def isColimitOfHasBinaryCoproductOfPreservesColimit [PreservesColimit (pair X Y) G] : IsColimit (BinaryCofan.mk (G.map (Limits.coprod.inl : X ⟶ X ⨿ Y)) (G.map Limits.coprod.inr)) := mapIsColimitOfPreservesOfIsColimit G _ _ (coprodIsCoprod X Y) variable [HasBinaryCoproduct (G.obj X) (G.obj Y)] /-- If the coproduct comparison map for `G` at `(X,Y)` is an isomorphism, then `G` preserves the pair of `(X,Y)`. -/ lemma PreservesColimitPair.of_iso_coprod_comparison [i : IsIso (coprodComparison G X Y)] : PreservesColimit (pair X Y) G := by apply preservesColimit_of_preserves_colimit_cocone (coprodIsCoprod X Y) apply (isColimitMapCoconeBinaryCofanEquiv _ _ _).symm _ refine @IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (pair (G.obj X) (G.obj Y))) ?_ apply i variable [PreservesColimit (pair X Y) G] /-- If `G` preserves the coproduct of `(X,Y)`, then the coproduct comparison map for `G` at `(X,Y)` is an isomorphism. -/ def PreservesColimitPair.iso : G.obj X ⨿ G.obj Y ≅ G.obj (X ⨿ Y) := IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitOfHasBinaryCoproductOfPreservesColimit G X Y) @[simp] theorem PreservesColimitPair.iso_hom : (PreservesColimitPair.iso G X Y).hom = coprodComparison G X Y := rfl instance : IsIso (coprodComparison G X Y) := by rw [← PreservesColimitPair.iso_hom] infer_instance /-- If the coproduct comparison maps of `G` at every pair `(X,Y)` is an isomorphism, then `G` preserves binary coproducts. -/ lemma preservesBinaryCoproducts_of_isIso_coprodComparison [HasBinaryCoproducts C] [HasBinaryCoproducts D] [i : ∀ {X Y : C}, IsIso (coprodComparison G X Y)] : PreservesColimitsOfShape (Discrete WalkingPair) G where preservesColimit := by intro K have : PreservesColimit (pair (K.obj ⟨WalkingPair.left⟩) (K.obj ⟨WalkingPair.right⟩)) G := PreservesColimitPair.of_iso_coprod_comparison .. apply preservesColimit_of_iso_diagram G (diagramIsoPair K).symm end end CategoryTheory.Limits
FormalCoproducts.lean
/- Copyright (c) 2025 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Kenny Lau -/ import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Formal Coproducts In this file we construct the category of formal coproducts given a category. ## Main definitions * `FormalCoproduct`: the category of formal coproducts, which are indexed sets of objects in a category. A morphism `∐ i : X.I, X.obj i ⟶ ∐ j : Y.I, Y.obj j` is given by a function `f : X.I → Y.I` and maps `X.obj i ⟶ Y.obj (f i)` for each `i : X.I`. * `FormalCoproduct.eval : (Cᵒᵖ ⥤ A) ⥤ ((FormalCoproduct C)ᵒᵖ ⥤ A)`: the universal property that a presheaf on `C` where the target category has arbitrary coproducts, can be extended to a presheaf on `FormalCoproduct C`. ## TODO * `FormalCoproduct.incl C : C ⥤ FormalCoproduct.{w} C` probably preserves every limit? -/ universe w w₁ w₂ w₃ v v₁ v₂ v₃ u u₁ u₂ u₃ open Opposite CategoryTheory Functor namespace CategoryTheory namespace Limits variable {C : Type u} [Category.{v} C] (A : Type u₁) [Category.{v₁} A] variable (C) in /-- A formal coproduct is an indexed set of objects, where ⟨I, f⟩ corresponds to the "formal coproduct" `⨿ (i : I), f i`, where `f i : C` is the `i`ᵗʰ component. -/ structure FormalCoproduct where /-- The indexing type. -/ I : Type w /-- The object in the original category indexed by `x : I`. -/ obj (i : I) : C namespace FormalCoproduct /-- A morphism `(⨿ (i : X.I), X.obj i) ⟶ (⨿ (j : Y.I), Y.obj i)` is given by first a function on the indexing sets `f : X.I → Y.I`, and then for each `i : X.I` a morphism `X.obj i ⟶ Y.obj (f i)`. -/ structure Hom (X Y : FormalCoproduct.{w} C) where /-- The function on the indexing sets. -/ f : X.I → Y.I /-- The map on each component. -/ φ (i : X.I) : X.obj i ⟶ Y.obj (f i) -- this category identifies to the fullsubcategory of the category of -- presheaves of sets on `C` which are coproducts of representable presheaves @[simps!] instance category : Category (FormalCoproduct.{w} C) where Hom := Hom id X := { f := id, φ := fun _ ↦ 𝟙 _ } comp α β := { f := β.f ∘ α.f, φ := fun _ ↦ α.φ _ ≫ β.φ _ } @[ext (iff := false)] lemma hom_ext {X Y : FormalCoproduct.{w} C} {f g : X ⟶ Y} (h₁ : f.f = g.f) (h₂ : ∀ (i : X.I), f.φ i ≫ eqToHom (by rw [h₁]) = g.φ i) : f = g := by obtain ⟨f, F⟩ := f obtain ⟨g, G⟩ := g obtain rfl : f = g := h₁ obtain rfl : F = G := by ext i; simpa using h₂ i rfl lemma hom_ext_iff {X Y : FormalCoproduct.{w} C} (f g : X ⟶ Y) : f = g ↔ ∃ h₁ : f.f = g.f, ∀ (i : X.I), f.φ i ≫ eqToHom (by rw [h₁]) = g.φ i := ⟨(· ▸ by simp), fun ⟨h₁, h₂⟩ ↦ hom_ext h₁ h₂⟩ lemma hom_ext_iff' {X Y : FormalCoproduct.{w} C} (f g : X ⟶ Y) : f = g ↔ ∀ i : X.I, ∃ h₁ : f.f i = g.f i, f.φ i ≫ eqToHom (by rw [h₁]) = g.φ i := ⟨(· ▸ by simp), fun h ↦ hom_ext (funext fun i ↦ (h i).fst) fun i ↦ (h i).snd⟩ /-- A way to create isomorphisms in the category of formal coproducts, by creating an `Equiv` between the indexing sets, and then correspondingly isomorphisms of each component. -/ @[simps!] def isoOfComponents {X Y : FormalCoproduct.{w} C} (e : X.I ≃ Y.I) (h : ∀ i, X.obj i ≅ Y.obj (e i)) : X ≅ Y where hom := { f := e, φ := fun i ↦ (h i).hom } inv := { f := e.symm, φ := fun i ↦ eqToHom (by simp) ≫ (h (e.symm i)).inv } hom_inv_id := by ext <;> aesop inv_hom_id := by ext <;> aesop variable (C) in /-- An object of the original category produces a formal coproduct on that object only, so indexed by `PUnit`, the type with one element. -/ @[simps!] def incl : C ⥤ FormalCoproduct.{w} C where obj X := ⟨PUnit, fun _ ↦ X⟩ map f := ⟨fun _ ↦ PUnit.unit, fun _ ↦ f⟩ section fromIncl variable {X : C} {Y : FormalCoproduct.{w} C} /-- A map `incl(X) ⟶ Y` is specified by an element of `Y`'s indexing set, and then a morphism `X ⟶ Y.obj i` in the original category. -/ @[simps!] def Hom.fromIncl (i : Y.I) (f : X ⟶ Y.obj i) : (incl C).obj X ⟶ Y := ⟨fun _ ↦ i, fun _ ↦ f⟩ /-- A map `incl(X) ⟶ Y` is specified by an element of `Y`'s indexing set, and then a morphism `X ⟶ Y.obj i` in the original category. -/ def Hom.asSigma (f : (incl C).obj X ⟶ Y) : Σ (i : Y.I), X ⟶ Y.obj i := ⟨f.f PUnit.unit, f.φ PUnit.unit⟩ lemma Hom.fromIncl_asSigma (f : (incl C).obj X ⟶ Y) : Hom.fromIncl f.asSigma.fst f.asSigma.snd = f := by ext <;> aesop end fromIncl -- This is probably some form of adjunction? /-- A map `incl(X) ⟶ Y` is specified by an element of `Y`'s indexing set, and then a morphism `X ⟶ Y.obj i` in the original category. -/ @[simps!] def inclHomEquiv (X : C) (Y : FormalCoproduct.{w} C) : ((incl C).obj X ⟶ Y) ≃ (i : Y.I) × (X ⟶ Y.obj i) where toFun f := f.asSigma invFun f := .fromIncl f.1 f.2 left_inv f := f.fromIncl_asSigma right_inv _ := rfl /-- `incl` is fully faithful, which means that `(X ⟶ Y) ≃ (incl(X) ⟶ incl(Y))`. -/ @[simps!] def fullyFaithfulIncl : (incl C).FullyFaithful where preimage f := f.φ PUnit.unit instance : (incl C).Full := fullyFaithfulIncl.full instance : (incl C).Faithful := fullyFaithfulIncl.faithful /-- A family of maps with the same target can be turned into one arrow in the category of formal coproducts. This is used in Čech cohomology. -/ @[simps!] def homOfPiHom (X : C) {J : Type w} (f : (j : J) → C) (φ : (j : J) → f j ⟶ X) : FormalCoproduct.mk _ f ⟶ (incl C).obj X := ⟨fun _ ↦ PUnit.unit, φ⟩ section Coproduct variable (𝒜 : Type w) (f : 𝒜 → FormalCoproduct.{w} C) (t X : FormalCoproduct.{w} C) /-- We construct explicitly the data that specify the coproduct of a given family of formal coproducts. -/ def cofan : Cofan f := Cofan.mk ⟨(i : 𝒜) × (f i).I, fun p ↦ (f p.1).obj p.2⟩ fun i ↦ ⟨fun x ↦ ⟨i, x⟩, fun x ↦ 𝟙 ((f i).obj x)⟩ section simp_lemmas variable {𝒜 f} theorem cofan_inj (i : 𝒜) : (cofan 𝒜 f).inj i = ⟨fun x ↦ ⟨i, x⟩, fun x ↦ 𝟙 ((f i).obj x)⟩ := rfl @[simp] lemma cofan_inj_f_fst (i : 𝒜) (x) : (((cofan 𝒜 f).inj i).f x).1 = i := rfl @[simp] lemma cofan_inj_f_snd (i : 𝒜) (x) : (((cofan 𝒜 f).inj i).f x).2 = x := rfl @[simp] lemma cofan_inj_φ (i : 𝒜) (x) : ((cofan 𝒜 f).inj i).φ x = 𝟙 ((f i).obj x) := rfl end simp_lemmas /-- The explicit `Equiv` between maps from the constructed coproduct `cofan 𝒜 f` and families of maps from each component, which is the universal property of coproducts. -/ @[simps!] def cofanHomEquiv : ((cofan 𝒜 f).pt ⟶ t) ≃ ((i : 𝒜) → (f i ⟶ t)) where toFun m i := (cofan 𝒜 f).inj i ≫ m invFun s := ⟨fun p ↦ (s p.1).f p.2, fun p ↦ (s p.1).φ p.2⟩ left_inv m := hom_ext rfl (fun ⟨i, x⟩ ↦ by simp [cofan_inj]) right_inv p := by ext <;> simp /-- `cofan 𝒜 f` is a coproduct of `f`. -/ @[simps!] def isColimitCofan : IsColimit (cofan 𝒜 f) := mkCofanColimit (cofan 𝒜 f) (fun t ↦ (cofanHomEquiv _ _ _).symm t.inj) (fun t i ↦ congrFun ((cofanHomEquiv _ _ _).right_inv t.inj) i) (fun _ _ h ↦ (Equiv.eq_symm_apply _).2 (funext h)) instance : HasCoproducts.{w} (FormalCoproduct.{w} C) := hasCoproducts_of_colimit_cofans _ (isColimitCofan _) /-- The arbitrary choice of the coproduct is isomorphic to our constructed coproduct `cofan 𝒜 f`. -/ noncomputable def coproductIsoCofanPt : ∐ f ≅ (cofan 𝒜 f).pt := colimit.isoColimitCocone ⟨_, isColimitCofan _ _⟩ variable {𝒜 f} in @[reassoc (attr := simp)] lemma ι_comp_coproductIsoCofanPt (i) : Sigma.ι f i ≫ (coproductIsoCofanPt 𝒜 f).hom = (cofan 𝒜 f).inj i := colimit.isoColimitCocone_ι_hom _ _ /-- Each `X : FormalCoproduct.{w} C` is actually itself a coproduct of objects of the original category (after coercion using `incl C`). This is the function that specifies the family for which `X` is a coproduct of. -/ def toFun (X : FormalCoproduct.{w} C) : X.I → FormalCoproduct.{w} C := (incl C).obj ∘ X.obj /-- The witness that each `X : FormalCoproduct.{w} C` is itself a coproduct of objects of the original category (after coercion using `incl C`), specified by `X.toFun`. -/ def cofanPtIsoSelf : (cofan X.I X.toFun).pt ≅ X := isoOfComponents (Equiv.sigmaPUnit X.I) fun i ↦ Iso.refl (X.obj i.fst) @[reassoc (attr := simp)] lemma inj_comp_cofanPtIsoSelf_hom (i : X.I) : (cofan X.I X.toFun).inj i ≫ (cofanPtIsoSelf X).hom = .fromIncl i (𝟙 (X.obj i)) := hom_ext rfl (fun i => by aesop) @[reassoc (attr := simp)] lemma fromIncl_comp_cofanPtIsoSelf_inv (i : X.I) : Hom.fromIncl i (𝟙 (X.obj i)) ≫ (cofanPtIsoSelf X).inv = (cofan X.I X.toFun).inj i := (Iso.comp_inv_eq _).2 (inj_comp_cofanPtIsoSelf_hom _ _).symm /-- The isomorphism between the coproduct of `X.toFun` and the object `X` itself. -/ @[simps!] noncomputable def coproductIsoSelf : ∐ X.toFun ≅ X := coproductIsoCofanPt _ _ ≪≫ cofanPtIsoSelf X @[reassoc (attr := simp)] lemma ι_comp_coproductIsoSelf_hom (i : X.I) : Sigma.ι _ i ≫ (coproductIsoSelf X).hom = .fromIncl i (𝟙 (X.obj i)) := by simp [coproductIsoSelf] @[reassoc (attr := simp)] lemma fromIncl_comp_coproductIsoSelf_inv (i : X.I) : Hom.fromIncl i (𝟙 (X.obj i)) ≫ (coproductIsoSelf X).inv = Sigma.ι X.toFun i := (Iso.comp_inv_eq _).2 (ι_comp_coproductIsoSelf_hom _ _).symm end Coproduct section Terminal /-- Given a terminal object `T` in the original category, we show that `incl(T)` is a terminal object in the category of formal coproducts. -/ def isTerminalIncl (T : C) (ht : IsTerminal T) : IsTerminal ((incl C).obj T) := IsTerminal.ofUniqueHom (fun _ ↦ ⟨fun _ ↦ PUnit.unit, fun _ ↦ ht.from _⟩) (fun _ _ ↦ hom_ext (funext fun _ ↦ rfl) (fun _ ↦ ht.hom_ext _ _)) instance [HasTerminal C] : HasTerminal (FormalCoproduct.{w} C) := (isTerminalIncl (⊤_ C) terminalIsTerminal).hasTerminal end Terminal section Pullback variable {X Y Z : FormalCoproduct.{w} C} (f : X ⟶ Z) (g : Y ⟶ Z) (pb : ∀ i : Function.Pullback f.f g.f, PullbackCone (f.φ i.1.1 ≫ eqToHom (by rw [i.2])) (g.φ i.1.2)) (hpb : ∀ i, IsLimit (pb i)) (T : FormalCoproduct.{w} C) /-- Given two morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`, given pullback in `C` over each component, construct the pullback in `FormalCategory.{w} C`. -/ def pullbackCone : PullbackCone f g := .mk (W := ⟨Function.Pullback f.f g.f, fun i ↦ (pb i).pt⟩) ⟨fun i ↦ i.1.fst, fun i ↦ (pb i).fst⟩ ⟨fun i ↦ i.1.snd, fun i ↦ (pb i).snd⟩ (hom_ext (funext fun i ↦ i.2) (fun i ↦ by simp [(pb i).condition])) section simp_lemmas @[simp] lemma pullbackCone_fst_f (i) : (pullbackCone f g pb).fst.f i = i.1.1 := rfl @[simp] lemma pullbackCone_fst_φ (i) : (pullbackCone f g pb).fst.φ i = (pb i).fst := rfl @[simp] lemma pullbackCone_snd_f (i) : (pullbackCone f g pb).snd.f i = i.1.2 := rfl @[simp] lemma pullbackCone_snd_φ (i) : (pullbackCone f g pb).snd.φ i = (pb i).snd := rfl @[simp] lemma pullbackCone_condition : (pullbackCone f g pb).fst ≫ f = (pullbackCone f g pb).snd ≫ g := PullbackCone.condition _ end simp_lemmas /-- The `Equiv` that witnesses that `pullbackCone f g pb` is actually a pullback. This is the universal property of pullbacks. -/ @[simps!] def homPullbackEquiv : (T ⟶ (pullbackCone f g pb).pt) ≃ { p : (T ⟶ X) × (T ⟶ Y) // p.1 ≫ f = p.2 ≫ g } where toFun m := ⟨⟨m ≫ (pullbackCone f g pb).fst, m ≫ (pullbackCone f g pb).snd⟩, by simp⟩ invFun s := ⟨fun i ↦ ⟨(s.1.1.f i, s.1.2.f i), congrFun (congrArg Hom.f s.2) i⟩, fun i ↦ (hpb _).lift (PullbackCone.mk (s.1.1.φ i) (s.1.2.φ i) (by simpa using ((hom_ext_iff _ _).1 s.2).2 i))⟩ left_inv m := hom_ext rfl (fun i ↦ by simp only [category_comp_f, category_comp_φ, eqToHom_refl, Category.comp_id] exact (hpb _).hom_ext ((pb _).equalizer_ext (by aesop) (by aesop))) right_inv s := by ext <;> simp /-- `pullbackCone f g pb` is a pullback. -/ def isLimitPullbackCone : IsLimit (pullbackCone f g pb) := by refine PullbackCone.IsLimit.mk (fst := (pullbackCone f g pb).fst) (snd := (pullbackCone f g pb).snd) _ (fun s ↦ (homPullbackEquiv f g pb hpb s.pt).2 ⟨(s.fst, s.snd), s.condition⟩) (fun s ↦ congrArg (·.1.fst) ((homPullbackEquiv f g pb hpb s.pt).right_inv ⟨(s.fst, s.snd), s.condition⟩)) (fun s ↦ congrArg (·.1.snd) ((homPullbackEquiv f g pb hpb s.pt).right_inv ⟨(s.fst, s.snd), s.condition⟩)) (fun s m h₁ h₂ ↦ ?_) convert ((homPullbackEquiv f g pb hpb s.pt).left_inv m).symm using 3 rw [← h₁, ← h₂]; rfl -- Arguments cannot be inferred. include pb hpb in theorem hasPullback_of_pullbackCone : HasPullback f g := ⟨⟨⟨_, isLimitPullbackCone f g pb hpb⟩⟩⟩ include hpb in lemma isPullback : IsPullback (pullbackCone f g pb).fst (pullbackCone f g pb).snd f g := ⟨⟨pullbackCone_condition f g pb⟩, ⟨isLimitPullbackCone f g pb hpb⟩⟩ omit pb variable [HasPullbacks C] instance : HasPullback f g := hasPullback_of_pullbackCone f g (fun _ ↦ pullback.cone _ _) (fun _ ↦ pullback.isLimit _ _) instance : HasPullbacks (FormalCoproduct.{w} C) := hasPullbacks_of_hasLimit_cospan _ end Pullback noncomputable section HasCoproducts variable [HasCoproducts.{w} A] (C) (J : Type w) (f : J → FormalCoproduct.{w} C) (F : C ⥤ A) /-- A copresheaf valued in a category `A` with arbitrary coproducts, can be extended to the category of formal coproducts. -/ @[simps!] def eval : (C ⥤ A) ⥤ (FormalCoproduct.{w} C ⥤ A) where obj F := { obj X := ∐ fun (i : X.I) ↦ F.obj (X.obj i) map {X Y} f := Sigma.desc fun i ↦ F.map (f.φ i) ≫ Sigma.ι (F.obj ∘ Y.obj) (f.f i) map_comp _ _ := Sigma.hom_ext _ _ (fun _ ↦ by simp [Sigma.ι_desc]) } map α := { app f := Sigma.map fun i ↦ α.app (f.obj i) } /-- `eval(F)` restricted to the original category (via `incl`) is the original copresheaf `F`. -/ @[simps!] def evalCompInclIsoId : eval C A ⋙ (whiskeringLeft _ _ A).obj (incl C) ≅ Functor.id (C ⥤ A) := NatIso.ofComponents fun F ↦ NatIso.ofComponents (fun x ↦ ⟨Sigma.desc fun _ ↦ 𝟙 _, Sigma.ι (fun _ ↦ F.obj x) PUnit.unit, by aesop, by simp⟩) (fun f ↦ Sigma.hom_ext _ _ (by simp [Sigma.ι_desc])) variable {C A} /-- `eval(F)` preserves arbitrary coproducts. -/ def isColimitEvalMapCoconeCofan : IsColimit (((eval.{w} C A).obj F).mapCocone (cofan.{w} J f)) where desc s := Sigma.desc fun i ↦ Sigma.ι (F.obj ∘ (f i.1).obj) i.2 ≫ s.ι.app ⟨i.1⟩ fac s i := Sigma.hom_ext _ _ fun i ↦ by simp [cofan, Function.comp_def] uniq s m h := Sigma.hom_ext _ _ fun ⟨i₁, i₂⟩ ↦ by simp [← h, cofan, Function.comp_def] instance : PreservesColimit (Discrete.functor f) ((eval.{w} C A).obj F) := ⟨fun hc ↦ ⟨IsColimit.ofIsoColimit (isColimitEvalMapCoconeCofan J f F) ((Cocones.functoriality _ _).mapIso ((isColimitCofan J f).uniqueUpToIso hc))⟩⟩ instance : PreservesColimitsOfShape (Discrete J) ((eval.{w} C A).obj F) := preservesColimitsOfShape_of_discrete _ end HasCoproducts noncomputable section HasProducts variable [HasProducts.{w} A] (C) (J : Type w) (f : J → FormalCoproduct.{w} C) (F : Cᵒᵖ ⥤ A) /-- A presheaf valued in a category `A` with arbitrary products can be extended to the category of formal coproducts. -/ @[simps!] def evalOp : (Cᵒᵖ ⥤ A) ⥤ ((FormalCoproduct.{w} C)ᵒᵖ ⥤ A) where obj F := { obj X := ∏ᶜ fun (i : X.unop.I) ↦ F.obj (op (X.unop.obj i)) map f := Pi.lift fun i ↦ Pi.π _ (f.unop.f i) ≫ F.map (f.unop.φ i).op } map α := { app f := Pi.map fun i ↦ α.app (op (f.unop.obj i)) } /-- `evalOp(F)` restricted to the original category (via `incl`) is the original presheaf `F`. -/ @[simps!] def evalOpCompInlIsoId : evalOp C A ⋙ (whiskeringLeft _ _ A).obj (incl C).op ≅ Functor.id (Cᵒᵖ ⥤ A) := NatIso.ofComponents fun F ↦ NatIso.ofComponents fun x ↦ ⟨Pi.π _ PUnit.unit, Pi.lift fun _ ↦ 𝟙 _, by aesop, by simp⟩ variable {C A} /-- `evalOp(F)` preserves arbitrary products. -/ def isLimitEvalMapConeCofanOp : IsLimit (((evalOp.{w} C A).obj F).mapCone (cofan.{w} J f).op) where lift s := Pi.lift fun i ↦ s.π.app ⟨i.1⟩ ≫ Pi.π _ i.2 fac s i := Pi.hom_ext _ _ fun i ↦ by simp [cofan] uniq s m h := Pi.hom_ext _ _ fun ⟨i₁, i₂⟩ ↦ by simp [← h, cofan] instance : PreservesLimit (Discrete.functor (op ∘ f)) ((evalOp.{w} C A).obj F) := ⟨fun hc ↦ ⟨IsLimit.ofIsoLimit (isLimitEvalMapConeCofanOp J f F) ((Cones.functoriality _ _).mapIso ((Cofan.IsColimit.op (isColimitCofan J f)).uniqueUpToIso hc))⟩⟩ end HasProducts end FormalCoproduct end Limits end CategoryTheory
EssentialFiniteness.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Localization.Defs import Mathlib.RingTheory.TensorProduct.Basic /-! # Essentially of finite type algebras ## Main results - `Algebra.EssFiniteType`: The class of essentially of finite type algebras. An `R`-algebra is essentially of finite type if it is the localization of an algebra of finite type. - `Algebra.EssFiniteType.algHom_ext`: The algebra homomorphisms out from an algebra essentially of finite type is determined by its values on a finite set. -/ open scoped TensorProduct namespace Algebra variable (R S T : Type*) [CommRing R] [CommRing S] [CommRing T] variable [Algebra R S] [Algebra R T] /-- An `R`-algebra is essentially of finite type if it is the localization of an algebra of finite type. See `essFiniteType_iff_exists_subalgebra`. -/ class EssFiniteType : Prop where cond : ∃ s : Finset S, IsLocalization ((IsUnit.submonoid S).comap (algebraMap (adjoin R (s : Set S)) S)) S /-- Let `S` be an `R`-algebra essentially of finite type, this is a choice of a finset `s ⊆ S` such that `S` is the localization of `R[s]`. -/ noncomputable def EssFiniteType.finset [h : EssFiniteType R S] : Finset S := h.cond.choose /-- A choice of a subalgebra of finite type in an essentially of finite type algebra, such that its localization is the whole ring. -/ noncomputable abbrev EssFiniteType.subalgebra [EssFiniteType R S] : Subalgebra R S := Algebra.adjoin R (finset R S : Set S) lemma EssFiniteType.adjoin_mem_finset [EssFiniteType R S] : adjoin R { x : subalgebra R S | x.1 ∈ finset R S } = ⊤ := adjoin_adjoin_coe_preimage instance [EssFiniteType R S] : Algebra.FiniteType R (EssFiniteType.subalgebra R S) := by constructor rw [Subalgebra.fg_top, EssFiniteType.subalgebra] exact ⟨_, rfl⟩ /-- A submonoid of `EssFiniteType.subalgebra R S`, whose localization is the whole algebra `S`. -/ noncomputable def EssFiniteType.submonoid [EssFiniteType R S] : Submonoid (EssFiniteType.subalgebra R S) := ((IsUnit.submonoid S).comap (algebraMap (EssFiniteType.subalgebra R S) S)) instance EssFiniteType.isLocalization [h : EssFiniteType R S] : IsLocalization (EssFiniteType.submonoid R S) S := h.cond.choose_spec lemma essFiniteType_cond_iff (σ : Finset S) : IsLocalization ((IsUnit.submonoid S).comap (algebraMap (adjoin R (σ : Set S)) S)) S ↔ (∀ s : S, ∃ t ∈ Algebra.adjoin R (σ : Set S), IsUnit t ∧ s * t ∈ Algebra.adjoin R (σ : Set S)) := by constructor <;> intro hσ · intro s obtain ⟨⟨⟨x, hx⟩, ⟨t, ht⟩, ht'⟩, h⟩ := hσ.2 s exact ⟨t, ht, ht', h ▸ hx⟩ · constructor · exact fun y ↦ y.prop · intro s obtain ⟨t, ht, ht', h⟩ := hσ s exact ⟨⟨⟨_, h⟩, ⟨t, ht⟩, ht'⟩, rfl⟩ · intros x y e exact ⟨1, by simpa using Subtype.ext e⟩ lemma essFiniteType_iff : EssFiniteType R S ↔ ∃ (σ : Finset S), (∀ s : S, ∃ t ∈ Algebra.adjoin R (σ : Set S), IsUnit t ∧ s * t ∈ Algebra.adjoin R (σ : Set S)) := by simp_rw [← essFiniteType_cond_iff] constructor <;> exact fun ⟨a, b⟩ ↦ ⟨a, b⟩ instance EssFiniteType.of_finiteType [FiniteType R S] : EssFiniteType R S := by obtain ⟨s, hs⟩ := ‹FiniteType R S› rw [essFiniteType_iff] exact ⟨s, fun _ ↦ by simpa only [hs, mem_top, and_true, true_and] using ⟨1, isUnit_one⟩⟩ variable {R} in lemma EssFiniteType.of_isLocalization (M : Submonoid R) [IsLocalization M S] : EssFiniteType R S := by rw [essFiniteType_iff] use ∅ simp only [Finset.coe_empty, Algebra.adjoin_empty, Algebra.mem_bot, Set.mem_range, exists_exists_eq_and] intro s obtain ⟨⟨x, t⟩, e⟩ := IsLocalization.surj M s exact ⟨_, IsLocalization.map_units S t, x, e.symm⟩ lemma EssFiniteType.of_id : EssFiniteType R R := inferInstance section variable [Algebra S T] [IsScalarTower R S T] lemma EssFiniteType.aux (σ : Subalgebra R S) (hσ : ∀ s : S, ∃ t ∈ σ, IsUnit t ∧ s * t ∈ σ) (τ : Set T) (t : T) (ht : t ∈ Algebra.adjoin S τ) : ∃ s ∈ σ, IsUnit s ∧ s • t ∈ σ.map (IsScalarTower.toAlgHom R S T) ⊔ Algebra.adjoin R τ := by refine Algebra.adjoin_induction ?_ ?_ ?_ ?_ ht · intro t ht exact ⟨1, Subalgebra.one_mem _, isUnit_one, (one_smul S t).symm ▸ Algebra.mem_sup_right (Algebra.subset_adjoin ht)⟩ · intro s obtain ⟨s', hs₁, hs₂, hs₃⟩ := hσ s refine ⟨_, hs₁, hs₂, Algebra.mem_sup_left ?_⟩ rw [Algebra.smul_def, ← map_mul, mul_comm] exact ⟨_, hs₃, rfl⟩ · rintro x y - - ⟨sx, hsx, hsx', hsx''⟩ ⟨sy, hsy, hsy', hsy''⟩ refine ⟨_, σ.mul_mem hsx hsy, hsx'.mul hsy', ?_⟩ rw [smul_add, mul_smul, mul_smul, Algebra.smul_def sx (sy • y), smul_comm, Algebra.smul_def sy (sx • x)] apply add_mem (mul_mem _ hsx'') (mul_mem _ hsy'') <;> exact Algebra.mem_sup_left ⟨_, ‹_›, rfl⟩ · rintro x y - - ⟨sx, hsx, hsx', hsx''⟩ ⟨sy, hsy, hsy', hsy''⟩ refine ⟨_, σ.mul_mem hsx hsy, hsx'.mul hsy', ?_⟩ rw [mul_smul, ← smul_eq_mul, smul_comm sy x, ← smul_assoc, smul_eq_mul] exact mul_mem hsx'' hsy'' lemma EssFiniteType.comp [h₁ : EssFiniteType R S] [h₂ : EssFiniteType S T] : EssFiniteType R T := by rw [essFiniteType_iff] at h₁ h₂ ⊢ classical obtain ⟨s, hs⟩ := h₁ obtain ⟨t, ht⟩ := h₂ use s.image (IsScalarTower.toAlgHom R S T) ∪ t simp only [Finset.coe_union, Finset.coe_image, Algebra.adjoin_union, Algebra.adjoin_image] intro x obtain ⟨y, hy₁, hy₂, hy₃⟩ := ht x obtain ⟨t₁, h₁, h₂, h₃⟩ := EssFiniteType.aux _ _ _ _ hs _ y hy₁ obtain ⟨t₂, h₄, h₅, h₆⟩ := EssFiniteType.aux _ _ _ _ hs _ _ hy₃ refine ⟨t₂ • t₁ • y, ?_, ?_, ?_⟩ · rw [Algebra.smul_def] exact mul_mem (Algebra.mem_sup_left ⟨_, h₄, rfl⟩) h₃ · rw [Algebra.smul_def, Algebra.smul_def] exact (h₅.map _).mul ((h₂.map _).mul hy₂) · rw [← mul_smul, mul_comm, smul_mul_assoc, mul_comm, mul_comm y, mul_smul, Algebra.smul_def] exact mul_mem (Algebra.mem_sup_left ⟨_, h₁, rfl⟩) h₆ open EssFiniteType in lemma essFiniteType_iff_exists_subalgebra : EssFiniteType R S ↔ ∃ (S₀ : Subalgebra R S) (M : Submonoid S₀), FiniteType R S₀ ∧ IsLocalization M S := by refine ⟨fun h ↦ ⟨subalgebra R S, submonoid R S, inferInstance, inferInstance⟩, ?_⟩ rintro ⟨S₀, M, _, _⟩ letI := of_isLocalization S M exact comp R S₀ S instance EssFiniteType.baseChange [h : EssFiniteType R S] : EssFiniteType T (T ⊗[R] S) := by classical rw [essFiniteType_iff] at h ⊢ obtain ⟨σ, hσ⟩ := h use σ.image Algebra.TensorProduct.includeRight intro s induction s using TensorProduct.induction_on with | zero => exact ⟨1, one_mem _, isUnit_one, by simp⟩ | tmul x y => obtain ⟨t, h₁, h₂, h₃⟩ := hσ y have H (x : S) (hx : x ∈ Algebra.adjoin R (σ : Set S)) : 1 ⊗ₜ[R] x ∈ Algebra.adjoin T ((σ.image Algebra.TensorProduct.includeRight : Finset (T ⊗[R] S)) : Set (T ⊗[R] S)) := by have : Algebra.TensorProduct.includeRight x ∈ (Algebra.adjoin R (σ : Set S)).map (Algebra.TensorProduct.includeRight (A := T)) := Subalgebra.mem_map.mpr ⟨_, hx, rfl⟩ rw [← Algebra.adjoin_adjoin_of_tower R] apply Algebra.subset_adjoin simpa [← Algebra.adjoin_image] using this refine ⟨Algebra.TensorProduct.includeRight t, H _ h₁, h₂.map _, ?_⟩ simp only [Algebra.TensorProduct.includeRight_apply, Algebra.TensorProduct.tmul_mul_tmul, mul_one] rw [← mul_one x, ← smul_eq_mul, ← TensorProduct.smul_tmul'] apply Subalgebra.smul_mem exact H _ h₃ | add x y hx hy => obtain ⟨tx, hx₁, hx₂, hx₃⟩ := hx obtain ⟨ty, hy₁, hy₂, hy₃⟩ := hy refine ⟨_, mul_mem hx₁ hy₁, hx₂.mul hy₂, ?_⟩ rw [add_mul, ← mul_assoc, mul_comm tx ty, ← mul_assoc] exact add_mem (mul_mem hx₃ hy₁) (mul_mem hy₃ hx₁) lemma EssFiniteType.of_comp [h : EssFiniteType R T] : EssFiniteType S T := by rw [essFiniteType_iff] at h ⊢ classical obtain ⟨σ, hσ⟩ := h use σ intro x obtain ⟨y, hy₁, hy₂, hy₃⟩ := hσ x simp_rw [← Algebra.adjoin_adjoin_of_tower R (S := S) (σ : Set T)] exact ⟨y, Algebra.subset_adjoin hy₁, hy₂, Algebra.subset_adjoin hy₃⟩ lemma EssFiniteType.comp_iff [EssFiniteType R S] : EssFiniteType R T ↔ EssFiniteType S T := ⟨fun _ ↦ of_comp R S T, fun _ ↦ comp R S T⟩ instance [EssFiniteType R S] (I : Ideal S) : EssFiniteType R (S ⧸ I) := .comp R S _ instance [EssFiniteType R S] (M : Submonoid S) : EssFiniteType R (Localization M) := have : EssFiniteType S (Localization M) := .of_isLocalization _ M .comp R S _ end variable {R S} in lemma EssFiniteType.algHom_ext [EssFiniteType R S] (f g : S →ₐ[R] T) (H : ∀ s ∈ finset R S, f s = g s) : f = g := by suffices f.toRingHom = g.toRingHom by ext; exact RingHom.congr_fun this _ apply IsLocalization.ringHom_ext (EssFiniteType.submonoid R S) suffices f.comp (IsScalarTower.toAlgHom R _ S) = g.comp (IsScalarTower.toAlgHom R _ S) by ext; exact AlgHom.congr_fun this _ apply AlgHom.ext_of_adjoin_eq_top (s := { x | x.1 ∈ finset R S }) · exact adjoin_mem_finset R S · rintro ⟨x, hx⟩ hx'; exact H x hx' end Algebra namespace RingHom variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] {f : R →+* S} /-- A ring hom is essentially of finite type if it is the composition of a localization map and a ring hom of finite type. See `Algebra.EssFiniteType`. -/ @[algebraize Algebra.EssFiniteType] def EssFiniteType (f : R →+* S) : Prop := letI := f.toAlgebra Algebra.EssFiniteType R S /-- A choice of "essential generators" for a ring hom essentially of finite type. See `Algebra.EssFiniteType.ext`. -/ noncomputable def EssFiniteType.finset (hf : f.EssFiniteType) : Finset S := letI := f.toAlgebra haveI : Algebra.EssFiniteType R S := hf Algebra.EssFiniteType.finset R S lemma FiniteType.essFiniteType (hf : f.FiniteType) : f.EssFiniteType := by algebraize [f] change Algebra.EssFiniteType R S infer_instance lemma EssFiniteType.ext (hf : f.EssFiniteType) {g₁ g₂ : S →+* T} (h₁ : g₁.comp f = g₂.comp f) (h₂ : ∀ x ∈ hf.finset, g₁ x = g₂ x) : g₁ = g₂ := by algebraize [f, g₁.comp f] ext x exact DFunLike.congr_fun (Algebra.EssFiniteType.algHom_ext T ⟨g₁, fun _ ↦ rfl⟩ ⟨g₂, DFunLike.congr_fun h₁.symm⟩ h₂) x end RingHom
classfun.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime order. From mathcomp Require Import ssralg poly finset fingroup morphism perm. From mathcomp Require Import automorphism quotient finalg action gproduct zmodp. From mathcomp Require Import commutator cyclic center pgroup sylow matrix. From mathcomp Require Import vector falgebra ssrnum algC algnum archimedean. (******************************************************************************) (* This file contains the basic theory of class functions: *) (* 'CF(G) == the type of class functions on G : {group gT}, i.e., *) (* which map gT to the type algC of complex algebraics, *) (* have support in G, and are constant on each conjugacy *) (* class of G. 'CF(G) implements the falgType interface of *) (* finite-dimensional F-algebras. *) (* The identity 1 : 'CF(G) is the indicator function of G, *) (* and (later) the principal character. *) (* --> The %CF scope (cfun_scope) is bound to the 'CF(_) types. *) (* 'CF(G)%VS == the (total) vector space of 'CF(G). *) (* 'CF(G, A) == the subspace of functions in 'CF(G) with support in A. *) (* phi x == the image of x : gT under phi : 'CF(G). *) (* #[phi]%CF == the multiplicative order of phi : 'CF(G). *) (* cfker phi == the kernel of phi : 'CF(G); note that cfker phi <| G. *) (* cfaithful phi <=> phi : 'CF(G) is faithful (has a trivial kernel). *) (* '1_A == the indicator function of A as a function of 'CF(G). *) (* (Provided A <| G; G is determined by the context.) *) (* phi^*%CF == the function conjugate to phi : 'CF(G). *) (* cfAut u phi == the function conjugate to phi by an algC-automorphism u *) (* phi^u The notation "_ ^u" is only reserved; it is up to *) (* clients to set Notation "phi ^u" := (cfAut u phi). *) (* '[phi, psi] == the convolution of phi, psi : 'CF(G) over G, normalised *) (* '[phi, psi]_G by #|G| so that '[1, 1]_G = 1 (G is usually inferred). *) (* cfdotr psi phi == '[phi, psi] (self-expanding). *) (* '[phi], '[phi]_G == the squared norm '[phi, phi] of phi : 'CF(G). *) (* orthogonal R S <=> each phi in R : seq 'CF(G) is orthogonal to each psi in *) (* S, i.e., '[phi, psi] = 0. As 'CF(G) coerces to seq, one *) (* can write orthogonal phi S and orthogonal phi psi. *) (* pairwise_orthogonal S <=> the class functions in S are pairwise orthogonal *) (* AND non-zero. *) (* orthonormal S <=> S is pairwise orthogonal and all class functions in S *) (* have norm 1. *) (* isometry tau <-> tau : 'CF(D) -> 'CF(R) is an isometry, mapping *) (* '[_, _]_D to '[_, _]_R. *) (* {in CD, isometry tau, to CR} <-> in the domain CD, tau is an isometry *) (* whose range is contained in CR. *) (* cfReal phi <=> phi is real, i.e., phi^* == phi. *) (* cfAut_closed u S <-> S : seq 'CF(G) is closed under conjugation by u. *) (* cfConjC_closed S <-> S : seq 'CF(G) is closed under complex conjugation. *) (* conjC_subset S1 S2 <-> S1 : seq 'CF(G) represents a subset of S2 closed *) (* under complex conjugation. *) (* := [/\ uniq S1, {subset S1 <= S2} & cfConjC_closed S1]. *) (* 'Res[H] phi == the restriction of phi : 'CF(G) to a function of 'CF(H) *) (* 'Res[H, G] phi 'Res[H] phi x = phi x if x \in H (when H \subset G), *) (* 'Res phi 'Res[H] phi x = 0 if x \notin H. The syntax variants *) (* allow H and G to be inferred; the default is to specify *) (* H explicitly, and infer G from the type of phi. *) (* 'Ind[G] phi == the class function of 'CF(G) induced by phi : 'CF(H), *) (* 'Ind[G, H] phi when H \subset G. As with 'Res phi, both G and H can *) (* 'Ind phi be inferred, though usually G isn't. *) (* cfMorph phi == the class function in 'CF(G) that maps x to phi (f x), *) (* where phi : 'CF(f @* G), provided G \subset 'dom f. *) (* cfIsom isoGR phi == the class function in 'CF(R) that maps f x to phi x, *) (* given isoGR : isom G R f, f : {morphism G >-> rT} and *) (* phi : 'CF(G). *) (* (phi %% H)%CF == special case of cfMorph phi, when phi : 'CF(G / H). *) (* (phi / H)%CF == the class function in 'CF(G / H) that coincides with *) (* phi : 'CF(G) on cosets of H \subset cfker phi. *) (* For a group G that is a semidirect product (defG : K ><| H = G), we have *) (* cfSdprod KxH phi == for phi : 'CF(H), the class function of 'CF(G) that *) (* maps k * h to psi h when k \in K and h \in H. *) (* For a group G that is a direct product (with KxH : K \x H = G), we have *) (* cfDprodl KxH phi == for phi : 'CF(K), the class function of 'CF(G) that *) (* maps k * h to phi k when k \in K and h \in H. *) (* cfDprodr KxH psi == for psi : 'CF(H), the class function of 'CF(G) that *) (* maps k * h to psi h when k \in K and h \in H. *) (* cfDprod KxH phi psi == for phi : 'CF(K), psi : 'CF(H), the class function *) (* of 'CF(G) that maps k * h to phi k * psi h (this is *) (* the product of the two functions above). *) (* Finally, given defG : \big[dprod/1]_(i | P i) A i = G, with G and A i *) (* groups and i ranges over a finType, we have *) (* cfBigdprodi defG phi == for phi : 'CF(A i) s.t. P i, the class function *) (* of 'CF(G) that maps x to phi x_i, where x_i is the *) (* (A i)-component of x : G. *) (* cfBigdprod defG phi == for phi : forall i, 'CF(A i), the class function *) (* of 'CF(G) that maps x to \prod_(i | P i) phi i x_i, *) (* where x_i is the (A i)-component of x : G. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope cfun_scope. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. Delimit Scope cfun_scope with CF. Reserved Notation "''CF' ( G , A )" (format "''CF' ( G , A )"). Reserved Notation "''CF' ( G )" (format "''CF' ( G )"). Reserved Notation "''1_' G" (at level 8, G at level 2, format "''1_' G"). Reserved Notation "''Res[' H , G ]". (* only parsing *) Reserved Notation "''Res[' H ]" (format "''Res[' H ]"). Reserved Notation "''Res'". (* only parsing *) Reserved Notation "''Ind[' G , H ]". (* only parsing *) Reserved Notation "''Ind[' G ]". (* only "''Ind[' G ]" *) Reserved Notation "''Ind'". (* only parsing *) Reserved Notation "'[ phi , psi ]_ G" (at level 0, G at level 2). (* only parsing *) Reserved Notation "'[ phi ]_ G" (at level 0, G at level 2). (* only parsing *) Reserved Notation "phi ^u" (format "phi ^u"). Section AlgC. (* Arithmetic properties of group orders in the characteristic 0 field algC. *) Variable (gT : finGroupType). Implicit Types (G : {group gT}) (B : {set gT}). Lemma neq0CG G : (#|G|)%:R != 0 :> algC. Proof. exact: natrG_neq0. Qed. Lemma neq0CiG G B : (#|G : B|)%:R != 0 :> algC. Proof. exact: natr_indexg_neq0. Qed. Lemma gt0CG G : 0 < #|G|%:R :> algC. Proof. exact: natrG_gt0. Qed. Lemma gt0CiG G B : 0 < #|G : B|%:R :> algC. Proof. exact: natr_indexg_gt0. Qed. Lemma algC'G_pchar G : [pchar algC]^'.-group G. Proof. by apply/pgroupP=> p _; rewrite inE /= pchar_num. Qed. End AlgC. #[deprecated(since="mathcomp 2.4.0", note="Use algC'G_pchar instead.")] Notation algC'G := (algC'G_pchar) (only parsing). Section Defs. Variable gT : finGroupType. Definition is_class_fun (B : {set gT}) (f : {ffun gT -> algC}) := [forall x, forall y in B, f (x ^ y) == f x] && (support f \subset B). Lemma intro_class_fun (G : {group gT}) f : {in G &, forall x y, f (x ^ y) = f x} -> (forall x, x \notin G -> f x = 0) -> is_class_fun G (finfun f). Proof. move=> fJ Gf; apply/andP; split; last first. by apply/supportP=> x notAf; rewrite ffunE Gf. apply/'forall_eqfun_inP=> x y Gy; rewrite !ffunE. by have [/fJ-> // | notGx] := boolP (x \in G); rewrite !Gf ?groupJr. Qed. Variable B : {set gT}. Local Notation G := <<B>>. Record classfun : predArgType := Classfun {cfun_val; _ : is_class_fun G cfun_val}. Implicit Types phi psi xi : classfun. (* The default expansion lemma cfunE requires key = 0. *) Fact classfun_key : unit. Proof. by []. Qed. Definition Cfun := locked_with classfun_key (fun flag : nat => Classfun). HB.instance Definition _ := [isSub for cfun_val]. HB.instance Definition _ := [Choice of classfun by <:]. Definition cfun_eqType : eqType := classfun. Definition fun_of_cfun phi := cfun_val phi : gT -> algC. Coercion fun_of_cfun : classfun >-> Funclass. Lemma cfunElock k f fP : @Cfun k (finfun f) fP =1 f. Proof. by rewrite locked_withE; apply: ffunE. Qed. Lemma cfunE f fP : @Cfun 0 (finfun f) fP =1 f. Proof. exact: cfunElock. Qed. Lemma cfunP phi psi : phi =1 psi <-> phi = psi. Proof. by split=> [/ffunP/val_inj | ->]. Qed. Lemma cfun0gen phi x : x \notin G -> phi x = 0. Proof. by case: phi => f fP; case: (andP fP) => _ /supportP; apply. Qed. Lemma cfun_in_genP phi psi : {in G, phi =1 psi} -> phi = psi. Proof. move=> eq_phi; apply/cfunP=> x. by have [/eq_phi-> // | notAx] := boolP (x \in G); rewrite !cfun0gen. Qed. Lemma cfunJgen phi x y : y \in G -> phi (x ^ y) = phi x. Proof. case: phi => f fP Gy; apply/eqP. by case: (andP fP) => /'forall_forall_inP->. Qed. Fact cfun_zero_subproof : is_class_fun G (0 : {ffun _}). Proof. exact: intro_class_fun. Qed. Definition cfun_zero := Cfun 0 cfun_zero_subproof. Fact cfun_comp_subproof f phi : f 0 = 0 -> is_class_fun G [ffun x => f (phi x)]. Proof. by move=> f0; apply: intro_class_fun => [x y _ /cfunJgen | x /cfun0gen] ->. Qed. Definition cfun_comp f f0 phi := Cfun 0 (@cfun_comp_subproof f phi f0). Definition cfun_opp := cfun_comp (oppr0 _). Fact cfun_add_subproof phi psi : is_class_fun G [ffun x => phi x + psi x]. Proof. apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //. by rewrite !cfun0gen ?add0r. Qed. Definition cfun_add phi psi := Cfun 0 (cfun_add_subproof phi psi). Fact cfun_indicator_subproof (A : {set gT}) : is_class_fun G [ffun x => ((x \in G) && (x ^: G \subset A))%:R]. Proof. apply: intro_class_fun => [x y Gx Gy | x /negbTE/= -> //]. by rewrite groupJr ?classGidl. Qed. Definition cfun_indicator A := Cfun 1 (cfun_indicator_subproof A). Local Notation "''1_' A" := (cfun_indicator A) : ring_scope. Lemma cfun1Egen x : '1_G x = (x \in G)%:R. Proof. by rewrite cfunElock andb_idr // => /class_subG->. Qed. Fact cfun_mul_subproof phi psi : is_class_fun G [ffun x => phi x * psi x]. Proof. apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //. by rewrite cfun0gen ?mul0r. Qed. Definition cfun_mul phi psi := Cfun 0 (cfun_mul_subproof phi psi). Definition cfun_unit := [pred phi : classfun | [forall x in G, phi x != 0]]. Definition cfun_inv phi := if phi \in cfun_unit then cfun_comp (invr0 _) phi else phi. Definition cfun_scale a := cfun_comp (mulr0 a). Fact cfun_addA : associative cfun_add. Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE addrA. Qed. Fact cfun_addC : commutative cfun_add. Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE addrC. Qed. Fact cfun_add0 : left_id cfun_zero cfun_add. Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE add0r. Qed. Fact cfun_addN : left_inverse cfun_zero cfun_opp cfun_add. Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE addNr. Qed. HB.instance Definition _ := GRing.isZmodule.Build classfun cfun_addA cfun_addC cfun_add0 cfun_addN. Lemma muln_cfunE phi n x : (phi *+ n) x = phi x *+ n. Proof. by elim: n => [|n IHn]; rewrite ?mulrS !cfunE ?IHn. Qed. Lemma sum_cfunE I r (P : pred I) (phi : I -> classfun) x : (\sum_(i <- r | P i) phi i) x = \sum_(i <- r | P i) (phi i) x. Proof. by elim/big_rec2: _ => [|i _ psi _ <-]; rewrite cfunE. Qed. Fact cfun_mulA : associative cfun_mul. Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrA. Qed. Fact cfun_mulC : commutative cfun_mul. Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE mulrC. Qed. Fact cfun_mul1 : left_id '1_G cfun_mul. Proof. by move=> phi; apply: cfun_in_genP => x Gx; rewrite !cfunE cfun1Egen Gx mul1r. Qed. Fact cfun_mulD : left_distributive cfun_mul cfun_add. Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed. Fact cfun_nz1 : '1_G != 0. Proof. by apply/eqP=> /cfunP/(_ 1%g)/eqP; rewrite cfun1Egen cfunE group1 oner_eq0. Qed. HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build classfun cfun_mulA cfun_mulC cfun_mul1 cfun_mulD cfun_nz1. Definition cfun_nzRingType : nzRingType := classfun. #[deprecated(since="mathcomp 2.4.0", note="Use cfun_nzRingType instead.")] Notation cfun_ringType := (cfun_nzRingType) (only parsing). Lemma expS_cfunE phi n x : (phi ^+ n.+1) x = phi x ^+ n.+1. Proof. by elim: n => //= n IHn; rewrite !cfunE IHn. Qed. Fact cfun_mulV : {in cfun_unit, left_inverse 1 cfun_inv *%R}. Proof. move=> phi Uphi; rewrite /cfun_inv Uphi; apply/cfun_in_genP=> x Gx. by rewrite !cfunE cfun1Egen Gx mulVf ?(forall_inP Uphi). Qed. Fact cfun_unitP phi psi : psi * phi = 1 -> phi \in cfun_unit. Proof. move/cfunP=> phiK; apply/forall_inP=> x Gx; rewrite -unitfE; apply/unitrP. by exists (psi x); have:= phiK x; rewrite !cfunE cfun1Egen Gx mulrC. Qed. Fact cfun_inv0id : {in [predC cfun_unit], cfun_inv =1 id}. Proof. by rewrite /cfun_inv => phi /negbTE/= ->. Qed. HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build classfun cfun_mulV cfun_unitP cfun_inv0id. Fact cfun_scaleA a b phi : cfun_scale a (cfun_scale b phi) = cfun_scale (a * b) phi. Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed. Fact cfun_scale1 : left_id 1 cfun_scale. Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE mul1r. Qed. Fact cfun_scaleDr : right_distributive cfun_scale +%R. Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunE mulrDr. Qed. Fact cfun_scaleDl phi : {morph cfun_scale^~ phi : a b / a + b}. Proof. by move=> a b; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build algC classfun cfun_scaleA cfun_scale1 cfun_scaleDr cfun_scaleDl. Fact cfun_scaleAl a phi psi : a *: (phi * psi) = (a *: phi) * psi. Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed. Fact cfun_scaleAr a phi psi : a *: (phi * psi) = phi * (a *: psi). Proof. by rewrite !(mulrC phi) cfun_scaleAl. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build algC classfun cfun_scaleAl. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build algC classfun cfun_scaleAr. Section Automorphism. Variable u : {rmorphism algC -> algC}. Definition cfAut := cfun_comp (rmorph0 u). Lemma cfAut_cfun1i A : cfAut '1_A = '1_A. Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed. Lemma cfAutZ a phi : cfAut (a *: phi) = u a *: cfAut phi. Proof. by apply/cfunP=> x; rewrite !cfunE rmorphM. Qed. Lemma cfAut_is_zmod_morphism : zmod_morphism cfAut. Proof. by move=> phi psi; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE /= rmorphB. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfAut_is_zmod_morphism` instead")] Definition cfAut_is_additive := cfAut_is_zmod_morphism. Lemma cfAut_is_monoid_morphism : monoid_morphism cfAut. Proof. by split=> [|phi psi]; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE rmorphM. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfAut_is_monoid_morphism` instead")] Definition cfAut_is_multiplicative := (fun g => (g.2,g.1)) cfAut_is_monoid_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build classfun classfun cfAut cfAut_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build classfun classfun cfAut cfAut_is_monoid_morphism. Lemma cfAut_cfun1 : cfAut 1 = 1. Proof. exact: rmorph1. Qed. Lemma cfAut_scalable : scalable_for (u \; *:%R) cfAut. Proof. by move=> a phi; apply/cfunP=> x; rewrite !cfunE rmorphM. Qed. HB.instance Definition _ := GRing.isScalable.Build algC classfun classfun (u \; *:%R) cfAut cfAut_scalable. Definition cfAut_closed (S : seq classfun) := {in S, forall phi, cfAut phi \in S}. End Automorphism. (* FIX ME this has changed *) Notation conjC := Num.conj_op. Definition cfReal phi := cfAut conjC phi == phi. Definition cfConjC_subset (S1 S2 : seq classfun) := [/\ uniq S1, {subset S1 <= S2} & cfAut_closed conjC S1]. Fact cfun_vect_iso : Vector.axiom #|classes G| classfun. Proof. exists (fun phi => \row_i phi (repr (enum_val i))) => [a phi psi|]. by apply/rowP=> i; rewrite !(mxE, cfunE). set n := #|_|; pose eK x : 'I_n := enum_rank_in (classes1 _) (x ^: G). have rV2vP v : is_class_fun G [ffun x => v (eK x) *+ (x \in G)]. apply: intro_class_fun => [x y Gx Gy | x /negbTE/=-> //]. by rewrite groupJr // /eK classGidl. exists (fun v : 'rV_n => Cfun 0 (rV2vP (v 0))) => [phi | v]. apply/cfun_in_genP=> x Gx; rewrite cfunE Gx mxE enum_rankK_in ?mem_classes //. by have [y Gy ->] := repr_class <<B>> x; rewrite cfunJgen. apply/rowP=> i; rewrite mxE cfunE; have /imsetP[x Gx def_i] := enum_valP i. rewrite def_i; have [y Gy ->] := repr_class <<B>> x. by rewrite groupJ // /eK classGidl // -def_i enum_valK_in. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build algC classfun cfun_vect_iso. Definition cfun_vectType : vectType _ := classfun. Definition cfun_base A : #|classes B ::&: A|.-tuple classfun := [tuple of [seq '1_xB | xB in classes B ::&: A]]. Definition classfun_on A := <<cfun_base A>>%VS. Definition cfdot phi psi := #|B|%:R^-1 * \sum_(x in B) phi x * (psi x)^*. Definition cfdotr psi phi := cfdot phi psi. Definition cfnorm phi := cfdot phi phi. Coercion seq_of_cfun phi := [:: phi]. Definition cforder phi := \big[lcmn/1]_(x in <<B>>) #[phi x]%C. End Defs. Bind Scope cfun_scope with classfun. Arguments classfun {gT} B%_g. Arguments classfun_on {gT} B%_g A%_g. Arguments cfun_indicator {gT} B%_g. Arguments cfAut {gT B%_g} u phi%_CF. Arguments cfReal {gT B%_g} phi%_CF. Arguments cfdot {gT B%_g} phi%_CF psi%_CF. Arguments cfdotr {gT B%_g} psi%_CF phi%_CF /. Arguments cfnorm {gT B%_g} phi%_CF /. Notation "''CF' ( G )" := (classfun G) : type_scope. Notation "''CF' ( G )" := (@fullv _ (cfun_vectType G)) : vspace_scope. Notation "''1_' A" := (cfun_indicator _ A) : ring_scope. Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope. Notation "1" := (@GRing.one (cfun_nzRingType _)) (only parsing) : cfun_scope. (* FIX ME this has changed *) Notation conjC := Num.conj_op. Notation "phi ^*" := (cfAut conjC phi) : cfun_scope. Notation cfConjC_closed := (cfAut_closed conjC). Prenex Implicits cfReal. (* Workaround for overeager projection reduction. *) Notation eqcfP := (@eqP (cfun_eqType _) _ _) (only parsing). Notation "#[ phi ]" := (cforder phi) : cfun_scope. Notation "''[' u , v ]_ G":= (@cfdot _ G u v) (only parsing) : ring_scope. Notation "''[' u , v ]" := (cfdot u v) : ring_scope. Notation "''[' u ]_ G" := '[u, u]_G (only parsing) : ring_scope. Notation "''[' u ]" := '[u, u] : ring_scope. Section Predicates. Variables (gT rT : finGroupType) (D : {set gT}) (R : {set rT}). Implicit Types (phi psi : 'CF(D)) (S : seq 'CF(D)) (tau : 'CF(D) -> 'CF(R)). Definition cfker phi := [set x in D | [forall y, phi (x * y)%g == phi y]]. Definition cfaithful phi := cfker phi \subset [1]. Definition ortho_rec S1 S2 := all [pred phi | all [pred psi | '[phi, psi] == 0] S2] S1. Definition orthogonal := ortho_rec. Arguments orthogonal : simpl never. Fixpoint pair_ortho_rec S := if S is psi :: S' then ortho_rec psi S' && pair_ortho_rec S' else true. (* We exclude 0 from pairwise orthogonal sets. *) Definition pairwise_orthogonal S := (0 \notin S) && pair_ortho_rec S. Definition orthonormal S := all [pred psi | '[psi] == 1] S && pair_ortho_rec S. Definition isometry tau := forall phi psi, '[tau phi, tau psi] = '[phi, psi]. Definition isometry_from_to mCFD tau mCFR := prop_in2 mCFD (inPhantom (isometry tau)) /\ prop_in1 mCFD (inPhantom (forall phi, in_mem (tau phi) mCFR)). End Predicates. Arguments orthogonal : simpl never. Arguments cfker {gT D%_g} phi%_CF. Arguments cfaithful {gT D%_g} phi%_CF. Arguments orthogonal {gT D%_g} S1%_CF S2%_CF. Arguments pairwise_orthogonal {gT D%_g} S%_CF. Arguments orthonormal {gT D%_g} S%_CF. Arguments isometry {gT rT D%_g R%_g} tau%_CF. Notation "{ 'in' CFD , 'isometry' tau , 'to' CFR }" := (isometry_from_to (mem CFD) tau (mem CFR)) (format "{ 'in' CFD , 'isometry' tau , 'to' CFR }") : type_scope. Section ClassFun. Variables (gT : finGroupType) (G : {group gT}). Implicit Types (A B : {set gT}) (H K : {group gT}) (phi psi xi : 'CF(G)). Local Notation "''1_' A" := (cfun_indicator G A). Lemma cfun0 phi x : x \notin G -> phi x = 0. Proof. by rewrite -{1}(genGid G) => /(cfun0gen phi). Qed. Lemma support_cfun phi : support phi \subset G. Proof. by apply/subsetP=> g; apply: contraR => /cfun0->. Qed. Lemma cfunJ phi x y : y \in G -> phi (x ^ y) = phi x. Proof. by rewrite -{1}(genGid G) => /(cfunJgen phi)->. Qed. Lemma cfun_repr phi x : phi (repr (x ^: G)) = phi x. Proof. by have [y Gy ->] := repr_class G x; apply: cfunJ. Qed. Lemma cfun_inP phi psi : {in G, phi =1 psi} -> phi = psi. Proof. by rewrite -{1}genGid => /cfun_in_genP. Qed. Lemma cfuniE A x : A <| G -> '1_A x = (x \in A)%:R. Proof. case/andP=> sAG nAG; rewrite cfunElock genGid. by rewrite class_sub_norm // andb_idl // => /(subsetP sAG). Qed. Lemma support_cfuni A : A <| G -> support '1_A =i A. Proof. by move=> nsAG x; rewrite !inE cfuniE // pnatr_eq0 -lt0n lt0b. Qed. Lemma eq_mul_cfuni A phi : A <| G -> {in A, phi * '1_A =1 phi}. Proof. by move=> nsAG x Ax; rewrite cfunE cfuniE // Ax mulr1. Qed. Lemma eq_cfuni A : A <| G -> {in A, '1_A =1 (1 : 'CF(G))}. Proof. by rewrite -['1_A]mul1r; apply: eq_mul_cfuni. Qed. Lemma cfuniG : '1_G = 1. Proof. by rewrite -[G in '1_G]genGid. Qed. Lemma cfun1E g : (1 : 'CF(G)) g = (g \in G)%:R. Proof. by rewrite -cfuniG cfuniE. Qed. Lemma cfun11 : (1 : 'CF(G)) 1%g = 1. Proof. by rewrite cfun1E group1. Qed. Lemma prod_cfunE I r (P : pred I) (phi : I -> 'CF(G)) x : x \in G -> (\prod_(i <- r | P i) phi i) x = \prod_(i <- r | P i) (phi i) x. Proof. by move=> Gx; elim/big_rec2: _ => [|i _ psi _ <-]; rewrite ?cfunE ?cfun1E ?Gx. Qed. Lemma exp_cfunE phi n x : x \in G -> (phi ^+ n) x = phi x ^+ n. Proof. by rewrite -[n]card_ord -!prodr_const; apply: prod_cfunE. Qed. Lemma mul_cfuni A B : '1_A * '1_B = '1_(A :&: B) :> 'CF(G). Proof. apply/cfunP=> g; rewrite !cfunElock -natrM mulnb subsetI. by rewrite andbCA !andbA andbb. Qed. Lemma cfun_classE x y : '1_(x ^: G) y = ((x \in G) && (y \in x ^: G))%:R. Proof. rewrite cfunElock genGid class_sub_norm ?class_norm //; congr (_ : bool)%:R. by apply: andb_id2r => /imsetP[z Gz ->]; rewrite groupJr. Qed. Lemma cfun_on_sum A : 'CF(G, A) = (\sum_(xG in classes G | xG \subset A) <['1_xG]>)%VS. Proof. by rewrite ['CF(G, A)]span_def big_image; apply: eq_bigl => xG; rewrite !inE. Qed. Lemma cfun_onP A phi : reflect (forall x, x \notin A -> phi x = 0) (phi \in 'CF(G, A)). Proof. apply: (iffP idP) => [/coord_span-> x notAx | Aphi]. set b := cfun_base G A; rewrite sum_cfunE big1 // => i _; rewrite cfunE. have /mapP[xG]: b`_i \in b by rewrite -tnth_nth mem_tnth. rewrite mem_enum => /setIdP[/imsetP[y Gy ->] Ay] ->. by rewrite cfun_classE Gy (contraNF (subsetP Ay x)) ?mulr0. suffices <-: \sum_(xG in classes G) phi (repr xG) *: '1_xG = phi. apply: memv_suml => _ /imsetP[x Gx ->]; rewrite rpredZeq cfun_repr. have [s_xG_A | /subsetPn[_ /imsetP[y Gy ->]]] := boolP (x ^: G \subset A). by rewrite cfun_on_sum [_ \in _](sumv_sup (x ^: G)) ?mem_classes ?orbT. by move/Aphi; rewrite cfunJ // => ->; rewrite eqxx. apply/cfun_inP=> x Gx; rewrite sum_cfunE (bigD1 (x ^: G)) ?mem_classes //=. rewrite cfunE cfun_repr cfun_classE Gx class_refl mulr1. rewrite big1 ?addr0 // => _ /andP[/imsetP[y Gy ->]]; apply: contraNeq. rewrite cfunE cfun_repr cfun_classE Gy mulf_eq0 => /norP[_]. by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->. Qed. Arguments cfun_onP {A phi}. Lemma cfun_on0 A phi x : phi \in 'CF(G, A) -> x \notin A -> phi x = 0. Proof. by move/cfun_onP; apply. Qed. Lemma sum_by_classes (R : nzRingType) (F : gT -> R) : {in G &, forall g h, F (g ^ h) = F g} -> \sum_(g in G) F g = \sum_(xG in classes G) #|xG|%:R * F (repr xG). Proof. move=> FJ; rewrite {1}(partition_big _ _ ((@mem_classes gT)^~ G)) /=. apply: eq_bigr => _ /imsetP[x Gx ->]; have [y Gy ->] := repr_class G x. rewrite mulr_natl -sumr_const FJ {y Gy}//; apply/esym/eq_big=> y /=. apply/idP/andP=> [xGy | [Gy /eqP<-]]; last exact: class_refl. by rewrite (class_eqP xGy) (subsetP (class_subG Gx (subxx _))). by case/imsetP=> z Gz ->; rewrite FJ. Qed. Lemma cfun_base_free A : free (cfun_base G A). Proof. have b_i (i : 'I_#|classes G ::&: A|) : (cfun_base G A)`_i = '1_(enum_val i). by rewrite /enum_val -!tnth_nth tnth_map. apply/freeP => s S0 i; move/cfunP/(_ (repr (enum_val i))): S0. rewrite sum_cfunE (bigD1 i) //= big1 ?addr0 => [|j]. rewrite b_i !cfunE; have /setIdP[/imsetP[x Gx ->] _] := enum_valP i. by rewrite cfun_repr cfun_classE Gx class_refl mulr1. apply: contraNeq; rewrite b_i !cfunE mulf_eq0 => /norP[_]. rewrite -(inj_eq enum_val_inj). have /setIdP[/imsetP[x _ ->] _] := enum_valP i; rewrite cfun_repr. have /setIdP[/imsetP[y Gy ->] _] := enum_valP j; rewrite cfun_classE Gy. by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->. Qed. Lemma dim_cfun : \dim 'CF(G) = #|classes G|. Proof. by rewrite dimvf /dim /= genGid. Qed. Lemma dim_cfun_on A : \dim 'CF(G, A) = #|classes G ::&: A|. Proof. by rewrite (eqnP (cfun_base_free A)) size_tuple. Qed. Lemma dim_cfun_on_abelian A : abelian G -> A \subset G -> \dim 'CF(G, A) = #|A|. Proof. move/abelian_classP=> cGG sAG; rewrite -(card_imset _ set1_inj) dim_cfun_on. apply/eq_card=> xG; rewrite !inE. apply/andP/imsetP=> [[/imsetP[x Gx ->] Ax] | [x Ax ->]] {xG}. by rewrite cGG ?sub1set // in Ax *; exists x. by rewrite -{1}(cGG x) ?mem_classes ?(subsetP sAG) ?sub1set. Qed. Lemma cfuni_on A : '1_A \in 'CF(G, A). Proof. apply/cfun_onP=> x notAx; rewrite cfunElock genGid. by case: andP => // [[_ s_xG_A]]; rewrite (subsetP s_xG_A) ?class_refl in notAx. Qed. Lemma mul_cfuni_on A phi : phi * '1_A \in 'CF(G, A). Proof. by apply/cfun_onP=> x /(cfun_onP (cfuni_on A)) Ax0; rewrite cfunE Ax0 mulr0. Qed. Lemma cfun_onE phi A : (phi \in 'CF(G, A)) = (support phi \subset A). Proof. exact: (sameP cfun_onP supportP). Qed. Lemma cfun_onT phi : phi \in 'CF(G, [set: gT]). Proof. by rewrite cfun_onE. Qed. Lemma cfun_onD1 phi A : (phi \in 'CF(G, A^#)) = (phi \in 'CF(G, A)) && (phi 1%g == 0). Proof. by rewrite !cfun_onE -!(eq_subset (in_set (support _))) subsetD1 !inE negbK. Qed. Lemma cfun_onG phi : phi \in 'CF(G, G). Proof. by rewrite cfun_onE support_cfun. Qed. Lemma cfunD1E phi : (phi \in 'CF(G, G^#)) = (phi 1%g == 0). Proof. by rewrite cfun_onD1 cfun_onG. Qed. Lemma cfunGid : 'CF(G, G) = 'CF(G)%VS. Proof. by apply/vspaceP=> phi; rewrite cfun_onG memvf. Qed. Lemma cfun_onS A B phi : B \subset A -> phi \in 'CF(G, B) -> phi \in 'CF(G, A). Proof. by rewrite !cfun_onE => sBA /subset_trans->. Qed. Lemma cfun_complement A : A <| G -> ('CF(G, A) + 'CF(G, G :\: A)%SET = 'CF(G))%VS. Proof. case/andP=> sAG nAG; rewrite -cfunGid [rhs in _ = rhs]cfun_on_sum. rewrite (bigID (fun B => B \subset A)) /=. congr (_ + _)%VS; rewrite cfun_on_sum; apply: eq_bigl => /= xG. rewrite andbAC; apply/esym/andb_idr=> /andP[/imsetP[x Gx ->] _]. by rewrite class_subG. rewrite -andbA; apply: andb_id2l => /imsetP[x Gx ->]. by rewrite !class_sub_norm ?normsD ?normG // inE andbC. Qed. Lemma cfConjCE phi x : ( phi^* )%CF x = (phi x)^*. Proof. by rewrite cfunE. Qed. Lemma cfConjCK : involutive (fun phi => phi^* )%CF. Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= conjCK. Qed. Lemma cfConjC_cfun1 : ( 1^* )%CF = 1 :> 'CF(G). Proof. exact: rmorph1. Qed. (* Class function kernel and faithful class functions *) Fact cfker_is_group phi : group_set (cfker phi). Proof. apply/group_setP; split=> [|x y]; rewrite !inE ?group1. by apply/forallP=> y; rewrite mul1g. case/andP=> Gx /forallP-Kx /andP[Gy /forallP-Ky]; rewrite groupM //. by apply/forallP=> z; rewrite -mulgA (eqP (Kx _)) Ky. Qed. Canonical cfker_group phi := Group (cfker_is_group phi). Lemma cfker_sub phi : cfker phi \subset G. Proof. by rewrite /cfker setIdE subsetIl. Qed. Lemma cfker_norm phi : G \subset 'N(cfker phi). Proof. apply/subsetP=> z Gz; have phiJz := cfunJ phi _ (groupVr Gz). rewrite inE; apply/subsetP=> _ /imsetP[x /setIdP[Gx /forallP-Kx] ->]. rewrite inE groupJ //; apply/forallP=> y. by rewrite -(phiJz y) -phiJz conjMg conjgK Kx. Qed. Lemma cfker_normal phi : cfker phi <| G. Proof. by rewrite /normal cfker_sub cfker_norm. Qed. Lemma cfkerMl phi x y : x \in cfker phi -> phi (x * y)%g = phi y. Proof. by case/setIdP=> _ /eqfunP->. Qed. Lemma cfkerMr phi x y : x \in cfker phi -> phi (y * x)%g = phi y. Proof. by move=> Kx; rewrite conjgC cfkerMl ?cfunJ ?(subsetP (cfker_sub phi)). Qed. Lemma cfker1 phi x : x \in cfker phi -> phi x = phi 1%g. Proof. by move=> Kx; rewrite -[x]mulg1 cfkerMl. Qed. Lemma cfker_cfun0 : @cfker _ G 0 = G. Proof. apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y. by rewrite !cfunE. Qed. Lemma cfker_add phi psi : cfker phi :&: cfker psi \subset cfker (phi + psi). Proof. apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x. by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl. Qed. Lemma cfker_sum I r (P : pred I) (Phi : I -> 'CF(G)) : G :&: \bigcap_(i <- r | P i) cfker (Phi i) \subset cfker (\sum_(i <- r | P i) Phi i). Proof. elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun0. by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_add _ _). Qed. Lemma cfker_scale a phi : cfker phi \subset cfker (a *: phi). Proof. apply/subsetP=> x Kphi_x; have [Gx _] := setIdP Kphi_x. by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE cfkerMl. Qed. Lemma cfker_scale_nz a phi : a != 0 -> cfker (a *: phi) = cfker phi. Proof. move=> nz_a; apply/eqP. by rewrite eqEsubset -{2}(scalerK nz_a phi) !cfker_scale. Qed. Lemma cfker_opp phi : cfker (- phi) = cfker phi. Proof. by rewrite -scaleN1r cfker_scale_nz // oppr_eq0 oner_eq0. Qed. Lemma cfker_cfun1 : @cfker _ G 1 = G. Proof. apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y. by rewrite !cfun1E groupMl. Qed. Lemma cfker_mul phi psi : cfker phi :&: cfker psi \subset cfker (phi * psi). Proof. apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x. by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl. Qed. Lemma cfker_prod I r (P : pred I) (Phi : I -> 'CF(G)) : G :&: \bigcap_(i <- r | P i) cfker (Phi i) \subset cfker (\prod_(i <- r | P i) Phi i). Proof. elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun1. by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_mul _ _). Qed. Lemma cfaithfulE phi : cfaithful phi = (cfker phi \subset [1]). Proof. by []. Qed. End ClassFun. Arguments classfun_on {gT} B%_g A%_g. Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope. Arguments cfun_onP {gT G A phi}. Arguments cfConjCK {gT G} phi : rename. #[global] Hint Resolve cfun_onT : core. Section DotProduct. Variable (gT : finGroupType) (G : {group gT}). Implicit Types (M : {group gT}) (phi psi xi : 'CF(G)) (R S : seq 'CF(G)). Lemma cfdotE phi psi : '[phi, psi] = #|G|%:R^-1 * \sum_(x in G) phi x * (psi x)^*. Proof. by []. Qed. Lemma cfdotElr A B phi psi : phi \in 'CF(G, A) -> psi \in 'CF(G, B) -> '[phi, psi] = #|G|%:R^-1 * \sum_(x in A :&: B) phi x * (psi x)^*. Proof. move=> Aphi Bpsi; rewrite (big_setID G)/= cfdotE (big_setID (A :&: B))/= setIC. congr (_ * (_ + _)); rewrite !big1 // => x /setDP[_]. by move/cfun0->; rewrite mul0r. rewrite inE; case/nandP=> notABx; first by rewrite (cfun_on0 Aphi) ?mul0r. by rewrite (cfun_on0 Bpsi) // rmorph0 mulr0. Qed. Lemma cfdotEl A phi psi : phi \in 'CF(G, A) -> '[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*. Proof. by move=> Aphi; rewrite (cfdotElr Aphi (cfun_onT psi)) setIT. Qed. Lemma cfdotEr A phi psi : psi \in 'CF(G, A) -> '[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*. Proof. by move=> Apsi; rewrite (cfdotElr (cfun_onT phi) Apsi) setTI. Qed. Lemma cfdot_complement A phi psi : phi \in 'CF(G, A) -> psi \in 'CF(G, G :\: A) -> '[phi, psi] = 0. Proof. move=> Aphi A'psi; rewrite (cfdotElr Aphi A'psi). by rewrite setDE setICA setICr setI0 big_set0 mulr0. Qed. Lemma cfnormE A phi : phi \in 'CF(G, A) -> '[phi] = #|G|%:R^-1 * (\sum_(x in A) `|phi x| ^+ 2). Proof. by move/cfdotEl->; rewrite (eq_bigr _ (fun _ _ => normCK _)). Qed. Lemma eq_cfdotl A phi1 phi2 psi : psi \in 'CF(G, A) -> {in A, phi1 =1 phi2} -> '[phi1, psi] = '[phi2, psi]. Proof. move/cfdotEr=> eq_dot eq_phi; rewrite !eq_dot; congr (_ * _). by apply: eq_bigr => x Ax; rewrite eq_phi. Qed. Lemma cfdot_cfuni A B : A <| G -> B <| G -> '['1_A, '1_B]_G = #|A :&: B|%:R / #|G|%:R. Proof. move=> nsAG nsBG; rewrite (cfdotElr (cfuni_on G A) (cfuni_on G B)) mulrC. congr (_ / _); rewrite -sumr_const; apply: eq_bigr => x /setIP[Ax Bx]. by rewrite !cfuniE // Ax Bx mul1r rmorph1. Qed. Lemma cfnorm1 : '[1]_G = 1. Proof. by rewrite cfdot_cfuni ?genGid // setIid divff ?neq0CG. Qed. Lemma cfdotrE psi phi : cfdotr psi phi = '[phi, psi]. Proof. by []. Qed. Lemma cfdotr_is_linear xi : linear (cfdotr xi : 'CF(G) -> algC^o). Proof. move=> a phi psi; rewrite scalerAr -mulrDr; congr (_ * _). rewrite linear_sum -big_split; apply: eq_bigr => x _ /=. by rewrite !cfunE mulrDl -mulrA. Qed. HB.instance Definition _ xi := GRing.isSemilinear.Build algC _ _ _ (cfdotr xi) (GRing.semilinear_linear (cfdotr_is_linear xi)). Lemma cfdot0l xi : '[0, xi] = 0. Proof. by rewrite -cfdotrE linear0. Qed. Lemma cfdotNl xi phi : '[- phi, xi] = - '[phi, xi]. Proof. by rewrite -!cfdotrE linearN. Qed. Lemma cfdotDl xi phi psi : '[phi + psi, xi] = '[phi, xi] + '[psi, xi]. Proof. by rewrite -!cfdotrE linearD. Qed. Lemma cfdotBl xi phi psi : '[phi - psi, xi] = '[phi, xi] - '[psi, xi]. Proof. by rewrite -!cfdotrE linearB. Qed. Lemma cfdotMnl xi phi n : '[phi *+ n, xi] = '[phi, xi] *+ n. Proof. by rewrite -!cfdotrE linearMn. Qed. Lemma cfdot_suml xi I r (P : pred I) (phi : I -> 'CF(G)) : '[\sum_(i <- r | P i) phi i, xi] = \sum_(i <- r | P i) '[phi i, xi]. Proof. by rewrite -!cfdotrE linear_sum. Qed. Lemma cfdotZl xi a phi : '[a *: phi, xi] = a * '[phi, xi]. Proof. by rewrite -!cfdotrE linearZ. Qed. Lemma cfdotC phi psi : '[phi, psi] = ('[psi, phi])^*. Proof. rewrite /cfdot rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _). by apply: eq_bigr=> x _; rewrite rmorphM /= conjCK mulrC. Qed. Lemma eq_cfdotr A phi psi1 psi2 : phi \in 'CF(G, A) -> {in A, psi1 =1 psi2} -> '[phi, psi1] = '[phi, psi2]. Proof. by move=> Aphi /eq_cfdotl eq_dot; rewrite cfdotC eq_dot // -cfdotC. Qed. Lemma cfdotBr xi phi psi : '[xi, phi - psi] = '[xi, phi] - '[xi, psi]. Proof. by rewrite !(cfdotC xi) -rmorphB cfdotBl. Qed. HB.instance Definition _ xi := GRing.isZmodMorphism.Build _ _ (cfdot xi) (cfdotBr xi). Lemma cfdot0r xi : '[xi, 0] = 0. Proof. exact: raddf0. Qed. Lemma cfdotNr xi phi : '[xi, - phi] = - '[xi, phi]. Proof. exact: raddfN. Qed. Lemma cfdotDr xi phi psi : '[xi, phi + psi] = '[xi, phi] + '[xi, psi]. Proof. exact: raddfD. Qed. Lemma cfdotMnr xi phi n : '[xi, phi *+ n] = '[xi, phi] *+ n. Proof. exact: raddfMn. Qed. Lemma cfdot_sumr xi I r (P : pred I) (phi : I -> 'CF(G)) : '[xi, \sum_(i <- r | P i) phi i] = \sum_(i <- r | P i) '[xi, phi i]. Proof. exact: raddf_sum. Qed. Lemma cfdotZr a xi phi : '[xi, a *: phi] = a^* * '[xi, phi]. Proof. by rewrite !(cfdotC xi) cfdotZl rmorphM. Qed. Lemma cfdot_cfAut (u : {rmorphism algC -> algC}) phi psi : {in image psi G, {morph u : x / x^*}} -> '[cfAut u phi, cfAut u psi] = u '[phi, psi]. Proof. move=> uC; rewrite rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _). by apply: eq_bigr => x Gx; rewrite !cfunE rmorphM /= uC ?map_f ?mem_enum. Qed. Lemma cfdot_conjC phi psi : '[phi^*, psi^*] = '[phi, psi]^*. Proof. by rewrite cfdot_cfAut. Qed. Lemma cfdot_conjCl phi psi : '[phi^*, psi] = '[phi, psi^*]^*. Proof. by rewrite -cfdot_conjC cfConjCK. Qed. Lemma cfdot_conjCr phi psi : '[phi, psi^*] = '[phi^*, psi]^*. Proof. by rewrite -cfdot_conjC cfConjCK. Qed. Lemma cfnorm_ge0 phi : 0 <= '[phi]. Proof. by rewrite mulr_ge0 ?invr_ge0 ?ler0n ?sumr_ge0 // => x _; apply: mul_conjC_ge0. Qed. Lemma cfnorm_eq0 phi : ('[phi] == 0) = (phi == 0). Proof. apply/idP/eqP=> [|->]; last by rewrite cfdot0r. rewrite mulf_eq0 invr_eq0 (negbTE (neq0CG G)) /= => /eqP/psumr_eq0P phi0. apply/cfun_inP=> x Gx; apply/eqP; rewrite cfunE -mul_conjC_eq0. by rewrite phi0 // => y _; apply: mul_conjC_ge0. Qed. Lemma cfnorm_gt0 phi : ('[phi] > 0) = (phi != 0). Proof. by rewrite lt_def cfnorm_ge0 cfnorm_eq0 andbT. Qed. Lemma sqrt_cfnorm_ge0 phi : 0 <= sqrtC '[phi]. Proof. by rewrite sqrtC_ge0 cfnorm_ge0. Qed. Lemma sqrt_cfnorm_eq0 phi : (sqrtC '[phi] == 0) = (phi == 0). Proof. by rewrite sqrtC_eq0 cfnorm_eq0. Qed. Lemma sqrt_cfnorm_gt0 phi : (sqrtC '[phi] > 0) = (phi != 0). Proof. by rewrite sqrtC_gt0 cfnorm_gt0. Qed. Lemma cfnormZ a phi : '[a *: phi]= `|a| ^+ 2 * '[phi]_G. Proof. by rewrite cfdotZl cfdotZr mulrA normCK. Qed. Lemma cfnormN phi : '[- phi] = '[phi]. Proof. by rewrite cfdotNl raddfN opprK. Qed. Lemma cfnorm_sign n phi : '[(-1) ^+ n *: phi] = '[phi]. Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?cfnormN. Qed. Lemma cfnormD phi psi : let d := '[phi, psi] in '[phi + psi] = '[phi] + '[psi] + ( d + d^* ). Proof. by rewrite /= addrAC -cfdotC cfdotDl !cfdotDr !addrA. Qed. Lemma cfnormB phi psi : let d := '[phi, psi] in '[phi - psi] = '[phi] + '[psi] - ( d + d^* ). Proof. by rewrite /= cfnormD cfnormN cfdotNr rmorphN -opprD. Qed. Lemma cfnormDd phi psi : '[phi, psi] = 0 -> '[phi + psi] = '[phi] + '[psi]. Proof. by move=> ophipsi; rewrite cfnormD ophipsi rmorph0 !addr0. Qed. Lemma cfnormBd phi psi : '[phi, psi] = 0 -> '[phi - psi] = '[phi] + '[psi]. Proof. by move=> ophipsi; rewrite cfnormDd ?cfnormN // cfdotNr ophipsi oppr0. Qed. Lemma cfnorm_conjC phi : '[phi^*] = '[phi]. Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed. Lemma cfCauchySchwarz phi psi : `|'[phi, psi]| ^+ 2 <= '[phi] * '[psi] ?= iff ~~ free (phi :: psi). Proof. rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. have [-> | nz_psi] /= := eqVneq psi 0. by apply/leifP; rewrite !cfdot0r normCK mul0r mulr0. without loss ophi: phi / '[phi, psi] = 0. move=> IHo; pose a := '[phi, psi] / '[psi]; pose phi1 := phi - a *: psi. have ophi: '[phi1, psi] = 0. by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr. rewrite (canRL (subrK _) (erefl phi1)) rpredDr ?rpredZ ?memv_line //. rewrite cfdotDl ophi add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)). rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ophi mulr0. by have:= IHo _ ophi; rewrite mulrDl -leifBLR subrr ophi normCK mul0r. rewrite ophi normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0. rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_psi) /=. apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ophi mulr0. by rewrite cfnorm_eq0 => /eqP->; apply: rpred0. Qed. Lemma cfCauchySchwarz_sqrt phi psi : `|'[phi, psi]| <= sqrtC '[phi] * sqrtC '[psi] ?= iff ~~ free (phi :: psi). Proof. rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?qualifE/= ?cfnorm_ge0 //. rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM ?qualifE/= ?cfnorm_ge0 //; [ exact: cfCauchySchwarz | exact: O.. ]. Qed. Lemma cf_triangle_leif phi psi : sqrtC '[phi + psi] <= sqrtC '[phi] + sqrtC '[psi] ?= iff ~~ free (phi :: psi) && (0 <= coord [tuple psi] 0 phi). Proof. rewrite -(mono_in_leif ler_sqr) ?rpredD ?qualifE/= ?sqrtC_ge0 ?cfnorm_ge0 //; [| exact: O.. ]. rewrite andbC sqrrD !sqrtCK addrAC cfnormD (mono_leif (lerD2l _)). rewrite -mulr_natr -[_ + _](divfK (negbT (eqC_nat 2 0))) -/('Re _). rewrite (mono_leif (ler_pM2r _)) ?ltr0n //. have:= leif_trans (leif_Re_Creal '[phi, psi]) (cfCauchySchwarz_sqrt phi psi). congr (_ <= _ ?= iff _); first by rewrite ReE. apply: andb_id2r; rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC /=. have [-> | nz_psi] := eqVneq psi 0; first by rewrite cfdot0r coord0. case/vlineP=> [x ->]; rewrite cfdotZl linearZ pmulr_lge0 ?cfnorm_gt0 //=. by rewrite (coord_free 0) ?seq1_free // eqxx mulr1. Qed. Lemma orthogonal_cons phi R S : orthogonal (phi :: R) S = orthogonal phi S && orthogonal R S. Proof. by rewrite /orthogonal /= andbT. Qed. Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal phi psi). Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed. Lemma orthogonalP S R : reflect {in S & R, forall phi psi, '[phi, psi] = 0} (orthogonal S R). Proof. apply: (iffP allP) => oSR phi => [psi /oSR/allP opS /opS/eqP // | /oSR opS]. by apply/allP=> psi /= /opS->. Qed. Lemma orthoPl phi S : reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal phi S). Proof. by rewrite [orthogonal _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP. Qed. Arguments orthoPl {phi S}. Lemma orthogonal_sym : symmetric (@orthogonal _ G). Proof. apply: symmetric_from_pre => R S /orthogonalP oRS. by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite cfdotC oRS ?rmorph0. Qed. Lemma orthoPr S psi : reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal S psi). Proof. rewrite orthogonal_sym. by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite cfdotC oSpsi ?conjC0. Qed. Lemma eq_orthogonal R1 R2 S1 S2 : R1 =i R2 -> S1 =i S2 -> orthogonal R1 S1 = orthogonal R2 S2. Proof. move=> eqR eqS; rewrite [orthogonal _ _](eq_all_r eqR). by apply: eq_all => psi /=; apply: eq_all_r. Qed. Lemma orthogonal_catl R1 R2 S : orthogonal (R1 ++ R2) S = orthogonal R1 S && orthogonal R2 S. Proof. exact: all_cat. Qed. Lemma orthogonal_catr R S1 S2 : orthogonal R (S1 ++ S2) = orthogonal R S1 && orthogonal R S2. Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed. Lemma span_orthogonal S1 S2 phi1 phi2 : orthogonal S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS -> '[phi1, phi2] = 0. Proof. move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->. rewrite cfdot_suml big1 // => i _; rewrite cfdot_sumr big1 // => j _. by rewrite cfdotZl cfdotZr oS12 ?mem_nth ?mulr0. Qed. Lemma orthogonal_split S beta : {X : 'CF(G) & X \in <<S>>%VS & {Y | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal Y S]}}. Proof. suffices [X S_X [Y -> oYS]]: {X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal Y S}}. - exists X => //; exists Y. by rewrite cfdotC (span_orthogonal oYS) ?memv_span1 ?conjC0. elim: S beta => [|phi S IHS] beta. by exists 0; last exists beta; rewrite ?mem0v ?add0r. have [[U S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta). pose Z := '[Y, V] / '[V] *: V; exists (X + Z). rewrite /Z -{4}(addKr U V) scalerDr scalerN addrA addrC span_cons. by rewrite memv_add ?memvB ?memvZ ?memv_line. exists (Y - Z); first by rewrite addrCA !addrA addrK addrC. apply/orthoPl=> psi /[!inE] /predU1P[-> | Spsi]; last first. by rewrite cfdotBl cfdotZl (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS). rewrite cfdotBl !cfdotDr (span_orthogonal oYS) // ?memv_span ?mem_head //. rewrite !cfdotZl (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //. have [-> | nzV] := eqVneq V 0; first by rewrite cfdot0r !mul0r subrr. by rewrite divfK ?cfnorm_eq0 ?subrr. Qed. Lemma map_orthogonal M (nu : 'CF(G) -> 'CF(M)) S R (A : {pred 'CF(G)}) : {in A &, isometry nu} -> {subset S <= A} -> {subset R <= A} -> orthogonal (map nu S) (map nu R) = orthogonal S R. Proof. move=> Inu sSA sRA; rewrite [orthogonal _ _]all_map. apply: eq_in_all => phi Sphi; rewrite /= all_map. by apply: eq_in_all => psi Rpsi; rewrite /= Inu ?(sSA phi) ?(sRA psi). Qed. Lemma orthogonal_oppr S R : orthogonal S (map -%R R) = orthogonal S R. Proof. wlog suffices IH: S R / orthogonal S R -> orthogonal S (map -%R R). by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK. move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->]. by rewrite cfdotNr oSR ?oppr0. Qed. Lemma orthogonal_oppl S R : orthogonal (map -%R S) R = orthogonal S R. Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed. Lemma pairwise_orthogonalP S : reflect (uniq (0 :: S) /\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0}) (pairwise_orthogonal S). Proof. rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case. elim: S notS0 => [|phi S IH] /=; first by left. rewrite inE eq_sym andbT => /norP[nz_phi /IH{}IH]. have [opS | not_opS] := allP; last first. right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=. by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp). rewrite (contra (opS _)) /= ?cfnorm_eq0 //. apply: (iffP IH) => [] [uniqS oSS]; last first. by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead. split=> // psi xi /[!inE] /predU1P[-> // | Spsi]. by case/predU1P=> [-> | /opS] /eqP. case/predU1P=> [-> _ | Sxi /oSS-> //]. by apply/eqP; rewrite cfdotC conjC_eq0 [_ == 0]opS. Qed. Lemma pairwise_orthogonal_cat R S : pairwise_orthogonal (R ++ S) = [&& pairwise_orthogonal R, pairwise_orthogonal S & orthogonal R S]. Proof. rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr. elim: R => [|phi R /= ->]; rewrite ?andbT // orthogonal_cons all_cat -!andbA /=. by do !bool_congr. Qed. Lemma eq_pairwise_orthogonal R S : perm_eq R S -> pairwise_orthogonal R = pairwise_orthogonal S. Proof. apply: catCA_perm_subst R S => R S S'. rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA. by do !bool_congr. Qed. Lemma sub_pairwise_orthogonal S1 S2 : {subset S1 <= S2} -> uniq S1 -> pairwise_orthogonal S2 -> pairwise_orthogonal S1. Proof. move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2]. apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //. by split=> //; apply: sub_in2 oS2. Qed. Lemma orthogonal_free S : pairwise_orthogonal S -> free S. Proof. case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS]. rewrite -(in_tupleE S); apply/freeP => a aS0 i. have S_i: S`_i \in S by apply: mem_nth. have /eqP: '[S`_i, 0]_G = 0 := cfdot0r _. rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first. by rewrite cfdotZr oSS ?mulr0 ?mem_nth // eq_sym nth_uniq. rewrite addr0 cfdotZr mulf_eq0 conjC_eq0 cfnorm_eq0. by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0. Qed. Lemma filter_pairwise_orthogonal S p : pairwise_orthogonal S -> pairwise_orthogonal (filter p S). Proof. move=> orthoS; apply: sub_pairwise_orthogonal (orthoS). exact: mem_subseq (filter_subseq p S). exact/filter_uniq/free_uniq/orthogonal_free. Qed. Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S. Proof. by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= cfdot0r eq_sym oner_eq0. Qed. Lemma orthonormalE S : orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S. Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed. Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S. Proof. by rewrite orthonormalE => /andP[_]. Qed. Lemma orthonormal_cat R S : orthonormal (R ++ S) = [&& orthonormal R, orthonormal S & orthogonal R S]. Proof. rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA. by do !bool_congr. Qed. Lemma eq_orthonormal R S : perm_eq R S -> orthonormal R = orthonormal S. Proof. move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)). by rewrite (eq_pairwise_orthogonal eqRS). Qed. Lemma orthonormal_free S : orthonormal S -> free S. Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed. Lemma orthonormalP S : reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi]_G = (phi == psi)%:R}) (orthonormal S). Proof. rewrite orthonormalE; have [/= normS | not_normS] := allP; last first. by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx. apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS]. split=> // [|phi psi]; first by case/andP: uniqS. by have [-> _ /normS/eqP | /oSS] := eqVneq. split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->. by rewrite /= (contra (normS _)) // cfdot0r eq_sym oner_eq0. Qed. Lemma sub_orthonormal S1 S2 : {subset S1 <= S2} -> uniq S1 -> orthonormal S2 -> orthonormal S1. Proof. move=> sS12 uniqS1 /orthonormalP[_ oS1]. by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _. Qed. Lemma orthonormal2P phi psi : reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1] (orthonormal [:: phi; psi]). Proof. rewrite /orthonormal /= !andbT andbC. by apply: (iffP and3P) => [] []; do 3!move/eqP->. Qed. Lemma conjC_pair_orthogonal S chi : cfConjC_closed S -> ~~ has cfReal S -> pairwise_orthogonal S -> chi \in S -> pairwise_orthogonal (chi :: chi^*%CF). Proof. move=> ccS /hasPn nrS oSS Schi; apply: sub_pairwise_orthogonal oSS. by apply/allP; rewrite /= Schi ccS. by rewrite /= inE eq_sym nrS. Qed. Lemma cfdot_real_conjC phi psi : cfReal phi -> '[phi, psi^*]_G = '[phi, psi]^*. Proof. by rewrite -cfdot_conjC => /eqcfP->. Qed. Lemma extend_cfConjC_subset S X phi : cfConjC_closed S -> ~~ has cfReal S -> phi \in S -> phi \notin X -> cfConjC_subset X S -> cfConjC_subset [:: phi, phi^* & X]%CF S. Proof. move=> ccS nrS Sphi X'phi [uniqX /allP-sXS ccX]. split; last 1 [by apply/allP; rewrite /= Sphi ccS | apply/allP]; rewrite /= inE. by rewrite negb_or X'phi eq_sym (hasPn nrS) // (contra (ccX _)) ?cfConjCK. by rewrite cfConjCK !mem_head orbT; apply/allP=> xi Xxi; rewrite !inE ccX ?orbT. Qed. (* Note: other isometry lemmas, and the dot product lemmas for orthogonal *) (* and orthonormal sequences are in vcharacter, because we need the 'Z[S] *) (* notation for the isometry domains. Alternatively, this could be moved to *) (* cfun. *) End DotProduct. Arguments orthoP {gT G phi psi}. Arguments orthoPl {gT G phi S}. Arguments orthoPr {gT G S psi}. Arguments orthogonalP {gT G S R}. Arguments pairwise_orthogonalP {gT G S}. Arguments orthonormalP {gT G S}. Section CfunOrder. Variables (gT : finGroupType) (G : {group gT}) (phi : 'CF(G)). Lemma dvdn_cforderP n : reflect {in G, forall x, phi x ^+ n = 1} (#[phi]%CF %| n)%N. Proof. apply: (iffP (dvdn_biglcmP _ _ _)); rewrite genGid => phiG1 x Gx. by apply/eqP; rewrite -dvdn_orderC phiG1. by rewrite dvdn_orderC phiG1. Qed. Lemma dvdn_cforder n : (#[phi]%CF %| n) = (phi ^+ n == 1). Proof. apply/dvdn_cforderP/eqP=> phi_n_1 => [|x Gx]. by apply/cfun_inP=> x Gx; rewrite exp_cfunE // cfun1E Gx phi_n_1. by rewrite -exp_cfunE // phi_n_1 // cfun1E Gx. Qed. Lemma exp_cforder : phi ^+ #[phi]%CF = 1. Proof. by apply/eqP; rewrite -dvdn_cforder. Qed. End CfunOrder. Arguments dvdn_cforderP {gT G phi n}. Section MorphOrder. Variables (aT rT : finGroupType) (G : {group aT}) (R : {group rT}). Variable f : {rmorphism 'CF(G) -> 'CF(R)}. Lemma cforder_rmorph phi : #[f phi]%CF %| #[phi]%CF. Proof. by rewrite dvdn_cforder -rmorphXn exp_cforder rmorph1. Qed. Lemma cforder_inj_rmorph phi : injective f -> #[f phi]%CF = #[phi]%CF. Proof. move=> inj_f; apply/eqP; rewrite eqn_dvd cforder_rmorph dvdn_cforder /=. by rewrite -(rmorph_eq1 _ inj_f) rmorphXn exp_cforder. Qed. End MorphOrder. Section BuildIsometries. Variable (gT : finGroupType) (L G : {group gT}). Implicit Types (phi psi xi : 'CF(L)) (R S : seq 'CF(L)). Implicit Types (U : {pred 'CF(L)}) (W : {pred 'CF(G)}). Lemma sub_iso_to U1 U2 W1 W2 tau : {subset U2 <= U1} -> {subset W1 <= W2} -> {in U1, isometry tau, to W1} -> {in U2, isometry tau, to W2}. Proof. by move=> sU sW [Itau Wtau]; split=> [|u /sU/Wtau/sW //]; apply: sub_in2 Itau. Qed. Lemma isometry_of_free S f : free S -> {in S &, isometry f} -> {tau : {linear 'CF(L) -> 'CF(G)} | {in S, tau =1 f} & {in <<S>>%VS &, isometry tau}}. Proof. move=> freeS If; have defS := free_span freeS. have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S). have{} Dtau: {in S, tau =1 f}. by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau. exists tau => // _ _ /defS[a -> _] /defS[b -> _]. rewrite !{1}linear_sum !{1}cfdot_suml; apply/eq_big_seq=> xi1 Sxi1. rewrite !{1}cfdot_sumr; apply/eq_big_seq=> xi2 Sxi2. by rewrite !linearZ /= !Dtau // !cfdotZl !cfdotZr If. Qed. Lemma isometry_of_cfnorm S tauS : pairwise_orthogonal S -> pairwise_orthogonal tauS -> map cfnorm tauS = map cfnorm S -> {tau : {linear 'CF(L) -> 'CF(G)} | map tau S = tauS & {in <<S>>%VS &, isometry tau}}. Proof. move=> oS oT eq_nST; have freeS := orthogonal_free oS. have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map. have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)). exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=. apply: eq_bigr => i _ /=; rewrite linearZ !cfdotZr !cfdot_suml; congr (_ * _). apply: eq_bigr => j _ /=; rewrite linearZ !cfdotZl; congr (_ * _). rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i. by rewrite -!['[_]](nth_map 0 0 cfnorm) ?eq_sz // eq_nST. have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS. have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT. by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz. Qed. Lemma isometry_raddf_inj U (tau : {additive 'CF(L) -> 'CF(G)}) : {in U &, isometry tau} -> {in U &, forall u v, u - v \in U} -> {in U &, injective tau}. Proof. move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB. by rewrite -cfnorm_eq0 Itau ?linU // cfnorm_eq0 subr_eq0 => /eqP. Qed. Lemma opp_isometry : @isometry _ _ G G -%R. Proof. by move=> x y; rewrite cfdotNl cfdotNr opprK. Qed. End BuildIsometries. Section Restrict. Variables (gT : finGroupType) (A B : {set gT}). Local Notation H := <<A>>. Local Notation G := <<B>>. Fact cfRes_subproof (phi : 'CF(B)) : is_class_fun H [ffun x => phi (if H \subset G then x else 1%g) *+ (x \in H)]. Proof. apply: intro_class_fun => /= [x y Hx Hy | x /negbTE/=-> //]. by rewrite Hx (groupJ Hx) //; case: subsetP => // sHG; rewrite cfunJgen ?sHG. Qed. Definition cfRes phi := Cfun 1 (cfRes_subproof phi). Lemma cfResE phi : A \subset B -> {in A, cfRes phi =1 phi}. Proof. by move=> sAB x Ax; rewrite cfunElock mem_gen ?genS. Qed. Lemma cfRes1 phi : cfRes phi 1%g = phi 1%g. Proof. by rewrite cfunElock if_same group1. Qed. Lemma cfRes_is_linear : linear cfRes. Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr mulrnDl. Qed. HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfRes (GRing.semilinear_linear cfRes_is_linear). Lemma cfRes_cfun1 : cfRes 1 = 1. Proof. apply: cfun_in_genP => x Hx; rewrite cfunElock Hx !cfun1Egen Hx. by case: subsetP => [-> // | _]; rewrite group1. Qed. Lemma cfRes_is_monoid_morphism : monoid_morphism cfRes. Proof. split=> [|phi psi]; [exact: cfRes_cfun1 | apply/cfunP=> x]. by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfRes_is_monoid_morphism` instead")] Definition cfRes_is_multiplicative := (fun g => (g.2,g.1)) cfRes_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfRes cfRes_is_monoid_morphism. End Restrict. Arguments cfRes {gT} A%_g {B%_g} phi%_CF. Notation "''Res[' H , G ]" := (@cfRes _ H G) (only parsing) : ring_scope. Notation "''Res[' H ]" := 'Res[H, _] : ring_scope. Notation "''Res'" := 'Res[_] (only parsing) : ring_scope. Section MoreRestrict. Variables (gT : finGroupType) (G H : {group gT}). Implicit Types (A : {set gT}) (phi : 'CF(G)). Lemma cfResEout phi : ~~ (H \subset G) -> 'Res[H] phi = (phi 1%g)%:A. Proof. move/negPf=> not_sHG; apply/cfunP=> x. by rewrite cfunE cfun1E mulr_natr cfunElock !genGid not_sHG. Qed. Lemma cfResRes A phi : A \subset H -> H \subset G -> 'Res[A] ('Res[H] phi) = 'Res[A] phi. Proof. move=> sAH sHG; apply/cfunP=> x; rewrite !cfunElock !genGid !gen_subG sAH sHG. by rewrite (subset_trans sAH) // -mulrnA mulnb -in_setI (setIidPr _) ?gen_subG. Qed. Lemma cfRes_id A psi : 'Res[A] psi = psi. Proof. by apply/cfun_in_genP=> x Ax; rewrite cfunElock Ax subxx. Qed. Lemma sub_cfker_Res A phi : A \subset H -> A \subset cfker phi -> A \subset cfker ('Res[H, G] phi). Proof. move=> sAH kerA; apply/subsetP=> x Ax; have Hx := subsetP sAH x Ax. rewrite inE Hx; apply/forallP=> y; rewrite !cfunElock !genGid groupMl //. by rewrite !(fun_if phi) cfkerMl // (subsetP kerA). Qed. Lemma eq_cfker_Res phi : H \subset cfker phi -> cfker ('Res[H, G] phi) = H. Proof. by move=> kH; apply/eqP; rewrite eqEsubset cfker_sub sub_cfker_Res. Qed. Lemma cfRes_sub_ker phi : H \subset cfker phi -> 'Res[H, G] phi = (phi 1%g)%:A. Proof. move=> kerHphi; have sHG := subset_trans kerHphi (cfker_sub phi). apply/cfun_inP=> x Hx; have ker_x := subsetP kerHphi x Hx. by rewrite cfResE // cfunE cfun1E Hx mulr1 cfker1. Qed. Lemma cforder_Res phi : #['Res[H] phi]%CF %| #[phi]%CF. Proof. exact: cforder_rmorph. Qed. End MoreRestrict. Section Morphim. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Section Main. Variable G : {group aT}. Implicit Type phi : 'CF(f @* G). Fact cfMorph_subproof phi : is_class_fun <<G>> [ffun x => phi (if G \subset D then f x else 1%g) *+ (x \in G)]. Proof. rewrite genGid; apply: intro_class_fun => [x y Gx Gy | x /negPf-> //]. rewrite Gx groupJ //; case subsetP => // sGD. by rewrite morphJ ?cfunJ ?mem_morphim ?sGD. Qed. Definition cfMorph phi := Cfun 1 (cfMorph_subproof phi). Lemma cfMorphE phi x : G \subset D -> x \in G -> cfMorph phi x = phi (f x). Proof. by rewrite cfunElock => -> ->. Qed. Lemma cfMorph1 phi : cfMorph phi 1%g = phi 1%g. Proof. by rewrite cfunElock morph1 if_same group1. Qed. Lemma cfMorphEout phi : ~~ (G \subset D) -> cfMorph phi = (phi 1%g)%:A. Proof. move/negPf=> not_sGD; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr. by rewrite cfunElock not_sGD. Qed. Lemma cfMorph_cfun1 : cfMorph 1 = 1. Proof. apply/cfun_inP=> x Gx; rewrite cfunElock !cfun1E Gx. by case: subsetP => [sGD | _]; rewrite ?group1 // mem_morphim ?sGD. Qed. Fact cfMorph_is_linear : linear cfMorph. Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr -mulrnDl. Qed. HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfMorph (GRing.semilinear_linear cfMorph_is_linear). Fact cfMorph_is_monoid_morphism : monoid_morphism cfMorph. Proof. split=> [|phi psi]; [exact: cfMorph_cfun1 | apply/cfunP=> x]. by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb. Qed. HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfMorph cfMorph_is_monoid_morphism. Hypothesis sGD : G \subset D. Lemma cfMorph_inj : injective cfMorph. Proof. move=> phi1 phi2 eq_phi; apply/cfun_inP=> _ /morphimP[x Dx Gx ->]. by rewrite -!cfMorphE // eq_phi. Qed. Lemma cfMorph_eq1 phi : (cfMorph phi == 1) = (phi == 1). Proof. exact/rmorph_eq1/cfMorph_inj. Qed. Lemma cfker_morph phi : cfker (cfMorph phi) = G :&: f @*^-1 (cfker phi). Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. have Dx := subsetP sGD x Gx; rewrite Dx mem_morphim //=. apply/forallP/forallP=> Kx y. have [{y} /morphimP[y Dy Gy ->] | fG'y] := boolP (y \in f @* G). by rewrite -morphM // -!(cfMorphE phi) ?groupM. by rewrite !cfun0 ?groupMl // mem_morphim. have [Gy | G'y] := boolP (y \in G); last by rewrite !cfun0 ?groupMl. by rewrite !cfMorphE ?groupM ?morphM // (subsetP sGD). Qed. Lemma cfker_morph_im phi : f @* cfker (cfMorph phi) = cfker phi. Proof. by rewrite cfker_morph // morphim_setIpre (setIidPr (cfker_sub _)). Qed. Lemma sub_cfker_morph phi (A : {set aT}) : (A \subset cfker (cfMorph phi)) = (A \subset G) && (f @* A \subset cfker phi). Proof. rewrite cfker_morph // subsetI; apply: andb_id2l => sAG. by rewrite sub_morphim_pre // (subset_trans sAG). Qed. Lemma sub_morphim_cfker phi (A : {set aT}) : A \subset G -> (f @* A \subset cfker phi) = (A \subset cfker (cfMorph phi)). Proof. by move=> sAG; rewrite sub_cfker_morph ?sAG. Qed. Lemma cforder_morph phi : #[cfMorph phi]%CF = #[phi]%CF. Proof. exact/cforder_inj_rmorph/cfMorph_inj. Qed. End Main. Lemma cfResMorph (G H : {group aT}) (phi : 'CF(f @* G)) : H \subset G -> G \subset D -> 'Res (cfMorph phi) = cfMorph ('Res[f @* H] phi). Proof. move=> sHG sGD; have sHD := subset_trans sHG sGD. apply/cfun_inP=> x Hx; have [Gx Dx] := (subsetP sHG x Hx, subsetP sHD x Hx). by rewrite !(cfMorphE, cfResE) ?morphimS ?mem_morphim //. Qed. End Morphim. Prenex Implicits cfMorph. Section Isomorphism. Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}). Variable R : {group rT}. Hypothesis isoGR : isom G R f. Let defR := isom_im isoGR. Local Notation G1 := (isom_inv isoGR @* R). Let defG : G1 = G := isom_im (isom_sym isoGR). Fact cfIsom_key : unit. Proof. by []. Qed. Definition cfIsom := locked_with cfIsom_key (cfMorph \o 'Res[G1] : 'CF(G) -> 'CF(R)). Canonical cfIsom_unlockable := [unlockable of cfIsom]. Lemma cfIsomE phi (x : aT : finType) : x \in G -> cfIsom phi (f x) = phi x. Proof. move=> Gx; rewrite unlock cfMorphE //= /restrm ?defG ?cfRes_id ?invmE //. by rewrite -defR mem_morphim. Qed. Lemma cfIsom1 phi : cfIsom phi 1%g = phi 1%g. Proof. by rewrite -(morph1 f) cfIsomE. Qed. Lemma cfIsom_is_zmod_morphism : zmod_morphism cfIsom. Proof. rewrite unlock; exact: raddfB. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfIsom_is_zmod_morphism` instead")] Definition cfIsom_is_additive := cfIsom_is_zmod_morphism. Lemma cfIsom_is_monoid_morphism : monoid_morphism cfIsom. Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfIsom_is_monoid_morphism` instead")] Definition cfIsom_is_multiplicative := (fun g => (g.2,g.1)) cfIsom_is_monoid_morphism. Lemma cfIsom_is_scalable : scalable cfIsom. Proof. rewrite unlock; exact: linearZ_LR. Qed. HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfIsom cfIsom_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfIsom cfIsom_is_monoid_morphism. HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfIsom cfIsom_is_scalable. Lemma cfIsom_cfun1 : cfIsom 1 = 1. Proof. exact: rmorph1. Qed. Lemma cfker_isom phi : cfker (cfIsom phi) = f @* cfker phi. Proof. rewrite unlock cfker_morph // defG cfRes_id morphpre_restrm morphpre_invm. by rewrite -defR !morphimIim. Qed. End Isomorphism. Prenex Implicits cfIsom. Section InvMorphism. Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}). Variable R : {group rT}. Hypothesis isoGR : isom G R f. Lemma cfIsomK : cancel (cfIsom isoGR) (cfIsom (isom_sym isoGR)). Proof. move=> phi; apply/cfun_inP=> x Gx; rewrite -{1}(invmE (isom_inj isoGR) Gx). by rewrite !cfIsomE // -(isom_im isoGR) mem_morphim. Qed. Lemma cfIsomKV : cancel (cfIsom (isom_sym isoGR)) (cfIsom isoGR). Proof. move=> phi; apply/cfun_inP=> y Ry; pose injGR := isom_inj isoGR. rewrite -{1}[y](invmK injGR) ?(isom_im isoGR) //. suffices /morphpreP[fGy Gf'y]: y \in invm injGR @*^-1 G by rewrite !cfIsomE. by rewrite morphpre_invm (isom_im isoGR). Qed. Lemma cfIsom_inj : injective (cfIsom isoGR). Proof. exact: can_inj cfIsomK. Qed. Lemma cfIsom_eq1 phi : (cfIsom isoGR phi == 1) = (phi == 1). Proof. exact/rmorph_eq1/cfIsom_inj. Qed. Lemma cforder_isom phi : #[cfIsom isoGR phi]%CF = #[phi]%CF. Proof. exact: cforder_inj_rmorph cfIsom_inj. Qed. End InvMorphism. Arguments cfIsom_inj {aT rT G f R} isoGR [phi1 phi2] : rename. Section Coset. Variables (gT : finGroupType) (G : {group gT}) (B : {set gT}). Implicit Type rT : finGroupType. Local Notation H := <<B>>%g. Definition cfMod : 'CF(G / B) -> 'CF(G) := cfMorph. Definition ffun_Quo (phi : 'CF(G)) := [ffun Hx : coset_of B => phi (if B \subset cfker phi then repr Hx else 1%g) *+ (Hx \in G / B)%g]. Fact cfQuo_subproof phi : is_class_fun <<G / B>> (ffun_Quo phi). Proof. rewrite genGid; apply: intro_class_fun => [|Hx /negPf-> //]. move=> _ _ /morphimP[x Nx Gx ->] /morphimP[z Nz Gz ->]. rewrite -morphJ ?mem_morphim ?val_coset_prim ?groupJ //= -gen_subG. case: subsetP => // KphiH; do 2!case: repr_rcosetP => _ /KphiH/cfkerMl->. by rewrite cfunJ. Qed. Definition cfQuo phi := Cfun 1 (cfQuo_subproof phi). Local Notation "phi / 'B'" := (cfQuo phi) (at level 40, left associativity) : cfun_scope. Local Notation "phi %% 'B'" := (cfMod phi) (at level 40) : cfun_scope. (* We specialize the cfMorph lemmas to cfMod by strengthening the domain *) (* condition G \subset 'N(H) to H <| G; the cfMorph lemmas can be used if the *) (* stronger results are needed. *) Lemma cfModE phi x : B <| G -> x \in G -> (phi %% B)%CF x = phi (coset B x). Proof. by move/normal_norm=> nBG; apply: cfMorphE. Qed. Lemma cfMod1 phi : (phi %% B)%CF 1%g = phi 1%g. Proof. exact: cfMorph1. Qed. HB.instance Definition _ := GRing.LRMorphism.on cfMod. Lemma cfMod_cfun1 : (1 %% B)%CF = 1. Proof. exact: rmorph1. Qed. Lemma cfker_mod phi : B <| G -> B \subset cfker (phi %% B). Proof. case/andP=> sBG nBG; rewrite cfker_morph // subsetI sBG. apply: subset_trans _ (ker_sub_pre _ _); rewrite ker_coset_prim subsetI. by rewrite (subset_trans sBG nBG) sub_gen. Qed. (* Note that cfQuo is nondegenerate even when G does not normalize B. *) Lemma cfQuoEnorm (phi : 'CF(G)) x : B \subset cfker phi -> x \in 'N_G(B) -> (phi / B)%CF (coset B x) = phi x. Proof. rewrite cfunElock -gen_subG => sHK /setIP[Gx nHx]; rewrite sHK /=. rewrite mem_morphim // val_coset_prim //. by case: repr_rcosetP => _ /(subsetP sHK)/cfkerMl->. Qed. Lemma cfQuoE (phi : 'CF(G)) x : B <| G -> B \subset cfker phi -> x \in G -> (phi / B)%CF (coset B x) = phi x. Proof. by case/andP=> _ nBG sBK Gx; rewrite cfQuoEnorm // (setIidPl _). Qed. Lemma cfQuo1 (phi : 'CF(G)) : (phi / B)%CF 1%g = phi 1%g. Proof. by rewrite cfunElock repr_coset1 group1 if_same. Qed. Lemma cfQuoEout (phi : 'CF(G)) : ~~ (B \subset cfker phi) -> (phi / B)%CF = (phi 1%g)%:A. Proof. move/negPf=> not_kerB; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr. by rewrite cfunElock not_kerB. Qed. (* cfQuo is only linear on the class functions that have H in their kernel. *) Lemma cfQuo_cfun1 : (1 / B)%CF = 1. Proof. apply/cfun_inP=> Hx G_Hx; rewrite cfunElock !cfun1E G_Hx cfker_cfun1 -gen_subG. have [x nHx Gx ->] := morphimP G_Hx. case: subsetP=> [sHG | _]; last by rewrite group1. by rewrite val_coset_prim //; case: repr_rcosetP => y /sHG/groupM->. Qed. (* Cancellation properties *) Lemma cfModK : B <| G -> cancel cfMod cfQuo. Proof. move=> nsBG phi; apply/cfun_inP=> _ /morphimP[x Nx Gx ->] //. by rewrite cfQuoE ?cfker_mod ?cfModE. Qed. Lemma cfQuoK : B <| G -> forall phi, B \subset cfker phi -> (phi / B %% B)%CF = phi. Proof. by move=> nsHG phi sHK; apply/cfun_inP=> x Gx; rewrite cfModE ?cfQuoE. Qed. Lemma cfMod_eq1 psi : B <| G -> (psi %% B == 1)%CF = (psi == 1). Proof. by move/cfModK/can_eq <-; rewrite rmorph1. Qed. Lemma cfQuo_eq1 phi : B <| G -> B \subset cfker phi -> (phi / B == 1)%CF = (phi == 1). Proof. by move=> nsBG kerH; rewrite -cfMod_eq1 // cfQuoK. Qed. End Coset. Arguments cfQuo {gT G%_G} B%_g phi%_CF. Arguments cfMod {gT G%_G B%_g} phi%_CF. Notation "phi / H" := (cfQuo H phi) : cfun_scope. Notation "phi %% H" := (@cfMod _ _ H phi) : cfun_scope. Section MoreCoset. Variables (gT : finGroupType) (G : {group gT}). Implicit Types (H K : {group gT}) (phi : 'CF(G)). Lemma cfResMod H K (psi : 'CF(G / K)) : H \subset G -> K <| G -> ('Res (psi %% K) = 'Res[H / K] psi %% K)%CF. Proof. by move=> sHG /andP[_]; apply: cfResMorph. Qed. Lemma quotient_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) : K <| G -> (cfker (psi %% K) / K)%g = cfker psi. Proof. by case/andP=> _ /cfker_morph_im <-. Qed. Lemma sub_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) : K <| G -> A \subset 'N(K) -> (A \subset cfker (psi %% K)) = (A / K \subset cfker psi)%g. Proof. by move=> nsKG nKA; rewrite -(quotientSGK nKA) ?quotient_cfker_mod// cfker_mod. Qed. Lemma cfker_quo H phi : H <| G -> H \subset cfker (phi) -> cfker (phi / H) = (cfker phi / H)%g. Proof. move=> nsHG /cfQuoK {2}<- //; have [sHG nHG] := andP nsHG. by rewrite cfker_morph 1?quotientGI // cosetpreK (setIidPr _) ?cfker_sub. Qed. Lemma cfQuoEker phi x : x \in G -> (phi / cfker phi)%CF (coset (cfker phi) x) = phi x. Proof. by move/cfQuoE->; rewrite ?cfker_normal. Qed. Lemma cfaithful_quo phi : cfaithful (phi / cfker phi). Proof. by rewrite cfaithfulE cfker_quo ?cfker_normal ?trivg_quotient. Qed. (* Note that there is no requirement that K be normal in H or G. *) Lemma cfResQuo H K phi : K \subset cfker phi -> K \subset H -> H \subset G -> ('Res[H / K] (phi / K) = 'Res[H] phi / K)%CF. Proof. move=> kerK sKH sHG; apply/cfun_inP=> xb Hxb; rewrite cfResE ?quotientS //. have{xb Hxb} [x nKx Hx ->] := morphimP Hxb. by rewrite !cfQuoEnorm ?cfResE// 1?inE ?Hx ?(subsetP sHG)// sub_cfker_Res. Qed. Lemma cfQuoInorm K phi : K \subset cfker phi -> (phi / K)%CF = 'Res ('Res['N_G(K)] phi / K)%CF. Proof. move=> kerK; rewrite -cfResQuo ?subsetIl ?quotientInorm ?cfRes_id //. by rewrite subsetI normG (subset_trans kerK) ?cfker_sub. Qed. Lemma cforder_mod H (psi : 'CF(G / H)) : H <| G -> #[psi %% H]%CF = #[psi]%CF. Proof. by move/cfModK/can_inj/cforder_inj_rmorph->. Qed. Lemma cforder_quo H phi : H <| G -> H \subset cfker phi -> #[phi / H]%CF = #[phi]%CF. Proof. by move=> nsHG kerHphi; rewrite -cforder_mod ?cfQuoK. Qed. End MoreCoset. Section Product. Variable (gT : finGroupType) (G : {group gT}). Lemma cfunM_onI A B phi psi : phi \in 'CF(G, A) -> psi \in 'CF(G, B) -> phi * psi \in 'CF(G, A :&: B). Proof. rewrite !cfun_onE => Aphi Bpsi; apply/subsetP=> x; rewrite !inE cfunE mulf_eq0. by case/norP=> /(subsetP Aphi)-> /(subsetP Bpsi). Qed. Lemma cfunM_on A phi psi : phi \in 'CF(G, A) -> psi \in 'CF(G, A) -> phi * psi \in 'CF(G, A). Proof. by move=> Aphi Bpsi; rewrite -[A]setIid cfunM_onI. Qed. End Product. Section SDproduct. Variables (gT : finGroupType) (G K H : {group gT}). Hypothesis defG : K ><| H = G. Fact cfSdprodKey : unit. Proof. by []. Qed. Definition cfSdprod := locked_with cfSdprodKey (cfMorph \o cfIsom (tagged (sdprod_isom defG)) : 'CF(H) -> 'CF(G)). Canonical cfSdprod_unlockable := [unlockable of cfSdprod]. Lemma cfSdprod_is_zmod_morphism : zmod_morphism cfSdprod. Proof. rewrite unlock; exact: raddfB. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfSdprod_is_zmod_morphism` instead")] Definition cfSdprod_is_additive := cfSdprod_is_zmod_morphism. Lemma cfSdprod_is_monoid_morphism : monoid_morphism cfSdprod. Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `cfSdprod_is_monoid_morphism` instead")] Definition cfSdprod_is_multiplicative := (fun g => (g.2,g.1)) cfSdprod_is_monoid_morphism. Lemma cfSdprod_is_scalable : scalable cfSdprod. Proof. rewrite unlock; exact: linearZ_LR. Qed. HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfSdprod cfSdprod_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfSdprod cfSdprod_is_monoid_morphism. HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfSdprod cfSdprod_is_scalable. Lemma cfSdprod1 phi : cfSdprod phi 1%g = phi 1%g. Proof. by rewrite unlock /= cfMorph1 cfIsom1. Qed. Let nsKG : K <| G. Proof. by have [] := sdprod_context defG. Qed. Let sHG : H \subset G. Proof. by have [] := sdprod_context defG. Qed. Let sKG : K \subset G. Proof. by have [] := andP nsKG. Qed. Lemma cfker_sdprod phi : K \subset cfker (cfSdprod phi). Proof. by rewrite unlock_with cfker_mod. Qed. Lemma cfSdprodEr phi : {in H, cfSdprod phi =1 phi}. Proof. by move=> y Hy; rewrite unlock cfModE ?cfIsomE ?(subsetP sHG). Qed. Lemma cfSdprodE phi : {in K & H, forall x y, cfSdprod phi (x * y)%g = phi y}. Proof. by move=> x y Kx Hy; rewrite /= cfkerMl ?(subsetP (cfker_sdprod _)) ?cfSdprodEr. Qed. Lemma cfSdprodK : cancel cfSdprod 'Res[H]. Proof. by move=> phi; apply/cfun_inP=> x Hx; rewrite cfResE ?cfSdprodEr. Qed. Lemma cfSdprod_inj : injective cfSdprod. Proof. exact: can_inj cfSdprodK. Qed. Lemma cfSdprod_eq1 phi : (cfSdprod phi == 1) = (phi == 1). Proof. exact: rmorph_eq1 cfSdprod_inj. Qed. Lemma cfRes_sdprodK phi : K \subset cfker phi -> cfSdprod ('Res[H] phi) = phi. Proof. move=> kerK; apply/cfun_inP=> _ /(mem_sdprod defG)[x [y [Kx Hy -> _]]]. by rewrite cfSdprodE // cfResE // cfkerMl ?(subsetP kerK). Qed. Lemma sdprod_cfker phi : K ><| cfker phi = cfker (cfSdprod phi). Proof. have [skerH [_ _ nKH tiKH]] := (cfker_sub phi, sdprodP defG). rewrite unlock cfker_morph ?normal_norm // cfker_isom restrmEsub //=. rewrite -(sdprod_modl defG) ?sub_cosetpre //=; congr (_ ><| _). by rewrite quotientK ?(subset_trans skerH) // -group_modr //= setIC tiKH mul1g. Qed. Lemma cforder_sdprod phi : #[cfSdprod phi]%CF = #[phi]%CF. Proof. exact: cforder_inj_rmorph cfSdprod_inj. Qed. End SDproduct. Section DProduct. Variables (gT : finGroupType) (G K H : {group gT}). Hypothesis KxH : K \x H = G. Lemma reindex_dprod R idx (op : Monoid.com_law idx) (F : gT -> R) : \big[op/idx]_(g in G) F g = \big[op/idx]_(k in K) \big[op/idx]_(h in H) F (k * h)%g. Proof. have /mulgmP/misomP[fM /isomP[injf im_f]] := KxH. rewrite pair_big_dep -im_f morphimEdom big_imset; last exact/injmP. by apply: eq_big => [][x y]; rewrite ?inE. Qed. Definition cfDprodr := cfSdprod (dprodWsd KxH). Definition cfDprodl := cfSdprod (dprodWsdC KxH). Definition cfDprod phi psi := cfDprodl phi * cfDprodr psi. HB.instance Definition _ := GRing.LRMorphism.on cfDprodl. HB.instance Definition _ := GRing.LRMorphism.on cfDprodr. Lemma cfDprodl1 phi : cfDprodl phi 1%g = phi 1%g. Proof. exact: cfSdprod1. Qed. Lemma cfDprodr1 psi : cfDprodr psi 1%g = psi 1%g. Proof. exact: cfSdprod1. Qed. Lemma cfDprod1 phi psi : cfDprod phi psi 1%g = phi 1%g * psi 1%g. Proof. by rewrite cfunE /= !cfSdprod1. Qed. Lemma cfDprodl_eq1 phi : (cfDprodl phi == 1) = (phi == 1). Proof. exact: cfSdprod_eq1. Qed. Lemma cfDprodr_eq1 psi : (cfDprodr psi == 1) = (psi == 1). Proof. exact: cfSdprod_eq1. Qed. Lemma cfDprod_cfun1r phi : cfDprod phi 1 = cfDprodl phi. Proof. by rewrite /cfDprod rmorph1 mulr1. Qed. Lemma cfDprod_cfun1l psi : cfDprod 1 psi = cfDprodr psi. Proof. by rewrite /cfDprod rmorph1 mul1r. Qed. Lemma cfDprod_cfun1 : cfDprod 1 1 = 1. Proof. by rewrite cfDprod_cfun1l rmorph1. Qed. Lemma cfDprod_split phi psi : cfDprod phi psi = cfDprod phi 1 * cfDprod 1 psi. Proof. by rewrite cfDprod_cfun1l cfDprod_cfun1r. Qed. Let nsKG : K <| G. Proof. by have [] := dprod_normal2 KxH. Qed. Let nsHG : H <| G. Proof. by have [] := dprod_normal2 KxH. Qed. Let cKH : H \subset 'C(K). Proof. by have [] := dprodP KxH. Qed. Let sKG := normal_sub nsKG. Let sHG := normal_sub nsHG. Lemma cfDprodlK : cancel cfDprodl 'Res[K]. Proof. exact: cfSdprodK. Qed. Lemma cfDprodrK : cancel cfDprodr 'Res[H]. Proof. exact: cfSdprodK. Qed. Lemma cfker_dprodl phi : cfker phi \x H = cfker (cfDprodl phi). Proof. by rewrite dprodC -sdprod_cfker dprodEsd // centsC (centsS (cfker_sub _)). Qed. Lemma cfker_dprodr psi : K \x cfker psi = cfker (cfDprodr psi). Proof. by rewrite -sdprod_cfker dprodEsd // (subset_trans (cfker_sub _)). Qed. Lemma cfDprodEl phi : {in K & H, forall k h, cfDprodl phi (k * h)%g = phi k}. Proof. by move=> k h Kk Hh /=; rewrite -(centsP cKH) // cfSdprodE. Qed. Lemma cfDprodEr psi : {in K & H, forall k h, cfDprodr psi (k * h)%g = psi h}. Proof. exact: cfSdprodE. Qed. Lemma cfDprodE phi psi : {in K & H, forall h k, cfDprod phi psi (h * k)%g = phi h * psi k}. Proof. by move=> k h Kk Hh /=; rewrite cfunE cfDprodEl ?cfDprodEr. Qed. Lemma cfDprod_Resl phi psi : 'Res[K] (cfDprod phi psi) = psi 1%g *: phi. Proof. by apply/cfun_inP=> x Kx; rewrite cfunE cfResE // -{1}[x]mulg1 mulrC cfDprodE. Qed. Lemma cfDprod_Resr phi psi : 'Res[H] (cfDprod phi psi) = phi 1%g *: psi. Proof. by apply/cfun_inP=> y Hy; rewrite cfunE cfResE // -{1}[y]mul1g cfDprodE. Qed. Lemma cfDprodKl (psi : 'CF(H)) : psi 1%g = 1 -> cancel (cfDprod^~ psi) 'Res. Proof. by move=> psi1 phi; rewrite cfDprod_Resl psi1 scale1r. Qed. Lemma cfDprodKr (phi : 'CF(K)) : phi 1%g = 1 -> cancel (cfDprod phi) 'Res. Proof. by move=> phi1 psi; rewrite cfDprod_Resr phi1 scale1r. Qed. (* Note that equality holds here iff either cfker phi = K and cfker psi = H, *) (* or else phi != 0, psi != 0 and coprime #|K : cfker phi| #|H : cfker phi|. *) Lemma cfker_dprod phi psi : cfker phi <*> cfker psi \subset cfker (cfDprod phi psi). Proof. rewrite -genM_join gen_subG; apply/subsetP=> _ /mulsgP[x y kKx kHy ->] /=. have [[Kx _] [Hy _]] := (setIdP kKx, setIdP kHy). have Gxy: (x * y)%g \in G by rewrite -(dprodW KxH) mem_mulg. rewrite inE Gxy; apply/forallP=> g. have [Gg | G'g] := boolP (g \in G); last by rewrite !cfun0 1?groupMl. have{g Gg} [k [h [Kk Hh -> _]]] := mem_dprod KxH Gg. rewrite mulgA -(mulgA x) (centsP cKH y) // mulgA -mulgA !cfDprodE ?groupM //. by rewrite !cfkerMl. Qed. Lemma cfdot_dprod phi1 phi2 psi1 psi2 : '[cfDprod phi1 psi1, cfDprod phi2 psi2] = '[phi1, phi2] * '[psi1, psi2]. Proof. rewrite !cfdotE mulrCA -mulrA mulrCA mulrA -invfM -natrM (dprod_card KxH). congr (_ * _); rewrite big_distrl reindex_dprod /=; apply: eq_bigr => k Kk. rewrite big_distrr; apply: eq_bigr => h Hh /=. by rewrite mulrCA -mulrA -rmorphM mulrCA mulrA !cfDprodE. Qed. Lemma cfDprodl_iso : isometry cfDprodl. Proof. by move=> phi1 phi2; rewrite -!cfDprod_cfun1r cfdot_dprod cfnorm1 mulr1. Qed. Lemma cfDprodr_iso : isometry cfDprodr. Proof. by move=> psi1 psi2; rewrite -!cfDprod_cfun1l cfdot_dprod cfnorm1 mul1r. Qed. Lemma cforder_dprodl phi : #[cfDprodl phi]%CF = #[phi]%CF. Proof. exact: cforder_sdprod. Qed. Lemma cforder_dprodr psi : #[cfDprodr psi]%CF = #[psi]%CF. Proof. exact: cforder_sdprod. Qed. End DProduct. Lemma cfDprodC (gT : finGroupType) (G K H : {group gT}) (KxH : K \x H = G) (HxK : H \x K = G) chi psi : cfDprod KxH chi psi = cfDprod HxK psi chi. Proof. rewrite /cfDprod mulrC. by congr (_ * _); congr (cfSdprod _ _); apply: eq_irrelevance. Qed. Section Bigdproduct. Variables (gT : finGroupType) (I : finType) (P : pred I). Variables (A : I -> {group gT}) (G : {group gT}). Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G. Let sAG i : P i -> A i \subset G. Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed. Fact cfBigdprodi_subproof i : gval (if P i then A i else 1%G) \x <<\bigcup_(j | P j && (j != i)) A j>> = G. Proof. have:= defG; rewrite fun_if big_mkcond (bigD1 i) // -big_mkcondl /= => defGi. by have [[_ Gi' _ defGi']] := dprodP defGi; rewrite (bigdprodWY defGi') -defGi'. Qed. Definition cfBigdprodi i := cfDprodl (cfBigdprodi_subproof i) \o 'Res[_, A i]. HB.instance Definition _ i := GRing.LRMorphism.on (@cfBigdprodi i). Lemma cfBigdprodi1 i (phi : 'CF(A i)) : cfBigdprodi phi 1%g = phi 1%g. Proof. by rewrite cfDprodl1 cfRes1. Qed. Lemma cfBigdprodi_eq1 i (phi : 'CF(A i)) : P i -> (cfBigdprodi phi == 1) = (phi == 1). Proof. by move=> Pi; rewrite cfSdprod_eq1 Pi cfRes_id. Qed. Lemma cfBigdprodiK i : P i -> cancel (@cfBigdprodi i) 'Res[A i]. Proof. move=> Pi phi; have:= cfDprodlK (cfBigdprodi_subproof i) ('Res phi). by rewrite -[cfDprodl _ _]/(cfBigdprodi phi) Pi cfRes_id. Qed. Lemma cfBigdprodi_inj i : P i -> injective (@cfBigdprodi i). Proof. by move/cfBigdprodiK; apply: can_inj. Qed. Lemma cfBigdprodEi i (phi : 'CF(A i)) x : P i -> (forall j, P j -> x j \in A j) -> cfBigdprodi phi (\prod_(j | P j) x j)%g = phi (x i). Proof. have [r big_r [Ur mem_r] _] := big_enumP P => Pi AxP. have:= bigdprodWcp defG; rewrite -!big_r => defGr. have{AxP} [r_i Axr]: i \in r /\ {in r, forall j, x j \in A j}. by split=> [|j]; rewrite mem_r // => /AxP. rewrite (perm_bigcprod defGr Axr (perm_to_rem r_i)) big_cons. rewrite cfDprodEl ?Pi ?cfRes_id ?Axr // big_seq group_prod // => j. rewrite mem_rem_uniq // => /andP[i'j /= r_j]. by apply/mem_gen/bigcupP; exists j; [rewrite -mem_r r_j | apply: Axr]. Qed. Lemma cfBigdprodi_iso i : P i -> isometry (@cfBigdprodi i). Proof. by move=> Pi phi psi; rewrite cfDprodl_iso Pi !cfRes_id. Qed. Definition cfBigdprod (phi : forall i, 'CF(A i)) := \prod_(i | P i) cfBigdprodi (phi i). Lemma cfBigdprodE phi x : (forall i, P i -> x i \in A i) -> cfBigdprod phi (\prod_(i | P i) x i)%g = \prod_(i | P i) phi i (x i). Proof. move=> Ax; rewrite prod_cfunE; last by rewrite -(bigdprodW defG) mem_prodg. by apply: eq_bigr => i Pi; rewrite cfBigdprodEi. Qed. Lemma cfBigdprod1 phi : cfBigdprod phi 1%g = \prod_(i | P i) phi i 1%g. Proof. by rewrite prod_cfunE //; apply/eq_bigr=> i _; apply: cfBigdprodi1. Qed. Lemma cfBigdprodK phi (Phi := cfBigdprod phi) i (a := phi i 1%g / Phi 1%g) : Phi 1%g != 0 -> P i -> a != 0 /\ a *: 'Res[A i] Phi = phi i. Proof. move=> nzPhi Pi; split. rewrite mulf_neq0 ?invr_eq0 // (contraNneq _ nzPhi) // => phi_i0. by rewrite cfBigdprod1 (bigD1 i) //= phi_i0 mul0r. apply/cfun_inP=> x Aix; rewrite cfunE cfResE ?sAG // mulrAC. have {1}->: x = (\prod_(j | P j) (if j == i then x else 1))%g. rewrite -big_mkcondr (big_pred1 i) ?eqxx // => j /=. by apply: andb_idl => /eqP->. rewrite cfBigdprodE => [|j _]; last by case: eqP => // ->. apply: canLR (mulfK nzPhi) _; rewrite cfBigdprod1 !(bigD1 i Pi) /= eqxx. by rewrite mulrCA !mulrA; congr (_ * _); apply: eq_bigr => j /andP[_ /negPf->]. Qed. Lemma cfdot_bigdprod phi psi : '[cfBigdprod phi, cfBigdprod psi] = \prod_(i | P i) '[phi i, psi i]. Proof. apply: canLR (mulKf (neq0CG G)) _; rewrite -(bigdprod_card defG). rewrite (big_morph _ (@natrM _) (erefl _)) -big_split /=. rewrite (eq_bigr _ (fun i _ => mulVKf (neq0CG _) _)) (big_distr_big_dep 1%g) /=. set F := pfamily _ _ _; pose h (f : {ffun I -> gT}) := (\prod_(i | P i) f i)%g. pose is_hK x f := forall f1, (f1 \in F) && (h f1 == x) = (f == f1). have /fin_all_exists[h1 Dh1] x: exists f, x \in G -> is_hK x f. case Gx: (x \in G); last by exists [ffun _ => x]. have [f [Af fK Uf]] := mem_bigdprod defG Gx. exists [ffun i => if P i then f i else 1%g] => _ f1. apply/andP/eqP=> [[/pfamilyP[Pf1 Af1] /eqP Dx] | <-]. by apply/ffunP=> i; rewrite ffunE; case: ifPn => [/Uf-> | /(supportP Pf1)]. split; last by rewrite fK; apply/eqP/eq_bigr=> i Pi; rewrite ffunE Pi. by apply/familyP=> i; rewrite ffunE !unfold_in; case: ifP => //= /Af. rewrite (reindex_onto h h1) /= => [|x /Dh1/(_ (h1 x))]; last first. by rewrite eqxx => /andP[_ /eqP]. apply/eq_big => [f | f /andP[/Dh1<- /andP[/pfamilyP[_ Af] _]]]; last first. by rewrite !cfBigdprodE // rmorph_prod -big_split /=. apply/idP/idP=> [/andP[/Dh1<-] | Ff]; first by rewrite eqxx andbT. have /pfamilyP[_ Af] := Ff; suffices Ghf: h f \in G by rewrite -Dh1 ?Ghf ?Ff /=. by apply/group_prod=> i Pi; rewrite (subsetP (sAG Pi)) ?Af. Qed. End Bigdproduct. Section MorphIsometry. Variable gT : finGroupType. Implicit Types (D G H K : {group gT}) (aT rT : finGroupType). Lemma cfMorph_iso aT rT (G D : {group aT}) (f : {morphism D >-> rT}) : G \subset D -> isometry (cfMorph : 'CF(f @* G) -> 'CF(G)). Proof. move=> sGD phi psi; rewrite !cfdotE card_morphim (setIidPr sGD). rewrite -(LagrangeI G ('ker f)) /= mulnC natrM invfM -mulrA. congr (_ * _); apply: (canLR (mulKf (neq0CG _))). rewrite mulr_sumr (partition_big_imset f) /= -morphimEsub //. apply: eq_bigr => _ /morphimP[x Dx Gx ->]. rewrite -(card_rcoset _ x) mulr_natl -sumr_const. apply/eq_big => [y | y /andP[Gy /eqP <-]]; last by rewrite !cfMorphE. rewrite mem_rcoset inE groupMr ?groupV // -mem_rcoset. by apply: andb_id2l => /(subsetP sGD) Dy; apply: sameP eqP (rcoset_kerP f _ _). Qed. Lemma cfIsom_iso rT G (R : {group rT}) (f : {morphism G >-> rT}) : forall isoG : isom G R f, isometry (cfIsom isoG). Proof. move=> isoG phi psi; rewrite unlock cfMorph_iso //; set G1 := _ @* R. by rewrite -(isom_im (isom_sym isoG)) -/G1 in phi psi *; rewrite !cfRes_id. Qed. Lemma cfMod_iso H G : H <| G -> isometry (@cfMod _ G H). Proof. by case/andP=> _; apply: cfMorph_iso. Qed. Lemma cfQuo_iso H G : H <| G -> {in [pred phi | H \subset cfker phi] &, isometry (@cfQuo _ G H)}. Proof. by move=> nsHG phi psi sHkphi sHkpsi; rewrite -(cfMod_iso nsHG) !cfQuoK. Qed. Lemma cfnorm_quo H G phi : H <| G -> H \subset cfker phi -> '[phi / H] = '[phi]_G. Proof. by move=> nsHG sHker; apply: cfQuo_iso. Qed. Lemma cfSdprod_iso K H G (defG : K ><| H = G) : isometry (cfSdprod defG). Proof. move=> phi psi; have [/andP[_ nKG] _ _ _ _] := sdprod_context defG. by rewrite [cfSdprod _]locked_withE cfMorph_iso ?cfIsom_iso. Qed. End MorphIsometry. Section Induced. Variable gT : finGroupType. Section Def. Variables B A : {set gT}. Local Notation G := <<B>>. Local Notation H := <<A>>. (* The default value for the ~~ (H \subset G) case matches the one for cfRes *) (* so that Frobenius reciprocity holds even in this degenerate case. *) Definition ffun_cfInd (phi : 'CF(A)) := [ffun x => if H \subset G then #|A|%:R^-1 * (\sum_(y in G) phi (x ^ y)) else #|G|%:R * '[phi, 1] *+ (x == 1%g)]. Fact cfInd_subproof phi : is_class_fun G (ffun_cfInd phi). Proof. apply: intro_class_fun => [x y Gx Gy | x H'x]; last first. case: subsetP => [sHG | _]; last by rewrite (negPf (group1_contra H'x)). rewrite big1 ?mulr0 // => y Gy; rewrite cfun0gen ?(contra _ H'x) //= => /sHG. by rewrite memJ_norm ?(subsetP (normG _)). rewrite conjg_eq1 (reindex_inj (mulgI y^-1)%g); congr (if _ then _ * _ else _). by apply: eq_big => [z | z Gz]; rewrite ?groupMl ?groupV // -conjgM mulKVg. Qed. Definition cfInd phi := Cfun 1 (cfInd_subproof phi). Lemma cfInd_is_linear : linear cfInd. Proof. move=> c phi psi; apply/cfunP=> x; rewrite !cfunElock; case: ifP => _. rewrite mulrCA -mulrDr [c * _]mulr_sumr -big_split /=. by congr (_ * _); apply: eq_bigr => y _; rewrite !cfunE. rewrite mulrnAr -mulrnDl !(mulrCA c) -!mulrDr [c * _]mulr_sumr -big_split /=. by congr (_ * (_ * _) *+ _); apply: eq_bigr => y; rewrite !cfunE mulrA mulrDl. Qed. HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfInd (GRing.semilinear_linear cfInd_is_linear). End Def. Local Notation "''Ind[' B , A ]" := (@cfInd B A) : ring_scope. Local Notation "''Ind[' B ]" := 'Ind[B, _] : ring_scope. Lemma cfIndE (G H : {group gT}) phi x : H \subset G -> 'Ind[G, H] phi x = #|H|%:R^-1 * (\sum_(y in G) phi (x ^ y)). Proof. by rewrite cfunElock !genGid => ->. Qed. Variables G K H : {group gT}. Implicit Types (phi : 'CF(H)) (psi : 'CF(G)). Lemma cfIndEout phi : ~~ (H \subset G) -> 'Ind[G] phi = (#|G|%:R * '[phi, 1]) *: '1_1%G. Proof. move/negPf=> not_sHG; apply/cfunP=> x; rewrite cfunE cfuniE ?normal1 // inE. by rewrite mulr_natr cfunElock !genGid not_sHG. Qed. Lemma cfIndEsdprod (phi : 'CF(K)) x : K ><| H = G -> 'Ind[G] phi x = \sum_(w in H) phi (x ^ w)%g. Proof. move=> defG; have [/andP[sKG _] _ mulKH nKH _] := sdprod_context defG. rewrite cfIndE //; apply: canLR (mulKf (neq0CG _)) _; rewrite -mulKH mulr_sumr. rewrite (set_partition_big _ (rcosets_partition_mul H K)) ?big_imset /=. apply: eq_bigr => y Hy; rewrite rcosetE norm_rlcoset ?(subsetP nKH) //. rewrite -lcosetE mulr_natl big_imset /=; last exact: in2W (mulgI _). by rewrite -sumr_const; apply: eq_bigr => z Kz; rewrite conjgM cfunJ. have [{}nKH /isomP[injf _]] := sdprod_isom defG. apply: can_in_inj (fun Ky => invm injf (coset K (repr Ky))) _ => y Hy. by rewrite rcosetE -val_coset ?(subsetP nKH) // coset_reprK invmE. Qed. Lemma cfInd_on A phi : H \subset G -> phi \in 'CF(H, A) -> 'Ind[G] phi \in 'CF(G, class_support A G). Proof. move=> sHG Af; apply/cfun_onP=> g AG'g; rewrite cfIndE ?big1 ?mulr0 // => h Gh. apply: (cfun_on0 Af); apply: contra AG'g => Agh. by rewrite -[g](conjgK h) memJ_class_support // groupV. Qed. Lemma cfInd_id phi : 'Ind[H] phi = phi. Proof. apply/cfun_inP=> x Hx; rewrite cfIndE // (eq_bigr _ (cfunJ phi x)) sumr_const. by rewrite -[phi x *+ _]mulr_natl mulKf ?neq0CG. Qed. Lemma cfInd_normal phi : H <| G -> 'Ind[G] phi \in 'CF(G, H). Proof. case/andP=> sHG nHG; apply: (cfun_onS (class_support_sub_norm (subxx _) nHG)). by rewrite cfInd_on ?cfun_onG. Qed. Lemma cfInd1 phi : H \subset G -> 'Ind[G] phi 1%g = #|G : H|%:R * phi 1%g. Proof. move=> sHG; rewrite cfIndE // natf_indexg // -mulrA mulrCA; congr (_ * _). by rewrite mulr_natl -sumr_const; apply: eq_bigr => x; rewrite conj1g. Qed. Lemma cfInd_cfun1 : H <| G -> 'Ind[G, H] 1 = #|G : H|%:R *: '1_H. Proof. move=> nsHG; have [sHG nHG] := andP nsHG; rewrite natf_indexg // mulrC. apply/cfunP=> x; rewrite cfIndE ?cfunE ?cfuniE // -mulrA; congr (_ * _). rewrite mulr_natl -sumr_const; apply: eq_bigr => y Gy. by rewrite cfun1E -{1}(normsP nHG y Gy) memJ_conjg. Qed. Lemma cfnorm_Ind_cfun1 : H <| G -> '['Ind[G, H] 1] = #|G : H|%:R. Proof. move=> nsHG; rewrite cfInd_cfun1 // cfnormZ normr_nat cfdot_cfuni // setIid. by rewrite expr2 {2}natf_indexg ?normal_sub // !mulrA divfK ?mulfK ?neq0CG. Qed. Lemma cfIndInd phi : K \subset G -> H \subset K -> 'Ind[G] ('Ind[K] phi) = 'Ind[G] phi. Proof. move=> sKG sHK; apply/cfun_inP=> x Gx; rewrite !cfIndE ?(subset_trans sHK) //. apply: canLR (mulKf (neq0CG K)) _; rewrite mulr_sumr mulr_natl. transitivity (\sum_(y in G) \sum_(z in K) #|H|%:R^-1 * phi ((x ^ y) ^ z)). by apply: eq_bigr => y Gy; rewrite cfIndE // -mulr_sumr. symmetry; rewrite exchange_big /= -sumr_const; apply: eq_bigr => z Kz. rewrite (reindex_inj (mulIg z)). by apply: eq_big => [y | y _]; rewrite ?conjgM // groupMr // (subsetP sKG). Qed. (* This is Isaacs, Lemma (5.2). *) Lemma Frobenius_reciprocity phi psi : '[phi, 'Res[H] psi] = '['Ind[G] phi, psi]. Proof. have [sHG | not_sHG] := boolP (H \subset G); last first. rewrite cfResEout // cfIndEout // cfdotZr cfdotZl mulrAC; congr (_ * _). rewrite (cfdotEl _ (cfuni_on _ _)) mulVKf ?neq0CG // big_set1. by rewrite cfuniE ?normal1 ?set11 ?mul1r. transitivity (#|H|%:R^-1 * \sum_(x in G) phi x * (psi x)^* ). rewrite (big_setID H) /= (setIidPr sHG) addrC big1 ?add0r; last first. by move=> x /setDP[_ /cfun0->]; rewrite mul0r. by congr (_ * _); apply: eq_bigr => x Hx; rewrite cfResE. set h' := _^-1; apply: canRL (mulKf (neq0CG G)) _. transitivity (h' * \sum_(y in G) \sum_(x in G) phi (x ^ y) * (psi (x ^ y))^* ). rewrite mulrCA mulr_natl -sumr_const; congr (_ * _); apply: eq_bigr => y Gy. by rewrite (reindex_acts 'J _ Gy) ?astabsJ ?normG. rewrite exchange_big mulr_sumr; apply: eq_bigr => x _; rewrite cfIndE //=. by rewrite -mulrA mulr_suml; congr (_ * _); apply: eq_bigr => y /(cfunJ psi)->. Qed. Definition cfdot_Res_r := Frobenius_reciprocity. Lemma cfdot_Res_l psi phi : '['Res[H] psi, phi] = '[psi, 'Ind[G] phi]. Proof. by rewrite cfdotC cfdot_Res_r -cfdotC. Qed. Lemma cfIndM phi psi: H \subset G -> 'Ind[G] (phi * ('Res[H] psi)) = 'Ind[G] phi * psi. Proof. move=> HsG; apply/cfun_inP=> x Gx; rewrite !cfIndE // !cfunE !cfIndE // -mulrA. congr (_ * _); rewrite mulr_suml; apply: eq_bigr=> i iG; rewrite !cfunE. case: (boolP (x ^ i \in H)) => xJi; last by rewrite cfun0gen ?mul0r ?genGid. by rewrite !cfResE //; congr (_ * _); rewrite cfunJgen ?genGid. Qed. End Induced. Arguments cfInd {gT} B%_g {A%_g} phi%_CF. Notation "''Ind[' G , H ]" := (@cfInd _ G H) (only parsing) : ring_scope. Notation "''Ind[' G ]" := 'Ind[G, _] : ring_scope. Notation "''Ind'" := 'Ind[_] (only parsing) : ring_scope. Section MorphInduced. Variables (aT rT : finGroupType) (D G H : {group aT}) (R S : {group rT}). Lemma cfIndMorph (f : {morphism D >-> rT}) (phi : 'CF(f @* H)) : 'ker f \subset H -> H \subset G -> G \subset D -> 'Ind[G] (cfMorph phi) = cfMorph ('Ind[f @* G] phi). Proof. move=> sKH sHG sGD; have [sHD inD] := (subset_trans sHG sGD, subsetP sGD). apply/cfun_inP=> /= x Gx; have [Dx sKG] := (inD x Gx, subset_trans sKH sHG). rewrite cfMorphE ?cfIndE ?morphimS // (partition_big_imset f) -morphimEsub //=. rewrite card_morphim (setIidPr sHD) natf_indexg // invfM invrK -mulrA. congr (_ * _); rewrite mulr_sumr; apply: eq_bigr => _ /morphimP[y Dy Gy ->]. rewrite -(card_rcoset _ y) mulr_natl -sumr_const. apply: eq_big => [z | z /andP[Gz /eqP <-]]. have [Gz | G'z] := boolP (z \in G). by rewrite (sameP eqP (rcoset_kerP _ _ _)) ?inD. by case: rcosetP G'z => // [[t Kt ->]]; rewrite groupM // (subsetP sKG). have [Dz Dxz] := (inD z Gz, inD (x ^ z) (groupJ Gx Gz)); rewrite -morphJ //. have [Hxz | notHxz] := boolP (x ^ z \in H); first by rewrite cfMorphE. by rewrite !cfun0 // -sub1set -morphim_set1 // morphimSGK ?sub1set. Qed. Variables (g : {morphism G >-> rT}) (h : {morphism H >-> rT}). Hypotheses (isoG : isom G R g) (isoH : isom H S h) (eq_hg : {in H, h =1 g}). Hypothesis sHG : H \subset G. Lemma cfResIsom phi : 'Res[S] (cfIsom isoG phi) = cfIsom isoH ('Res[H] phi). Proof. have [[injg defR] [injh defS]] := (isomP isoG, isomP isoH). rewrite !morphimEdom in defS defR; apply/cfun_inP=> s. rewrite -{1}defS => /imsetP[x Hx ->] {s}; have Gx := subsetP sHG x Hx. rewrite {1}eq_hg ?(cfResE, cfIsomE) // -defS -?eq_hg ?imset_f // -defR. by rewrite (eq_in_imset eq_hg) imsetS. Qed. Lemma cfIndIsom phi : 'Ind[R] (cfIsom isoH phi) = cfIsom isoG ('Ind[G] phi). Proof. have [[injg defR] [_ defS]] := (isomP isoG, isomP isoH). rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS. apply/cfun_inP=> s; rewrite -{1}defR => /morphimP[x _ Gx ->]{s}. rewrite cfIsomE ?cfIndE // -defR -{1}defS ?morphimS ?card_injm // morphimEdom. congr (_ * _); rewrite big_imset //=; last exact/injmP. apply: eq_bigr => y Gy; rewrite -morphJ //. have [Hxy | H'xy] := boolP (x ^ y \in H); first by rewrite -eq_hg ?cfIsomE. by rewrite !cfun0 -?defS // -sub1set -morphim_set1 ?injmSK ?sub1set // groupJ. Qed. End MorphInduced. Section FieldAutomorphism. Variables (u : {rmorphism algC -> algC}) (gT rT : finGroupType). Variables (G K H : {group gT}) (f : {morphism G >-> rT}) (R : {group rT}). Implicit Types (phi : 'CF(G)) (S : seq 'CF(G)). Local Notation "phi ^u" := (cfAut u phi). Lemma cfAutZ_nat n phi : (n%:R *: phi)^u = n%:R *: phi^u. Proof. exact: raddfZnat. Qed. Lemma cfAutZ_Cnat z phi : z \in Num.nat -> (z *: phi)^u = z *: phi^u. Proof. exact: raddfZ_nat. Qed. Lemma cfAutZ_Cint z phi : z \in Num.int -> (z *: phi)^u = z *: phi^u. Proof. exact: raddfZ_int. Qed. Lemma cfAutK : cancel (@cfAut gT G u) (cfAut (algC_invaut u)). Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_autK. Qed. Lemma cfAutVK : cancel (cfAut (algC_invaut u)) (@cfAut gT G u). Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_invautK. Qed. Lemma cfAut_inj : injective (@cfAut gT G u). Proof. exact: can_inj cfAutK. Qed. Lemma cfAut_eq1 phi : (cfAut u phi == 1) = (phi == 1). Proof. by rewrite rmorph_eq1 //; apply: cfAut_inj. Qed. Lemma support_cfAut phi : support phi^u =i support phi. Proof. by move=> x; rewrite !inE cfunE fmorph_eq0. Qed. Lemma map_cfAut_free S : cfAut_closed u S -> free S -> free (map (cfAut u) S). Proof. set Su := map _ S => sSuS freeS; have uniqS := free_uniq freeS. have uniqSu: uniq Su by rewrite (map_inj_uniq cfAut_inj). have{} sSuS: {subset Su <= S} by move=> _ /mapP[phi Sphi ->]; apply: sSuS. have [|_ eqSuS] := uniq_min_size uniqSu sSuS; first by rewrite size_map. by rewrite (perm_free (uniq_perm uniqSu uniqS eqSuS)). Qed. Lemma cfAut_on A phi : (phi^u \in 'CF(G, A)) = (phi \in 'CF(G, A)). Proof. by rewrite !cfun_onE (eq_subset (support_cfAut phi)). Qed. Lemma cfker_aut phi : cfker phi^u = cfker phi. Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. by apply/forallP/forallP=> Kx y; have:= Kx y; rewrite !cfunE (inj_eq (fmorph_inj u)). Qed. Lemma cfAut_cfuni A : ('1_A)^u = '1_A :> 'CF(G). Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed. Lemma cforder_aut phi : #[phi^u]%CF = #[phi]%CF. Proof. exact: cforder_inj_rmorph cfAut_inj. Qed. Lemma cfAutRes phi : ('Res[H] phi)^u = 'Res phi^u. Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed. Lemma cfAutMorph (psi : 'CF(f @* H)) : (cfMorph psi)^u = cfMorph psi^u. Proof. by apply/cfun_inP=> x Hx; rewrite !cfunElock Hx. Qed. Lemma cfAutIsom (isoGR : isom G R f) phi : (cfIsom isoGR phi)^u = cfIsom isoGR phi^u. Proof. apply/cfun_inP=> y; have [_ {1}<-] := isomP isoGR => /morphimP[x _ Gx ->{y}]. by rewrite !(cfunE, cfIsomE). Qed. Lemma cfAutQuo phi : (phi / H)^u = (phi^u / H)%CF. Proof. by apply/cfunP=> Hx; rewrite !cfunElock cfker_aut rmorphMn. Qed. Lemma cfAutMod (psi : 'CF(G / H)) : (psi %% H)^u = (psi^u %% H)%CF. Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed. Lemma cfAutInd (psi : 'CF(H)) : ('Ind[G] psi)^u = 'Ind psi^u. Proof. have [sHG | not_sHG] := boolP (H \subset G). apply/cfunP=> x; rewrite !(cfunE, cfIndE) // rmorphM /= fmorphV rmorph_nat. by congr (_ * _); rewrite rmorph_sum; apply: eq_bigr => y; rewrite !cfunE. rewrite !cfIndEout // linearZ /= cfAut_cfuni rmorphM rmorph_nat /=. rewrite -cfdot_cfAut ?rmorph1 // => _ /imageP[x Hx ->]. by rewrite cfun1E Hx !rmorph1. Qed. Hypothesis KxH : K \x H = G. Lemma cfAutDprodl (phi : 'CF(K)) : (cfDprodl KxH phi)^u = cfDprodl KxH phi^u. Proof. apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]]. by rewrite !(cfunE, cfDprodEl). Qed. Lemma cfAutDprodr (psi : 'CF(H)) : (cfDprodr KxH psi)^u = cfDprodr KxH psi^u. Proof. apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]]. by rewrite !(cfunE, cfDprodEr). Qed. Lemma cfAutDprod (phi : 'CF(K)) (psi : 'CF(H)) : (cfDprod KxH phi psi)^u = cfDprod KxH phi^u psi^u. Proof. by rewrite rmorphM /= cfAutDprodl cfAutDprodr. Qed. End FieldAutomorphism. Arguments cfAutK u {gT G}. Arguments cfAutVK u {gT G}. Arguments cfAut_inj u {gT G} [phi1 phi2] : rename. Definition conj_cfRes := cfAutRes conjC. Definition cfker_conjC := cfker_aut conjC. Definition conj_cfQuo := cfAutQuo conjC. Definition conj_cfMod := cfAutMod conjC. Definition conj_cfInd := cfAutInd conjC. Definition cfconjC_eq1 := cfAut_eq1 conjC.
DegreeSum.lean
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Combinatorics.SimpleGraph.Dart import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Data.ZMod.Basic /-! # Degree-sum formula and handshaking lemma The degree-sum formula is that the sum of the degrees of the vertices in a finite graph is equal to twice the number of edges. The handshaking lemma, a corollary, is that the number of odd-degree vertices is even. ## Main definitions - `SimpleGraph.sum_degrees_eq_twice_card_edges` is the degree-sum formula. - `SimpleGraph.even_card_odd_degree_vertices` is the handshaking lemma. - `SimpleGraph.odd_card_odd_degree_vertices_ne` is that the number of odd-degree vertices different from a given odd-degree vertex is odd. - `SimpleGraph.exists_ne_odd_degree_of_exists_odd_degree` is that the existence of an odd-degree vertex implies the existence of another one. ## Implementation notes We give a combinatorial proof by using the facts that (1) the map from darts to vertices is such that each fiber has cardinality the degree of the corresponding vertex and that (2) the map from darts to edges is 2-to-1. ## Tags simple graphs, sums, degree-sum formula, handshaking lemma -/ assert_not_exists Field TwoSidedIdeal open Finset namespace SimpleGraph universe u variable {V : Type u} (G : SimpleGraph V) section DegreeSum variable [Fintype V] [DecidableRel G.Adj] theorem dart_fst_fiber [DecidableEq V] (v : V) : ({d : G.Dart | d.fst = v} : Finset _) = univ.image (G.dartOfNeighborSet v) := by ext d simp only [mem_image, true_and, mem_filter, SetCoe.exists, mem_univ] constructor · rintro rfl exact ⟨_, d.adj, by ext <;> rfl⟩ · rintro ⟨e, he, rfl⟩ rfl theorem dart_fst_fiber_card_eq_degree [DecidableEq V] (v : V) : #{d : G.Dart | d.fst = v} = G.degree v := by simpa only [dart_fst_fiber, Finset.card_univ, card_neighborSet_eq_degree] using card_image_of_injective univ (G.dartOfNeighborSet_injective v) theorem dart_card_eq_sum_degrees : Fintype.card G.Dart = ∑ v, G.degree v := by haveI := Classical.decEq V simp only [← card_univ, ← dart_fst_fiber_card_eq_degree] exact card_eq_sum_card_fiberwise (by simp) variable {G} in theorem Dart.edge_fiber [DecidableEq V] (d : G.Dart) : ({d' : G.Dart | d'.edge = d.edge} : Finset _) = {d, d.symm} := Finset.ext fun d' => by simpa using dart_edge_eq_iff d' d theorem dart_edge_fiber_card [DecidableEq V] (e : Sym2 V) (h : e ∈ G.edgeSet) : #{d : G.Dart | d.edge = e} = 2 := by obtain ⟨v, w⟩ := e let d : G.Dart := ⟨(v, w), h⟩ convert congr_arg card d.edge_fiber rw [card_insert_of_notMem, card_singleton] rw [mem_singleton] exact d.symm_ne.symm theorem dart_card_eq_twice_card_edges : Fintype.card G.Dart = 2 * #G.edgeFinset := by classical rw [← card_univ] rw [@card_eq_sum_card_fiberwise _ _ _ Dart.edge _ G.edgeFinset fun d _h => by rw [mem_coe, mem_edgeFinset]; apply Dart.edge_mem] rw [← mul_comm, sum_const_nat] intro e h apply G.dart_edge_fiber_card e rwa [← mem_edgeFinset] /-- The degree-sum formula. This is also known as the handshaking lemma, which might more specifically refer to `SimpleGraph.even_card_odd_degree_vertices`. -/ theorem sum_degrees_eq_twice_card_edges : ∑ v, G.degree v = 2 * #G.edgeFinset := G.dart_card_eq_sum_degrees.symm.trans G.dart_card_eq_twice_card_edges lemma two_mul_card_edgeFinset : 2 * #G.edgeFinset = #(univ.filter fun (x, y) ↦ G.Adj x y) := by rw [← dart_card_eq_twice_card_edges, ← card_univ] refine card_bij' (fun d _ ↦ (d.fst, d.snd)) (fun xy h ↦ ⟨xy, (mem_filter.1 h).2⟩) ?_ ?_ ?_ ?_ <;> simp /-- The degree-sum formula only counting over the vertices that form edges. See `SimpleGraph.sum_degrees_eq_twice_card_edges` for the general version. -/ theorem sum_degrees_support_eq_twice_card_edges : ∑ v ∈ G.support, G.degree v = 2 * #G.edgeFinset := by classical simp_rw [← sum_degrees_eq_twice_card_edges, ← sum_add_sum_compl G.support.toFinset, left_eq_add] apply Finset.sum_eq_zero intro v hv rw [degree_eq_zero_iff_notMem_support] rwa [mem_compl, Set.mem_toFinset] at hv end DegreeSum /-- The handshaking lemma. See also `SimpleGraph.sum_degrees_eq_twice_card_edges`. -/ theorem even_card_odd_degree_vertices [Fintype V] [DecidableRel G.Adj] : Even #{v | Odd (G.degree v)} := by classical have h := congr_arg (fun n => ↑n : ℕ → ZMod 2) G.sum_degrees_eq_twice_card_edges simp only [ZMod.natCast_self, zero_mul, Nat.cast_mul] at h rw [Nat.cast_sum, ← sum_filter_ne_zero] at h rw [sum_congr (g := fun _v ↦ (1 : ZMod 2)) rfl] at h · simp only [mul_one, nsmul_eq_mul, sum_const, Ne] at h rw [← ZMod.eq_zero_iff_even] convert h exact ZMod.ne_zero_iff_odd.symm · intro v rw [mem_filter_univ, Ne, ZMod.eq_zero_iff_even, ZMod.eq_one_iff_odd, ← Nat.not_even_iff_odd] tauto theorem odd_card_odd_degree_vertices_ne [Fintype V] [DecidableEq V] [DecidableRel G.Adj] (v : V) (h : Odd (G.degree v)) : Odd #{w | w ≠ v ∧ Odd (G.degree w)} := by rcases G.even_card_odd_degree_vertices with ⟨k, hg⟩ have hk : 0 < k := by have hh : Finset.Nonempty {v : V | Odd (G.degree v)} := by use v rw [mem_filter_univ] exact h rwa [← card_pos, hg, ← two_mul, mul_pos_iff_of_pos_left] at hh exact zero_lt_two have hc : (fun w : V => w ≠ v ∧ Odd (G.degree w)) = fun w : V => Odd (G.degree w) ∧ w ≠ v := by ext w rw [and_comm] simp only [hc] rw [← filter_filter, filter_ne', card_erase_of_mem] · refine ⟨k - 1, tsub_eq_of_eq_add <| hg.trans ?_⟩ omega · rwa [mem_filter_univ] theorem exists_ne_odd_degree_of_exists_odd_degree [Fintype V] [DecidableRel G.Adj] (v : V) (h : Odd (G.degree v)) : ∃ w : V, w ≠ v ∧ Odd (G.degree w) := by haveI := Classical.decEq V rcases G.odd_card_odd_degree_vertices_ne v h with ⟨k, hg⟩ have hg' : 0 < #{w | w ≠ v ∧ Odd (G.degree w)} := by rw [hg] apply Nat.succ_pos rcases card_pos.mp hg' with ⟨w, hw⟩ rw [mem_filter_univ] at hw exact ⟨w, hw⟩ end SimpleGraph
Kleene.lean
/- Copyright (c) 2022 Siddhartha Prasad, Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Siddhartha Prasad, Yaël Dillies -/ import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Ring.InjSurj import Mathlib.Algebra.Ring.Pi import Mathlib.Algebra.Ring.Prod import Mathlib.Tactic.Monotonicity.Attr /-! # Kleene Algebras This file defines idempotent semirings and Kleene algebras, which are used extensively in the theory of computation. An idempotent semiring is a semiring whose addition is idempotent. An idempotent semiring is naturally a semilattice by setting `a ≤ b` if `a + b = b`. A Kleene algebra is an idempotent semiring equipped with an additional unary operator `∗`, the Kleene star. ## Main declarations * `IdemSemiring`: Idempotent semiring * `IdemCommSemiring`: Idempotent commutative semiring * `KleeneAlgebra`: Kleene algebra ## Notation `a∗` is notation for `kstar a` in locale `Computability`. ## References * [D. Kozen, *A completeness theorem for Kleene algebras and the algebra of regular events*] [kozen1994] * https://planetmath.org/idempotentsemiring * https://encyclopediaofmath.org/wiki/Idempotent_semi-ring * https://planetmath.org/kleene_algebra ## TODO Instances for `AddOpposite`, `MulOpposite`, `ULift`, `Subsemiring`, `Subring`, `Subalgebra`. ## Tags kleene algebra, idempotent semiring -/ open Function universe u variable {α β ι : Type*} {π : ι → Type*} /-- An idempotent semiring is a semiring with the additional property that addition is idempotent. -/ class IdemSemiring (α : Type u) extends Semiring α, SemilatticeSup α where protected sup := (· + ·) protected add_eq_sup : ∀ a b : α, a + b = a ⊔ b := by intros rfl /-- The bottom element of an idempotent semiring: `0` by default -/ protected bot : α := 0 protected bot_le : ∀ a, bot ≤ a /-- An idempotent commutative semiring is a commutative semiring with the additional property that addition is idempotent. -/ class IdemCommSemiring (α : Type u) extends CommSemiring α, IdemSemiring α /-- Notation typeclass for the Kleene star `∗`. -/ class KStar (α : Type*) where /-- The Kleene star operator on a Kleene algebra -/ protected kstar : α → α @[inherit_doc] scoped[Computability] postfix:1024 "∗" => KStar.kstar open Computability /-- A Kleene Algebra is an idempotent semiring with an additional unary operator `kstar` (for Kleene star) that satisfies the following properties: * `1 + a * a∗ ≤ a∗` * `1 + a∗ * a ≤ a∗` * If `a * c + b ≤ c`, then `a∗ * b ≤ c` * If `c * a + b ≤ c`, then `b * a∗ ≤ c` -/ class KleeneAlgebra (α : Type*) extends IdemSemiring α, KStar α where protected one_le_kstar : ∀ a : α, 1 ≤ a∗ protected mul_kstar_le_kstar : ∀ a : α, a * a∗ ≤ a∗ protected kstar_mul_le_kstar : ∀ a : α, a∗ * a ≤ a∗ protected mul_kstar_le_self : ∀ a b : α, b * a ≤ b → b * a∗ ≤ b protected kstar_mul_le_self : ∀ a b : α, a * b ≤ b → a∗ * b ≤ b -- See note [lower instance priority] instance (priority := 100) IdemSemiring.toOrderBot [IdemSemiring α] : OrderBot α := { ‹IdemSemiring α› with } -- See note [reducible non-instances] /-- Construct an idempotent semiring from an idempotent addition. -/ abbrev IdemSemiring.ofSemiring [Semiring α] (h : ∀ a : α, a + a = a) : IdemSemiring α := { ‹Semiring α› with le := fun a b ↦ a + b = b le_refl := h le_trans := fun a b c hab hbc ↦ by rw [← hbc, ← add_assoc, hab] le_antisymm := fun a b hab hba ↦ by rwa [← hba, add_comm] sup := (· + ·) le_sup_left := fun a b ↦ by rw [← add_assoc, h] le_sup_right := fun a b ↦ by rw [add_comm, add_assoc, h] sup_le := fun a b c hab hbc ↦ by rwa [add_assoc, hbc] bot := 0 bot_le := zero_add } section IdemSemiring variable [IdemSemiring α] {a b c : α} theorem add_eq_sup (a b : α) : a + b = a ⊔ b := IdemSemiring.add_eq_sup _ _ scoped[Computability] attribute [simp] add_eq_sup theorem add_idem (a : α) : a + a = a := by simp lemma natCast_eq_one {n : ℕ} (nezero : n ≠ 0) : (n : α) = 1 := by rw [← Nat.one_le_iff_ne_zero] at nezero induction n, nezero using Nat.le_induction with | base => exact Nat.cast_one | succ x _ hx => rw [Nat.cast_add, hx, Nat.cast_one, add_idem 1] lemma ofNat_eq_one {n : ℕ} [n.AtLeastTwo] : (ofNat(n) : α) = 1 := natCast_eq_one <| Nat.ne_zero_of_lt Nat.AtLeastTwo.prop theorem nsmul_eq_self : ∀ {n : ℕ} (_ : n ≠ 0) (a : α), n • a = a | 0, h => (h rfl).elim | 1, _ => one_nsmul | n + 2, _ => fun a ↦ by rw [succ_nsmul, nsmul_eq_self n.succ_ne_zero, add_idem] theorem add_eq_left_iff_le : a + b = a ↔ b ≤ a := by simp theorem add_eq_right_iff_le : a + b = b ↔ a ≤ b := by simp alias ⟨_, LE.le.add_eq_left⟩ := add_eq_left_iff_le alias ⟨_, LE.le.add_eq_right⟩ := add_eq_right_iff_le theorem add_le_iff : a + b ≤ c ↔ a ≤ c ∧ b ≤ c := by simp theorem add_le (ha : a ≤ c) (hb : b ≤ c) : a + b ≤ c := add_le_iff.2 ⟨ha, hb⟩ -- See note [lower instance priority] instance (priority := 100) IdemSemiring.toIsOrderedAddMonoid : IsOrderedAddMonoid α := { add_le_add_left := fun a b hbc c ↦ by simp_rw [add_eq_sup] exact sup_le_sup_left hbc _ } -- See note [lower instance priority] instance (priority := 100) IdemSemiring.toCanonicallyOrderedAdd : CanonicallyOrderedAdd α := { exists_add_of_le := fun h ↦ ⟨_, h.add_eq_right.symm⟩ le_self_add := fun a b ↦ add_eq_right_iff_le.1 <| by rw [← add_assoc, add_idem] } -- See note [lower instance priority] instance (priority := 100) IdemSemiring.toMulLeftMono : MulLeftMono α := ⟨fun a b c hbc ↦ add_eq_left_iff_le.1 <| by rw [← mul_add, hbc.add_eq_left]⟩ -- See note [lower instance priority] instance (priority := 100) IdemSemiring.toMulRightMono : MulRightMono α := ⟨fun a b c hbc ↦ add_eq_left_iff_le.1 <| by rw [← add_mul, hbc.add_eq_left]⟩ end IdemSemiring section KleeneAlgebra variable [KleeneAlgebra α] {a b c : α} @[simp] theorem one_le_kstar : 1 ≤ a∗ := KleeneAlgebra.one_le_kstar _ theorem mul_kstar_le_kstar : a * a∗ ≤ a∗ := KleeneAlgebra.mul_kstar_le_kstar _ theorem kstar_mul_le_kstar : a∗ * a ≤ a∗ := KleeneAlgebra.kstar_mul_le_kstar _ theorem mul_kstar_le_self : b * a ≤ b → b * a∗ ≤ b := KleeneAlgebra.mul_kstar_le_self _ _ theorem kstar_mul_le_self : a * b ≤ b → a∗ * b ≤ b := KleeneAlgebra.kstar_mul_le_self _ _ theorem mul_kstar_le (hb : b ≤ c) (ha : c * a ≤ c) : b * a∗ ≤ c := (mul_le_mul_right' hb _).trans <| mul_kstar_le_self ha theorem kstar_mul_le (hb : b ≤ c) (ha : a * c ≤ c) : a∗ * b ≤ c := (mul_le_mul_left' hb _).trans <| kstar_mul_le_self ha theorem kstar_le_of_mul_le_left (hb : 1 ≤ b) : b * a ≤ b → a∗ ≤ b := by simpa using mul_kstar_le hb theorem kstar_le_of_mul_le_right (hb : 1 ≤ b) : a * b ≤ b → a∗ ≤ b := by simpa using kstar_mul_le hb @[simp] theorem le_kstar : a ≤ a∗ := le_trans (le_mul_of_one_le_left' one_le_kstar) kstar_mul_le_kstar @[mono] theorem kstar_mono : Monotone (KStar.kstar : α → α) := fun _ _ h ↦ kstar_le_of_mul_le_left one_le_kstar <| kstar_mul_le (h.trans le_kstar) <| mul_kstar_le_kstar @[simp] theorem kstar_eq_one : a∗ = 1 ↔ a ≤ 1 := ⟨le_kstar.trans_eq, fun h ↦ one_le_kstar.antisymm' <| kstar_le_of_mul_le_left le_rfl <| by rwa [one_mul]⟩ @[simp] lemma kstar_zero : (0 : α)∗ = 1 := kstar_eq_one.2 (zero_le _) @[simp] theorem kstar_one : (1 : α)∗ = 1 := kstar_eq_one.2 le_rfl @[simp] theorem kstar_mul_kstar (a : α) : a∗ * a∗ = a∗ := (mul_kstar_le le_rfl <| kstar_mul_le_kstar).antisymm <| le_mul_of_one_le_left' one_le_kstar @[simp] theorem kstar_eq_self : a∗ = a ↔ a * a = a ∧ 1 ≤ a := ⟨fun h ↦ ⟨by rw [← h, kstar_mul_kstar], one_le_kstar.trans_eq h⟩, fun h ↦ (kstar_le_of_mul_le_left h.2 h.1.le).antisymm le_kstar⟩ @[simp] theorem kstar_idem (a : α) : a∗∗ = a∗ := kstar_eq_self.2 ⟨kstar_mul_kstar _, one_le_kstar⟩ @[simp] theorem pow_le_kstar : ∀ {n : ℕ}, a ^ n ≤ a∗ | 0 => (pow_zero _).trans_le one_le_kstar | n + 1 => by rw [pow_succ'] exact (mul_le_mul_left' pow_le_kstar _).trans mul_kstar_le_kstar end KleeneAlgebra namespace Prod instance instIdemSemiring [IdemSemiring α] [IdemSemiring β] : IdemSemiring (α × β) := { Prod.instSemiring, Prod.instSemilatticeSup _ _, Prod.instOrderBot _ _ with add_eq_sup := fun _ _ ↦ Prod.ext (add_eq_sup _ _) (add_eq_sup _ _) } instance [IdemCommSemiring α] [IdemCommSemiring β] : IdemCommSemiring (α × β) := { Prod.instCommSemiring, Prod.instIdemSemiring with } variable [KleeneAlgebra α] [KleeneAlgebra β] instance : KleeneAlgebra (α × β) := { Prod.instIdemSemiring with kstar := fun a ↦ (a.1∗, a.2∗) one_le_kstar := fun _ ↦ ⟨one_le_kstar, one_le_kstar⟩ mul_kstar_le_kstar := fun _ ↦ ⟨mul_kstar_le_kstar, mul_kstar_le_kstar⟩ kstar_mul_le_kstar := fun _ ↦ ⟨kstar_mul_le_kstar, kstar_mul_le_kstar⟩ mul_kstar_le_self := fun _ _ ↦ And.imp mul_kstar_le_self mul_kstar_le_self kstar_mul_le_self := fun _ _ ↦ And.imp kstar_mul_le_self kstar_mul_le_self } theorem kstar_def (a : α × β) : a∗ = (a.1∗, a.2∗) := rfl @[simp] theorem fst_kstar (a : α × β) : a∗.1 = a.1∗ := rfl @[simp] theorem snd_kstar (a : α × β) : a∗.2 = a.2∗ := rfl end Prod namespace Pi instance instIdemSemiring [∀ i, IdemSemiring (π i)] : IdemSemiring (∀ i, π i) := { Pi.semiring, Pi.instSemilatticeSup, Pi.instOrderBot with add_eq_sup := fun _ _ ↦ funext fun _ ↦ add_eq_sup _ _ } instance [∀ i, IdemCommSemiring (π i)] : IdemCommSemiring (∀ i, π i) := { Pi.commSemiring, Pi.instIdemSemiring with } variable [∀ i, KleeneAlgebra (π i)] instance : KleeneAlgebra (∀ i, π i) := { Pi.instIdemSemiring with kstar := fun a i ↦ (a i)∗ one_le_kstar := fun _ _ ↦ one_le_kstar mul_kstar_le_kstar := fun _ _ ↦ mul_kstar_le_kstar kstar_mul_le_kstar := fun _ _ ↦ kstar_mul_le_kstar mul_kstar_le_self := fun _ _ h _ ↦ mul_kstar_le_self <| h _ kstar_mul_le_self := fun _ _ h _ ↦ kstar_mul_le_self <| h _ } theorem kstar_def (a : ∀ i, π i) : a∗ = fun i ↦ (a i)∗ := rfl @[simp] theorem kstar_apply (a : ∀ i, π i) (i : ι) : a∗ i = (a i)∗ := rfl end Pi namespace Function.Injective -- See note [reducible non-instances] /-- Pullback an `IdemSemiring` instance along an injective function. -/ protected abbrev idemSemiring [IdemSemiring α] [Zero β] [One β] [Add β] [Mul β] [Pow β ℕ] [SMul ℕ β] [NatCast β] [Max β] [Bot β] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (bot : f ⊥ = ⊥) : IdemSemiring β := { hf.semiring f zero one add mul nsmul npow natCast, hf.semilatticeSup _ sup, ‹Bot β› with add_eq_sup := fun a b ↦ hf <| by rw [sup, add, add_eq_sup] bot := ⊥ bot_le := fun a ↦ bot.trans_le <| @bot_le _ _ _ <| f a } -- See note [reducible non-instances] /-- Pullback an `IdemCommSemiring` instance along an injective function. -/ protected abbrev idemCommSemiring [IdemCommSemiring α] [Zero β] [One β] [Add β] [Mul β] [Pow β ℕ] [SMul ℕ β] [NatCast β] [Max β] [Bot β] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (bot : f ⊥ = ⊥) : IdemCommSemiring β := { hf.commSemiring f zero one add mul nsmul npow natCast, hf.idemSemiring f zero one add mul nsmul npow natCast sup bot with } -- See note [reducible non-instances] /-- Pullback a `KleeneAlgebra` instance along an injective function. -/ protected abbrev kleeneAlgebra [KleeneAlgebra α] [Zero β] [One β] [Add β] [Mul β] [Pow β ℕ] [SMul ℕ β] [NatCast β] [Max β] [Bot β] [KStar β] (f : β → α) (hf : Injective f) (zero : f 0 = 0) (one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) (nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (natCast : ∀ n : ℕ, f n = n) (sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (bot : f ⊥ = ⊥) (kstar : ∀ a, f a∗ = (f a)∗) : KleeneAlgebra β := { hf.idemSemiring f zero one add mul nsmul npow natCast sup bot, ‹KStar β› with one_le_kstar := fun a ↦ one.trans_le <| by rw [kstar] exact one_le_kstar mul_kstar_le_kstar := fun a ↦ by change f _ ≤ _ rw [mul, kstar] exact mul_kstar_le_kstar kstar_mul_le_kstar := fun a ↦ by change f _ ≤ _ rw [mul, kstar] exact kstar_mul_le_kstar mul_kstar_le_self := fun a b (h : f _ ≤ _) ↦ by change f _ ≤ _ rw [mul, kstar] rw [mul] at h exact mul_kstar_le_self h kstar_mul_le_self := fun a b (h : f _ ≤ _) ↦ by change f _ ≤ _ rw [mul, kstar] rw [mul] at h exact kstar_mul_le_self h } end Function.Injective
test_intro_rw.v
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Lemma test_dup1 : forall n : nat, odd n. Proof. move=> /[dup] m n; suff: odd n by []. Abort. Lemma test_dup2 : let n := 1 in False. Proof. move=> /[dup] m n; have : m = n := erefl. Abort. Lemma test_swap1 : forall (n : nat) (b : bool), odd n = b. Proof. move=> /[swap] b n; suff: odd n = b by []. Abort. Lemma test_swap1 : let n := 1 in let b := true in False. Proof. move=> /[swap] b n; have : odd n = b := erefl. Abort. Lemma test_apply A B : forall (f : A -> B) (a : A), False. Proof. move=> /[apply] b. Check (b : B). Abort. Lemma test_swap_plus P Q : P -> Q -> False. Proof. move=> + /[dup] q. suff: P -> Q -> False by []. Abort. Lemma test_dup_plus2 P : P -> let x := 0 in False. Proof. move=> + /[dup] y. suff: P -> let x := 0 in False by []. Abort. Lemma test_swap_plus P Q R : P -> Q -> R -> False. Proof. move=> + /[swap]. suff: P -> R -> Q -> False by []. Abort. Lemma test_swap_plus2 P : P -> let x := 0 in let y := 1 in False. Proof. move=> + /[swap]. suff: P -> let y := 1 in let x := 0 in False by []. Abort.
DiscrTree.lean
/- Copyright (c) 2023 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Init import Lean.Meta.DiscrTree /-! # Additions to `Lean.Meta.DiscrTree` -/ namespace Lean.Meta.DiscrTree /-- Find keys which match the expression, or some subexpression. Note that repeated subexpressions will be visited each time they appear, making this operation potentially very expensive. It would be good to solve this problem! Implementation: we reverse the results from `getMatch`, so that we return lemmas matching larger subexpressions first, and amongst those we return more specific lemmas first. -/ partial def getSubexpressionMatches {α : Type} (d : DiscrTree α) (e : Expr) : MetaM (Array α) := do match e with | .bvar _ => return #[] | .forallE _ _ _ _ => forallTelescope e (fun args body => do args.foldlM (fun acc arg => do pure <| acc ++ (← d.getSubexpressionMatches (← inferType arg))) (← d.getSubexpressionMatches body).reverse) | .lam _ _ _ _ | .letE _ _ _ _ _ => lambdaLetTelescope e (fun args body => do args.foldlM (fun acc arg => do pure <| acc ++ (← d.getSubexpressionMatches (← inferType arg))) (← d.getSubexpressionMatches body).reverse) | _ => e.foldlM (fun a f => do pure <| a ++ (← d.getSubexpressionMatches f)) (← d.getMatch e).reverse /-- Check if a `keys : Array DiscTree.Key` is "specific", i.e. something other than `[*]` or `[=, *, *, *]`. -/ def keysSpecific (keys : Array DiscrTree.Key) : Bool := keys != #[Key.star] && keys != #[Key.const ``Eq 3, Key.star, Key.star, Key.star] end Lean.Meta.DiscrTree
LocallyCompactRegular.lean
/- Copyright (c) 2022 Damien Thomine. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damien Thomine -/ import Mathlib.Topology.Sets.Compacts /-! # Second Baire theorem In this file we prove that a locally compact regular topological space has Baire property. -/ open TopologicalSpace Set /-- **Second Baire theorem**: locally compact R₁ spaces are Baire. -/ instance (priority := 100) BaireSpace.of_t2Space_locallyCompactSpace {X : Type*} [TopologicalSpace X] [R1Space X] [LocallyCompactSpace X] : BaireSpace X := by constructor intro f ho hd /- To prove that an intersection of open dense subsets is dense, prove that its intersection with any open neighbourhood `U` is dense. Define recursively a decreasing sequence `K` of compact neighbourhoods: start with some compact neighbourhood inside `U`, then at each step, take its interior, intersect with `f n`, then choose a compact neighbourhood inside the intersection. -/ rw [dense_iff_inter_open] intro U U_open U_nonempty -- Choose an antitone sequence of positive compacts such that `closure (K 0) ⊆ U` -- and `closure (K (n + 1)) ⊆ f n` for all `n` obtain ⟨K, hK_anti, hKf, hKU⟩ : ∃ K : ℕ → PositiveCompacts X, (∀ n, K (n + 1) ≤ K n) ∧ (∀ n, closure ↑(K (n + 1)) ⊆ f n) ∧ closure ↑(K 0) ⊆ U := by rcases U_open.exists_positiveCompacts_closure_subset U_nonempty with ⟨K₀, hK₀⟩ have : ∀ (n) (K : PositiveCompacts X), ∃ K' : PositiveCompacts X, closure ↑K' ⊆ f n ∩ interior K := by refine fun n K ↦ ((ho n).inter isOpen_interior).exists_positiveCompacts_closure_subset ?_ rw [inter_comm] exact (hd n).inter_open_nonempty _ isOpen_interior K.interior_nonempty choose K_next hK_next using this -- The next two lines are faster than a single `refine`. use Nat.rec K₀ K_next refine ⟨fun n ↦ ?_, fun n ↦ (hK_next n _).trans inter_subset_left, hK₀⟩ exact subset_closure.trans <| (hK_next _ _).trans <| inter_subset_right.trans interior_subset -- Prove that ̀`⋂ n : ℕ, closure (K n)` is inside `U ∩ ⋂ n : ℕ, f n`. have hK_subset : (⋂ n, closure (K n) : Set X) ⊆ U ∩ ⋂ n, f n := fun x hx ↦ by simp only [mem_iInter, mem_inter_iff] at hx ⊢ exact ⟨hKU <| hx 0, fun n ↦ hKf n <| hx (n + 1)⟩ /- Prove that `⋂ n : ℕ, closure (K n)` is not empty, as an intersection of a decreasing sequence of nonempty compact closed subsets. -/ have hK_nonempty : (⋂ n, closure (K n) : Set X).Nonempty := IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed _ (fun n => closure_mono <| hK_anti n) (fun n => (K n).nonempty.closure) (K 0).isCompact.closure fun n => isClosed_closure exact hK_nonempty.mono hK_subset
prime.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import choice fintype div bigop. (******************************************************************************) (* This file contains the definitions of: *) (* prime p <=> p is a prime. *) (* primes m == the sorted list of prime divisors of m > 1, else [::]. *) (* pfactor p e == the value p ^ e of a prime factor (p, e). *) (* NumFactor f == print version of a prime factor, converting the prime *) (* component to a Num (which can print large values). *) (* prime_decomp m == the list of prime factors of m > 1, sorted by primes. *) (* logn p m == the e such that (p ^ e) \in prime_decomp n, else 0. *) (* trunc_log p m == the largest e such that p ^ e <= m, or 0 if p <= 1 or *) (* m is 0. *) (* up_log p m == the smallest e such that m <= p ^ e, or 0 if p <= 1 *) (* pdiv n == the smallest prime divisor of n > 1, else 1. *) (* max_pdiv n == the largest prime divisor of n > 1, else 1. *) (* divisors m == the sorted list of divisors of m > 0, else [::]. *) (* totient n == the Euler totient (#|{i < n | i and n coprime}|). *) (* nat_pred == the type of explicit collective nat predicates. *) (* := simpl_pred nat. *) (* -> We allow the coercion nat >-> nat_pred, interpreting p as pred1 p. *) (* -> We define a predType for nat_pred, enabling the notation p \in pi. *) (* -> We don't have nat_pred >-> pred, which would imply nat >-> Funclass. *) (* pi^' == the complement of pi : nat_pred, i.e., the nat_pred such *) (* that (p \in pi^') = (p \notin pi). *) (* \pi(n) == the set of prime divisors of n, i.e., the nat_pred such *) (* that (p \in \pi(n)) = (p \in primes n). *) (* \pi(A) == the set of primes of #|A|, with A a collective predicate *) (* over a finite Type. *) (* -> The notation \pi(A) is implemented with a collapsible Coercion. The *) (* type of A must coerce to finpred_sort (e.g., by coercing to {set T}) *) (* and not merely implement the predType interface (as seq T does). *) (* -> The expression #|A| will only appear in \pi(A) after simplification *) (* collapses the coercion, so it is advisable to do so early on. *) (* pi.-nat n <=> n > 0 and all prime divisors of n are in pi. *) (* n`_pi == the pi-part of n -- the largest pi.-nat divisor of n. *) (* := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. *) (* -> The nat >-> nat_pred coercion lets us write p.-nat n and n`_p. *) (* In addition to the lemmas relevant to these definitions, this file also *) (* contains the dvdn_sum lemma, so that bigop.v doesn't depend on div.v. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "pi ^'" (format "pi ^'"). Reserved Notation "pi .-nat" (format "pi .-nat"). (* The complexity of any arithmetic operation with the Peano representation *) (* is pretty dreadful, so using algorithms for "harder" problems such as *) (* factoring, that are geared for efficient arithmetic leads to dismal *) (* performance -- it takes a significant time, for instance, to compute the *) (* divisors of just a two-digit number. On the other hand, for Peano *) (* integers, prime factoring (and testing) is linear-time with a small *) (* constant factor -- indeed, the same as converting in and out of a binary *) (* representation. This is implemented by the code below, which is then *) (* used to give the "standard" definitions of prime, primes, and divisors, *) (* which can then be used casually in proofs with moderately-sized numeric *) (* values (indeed, the code here performs well for up to 6-digit numbers). *) Module Import PrimeDecompAux. (* We start with faster mod-2 and 2-valuation functions. *) Fixpoint edivn2 q r := if r is r'.+2 then edivn2 q.+1 r' else (q, r). Lemma edivn2P n : edivn_spec n 2 (edivn2 0 n). Proof. rewrite -[n]odd_double_half addnC -{1}[n./2]addn0 -{1}mul2n mulnC. elim: n./2 {1 4}0 => [|r IHr] q; first by case (odd n) => /=. by rewrite addSnnS; apply: IHr. Qed. Fixpoint elogn2 e q r {struct q} := match q, r with | 0, _ | _, 0 => (e, q) | q'.+1, 1 => elogn2 e.+1 q' q' | q'.+1, r'.+2 => elogn2 e q' r' end. Arguments elogn2 : simpl nomatch. Variant elogn2_spec n : nat * nat -> Type := Elogn2Spec e m of n = 2 ^ e * m.*2.+1 : elogn2_spec n (e, m). Lemma elogn2P n : elogn2_spec n.+1 (elogn2 0 n n). Proof. rewrite -[n.+1]mul1n -[1]/(2 ^ 0) -[n in _ * n.+1](addKn n n) addnn. elim: n {1 4 6}n {2 3}0 (leqnn n) => [|q IHq] [|[|r]] e //=; last first. by move/ltnW; apply: IHq. rewrite subn1 prednK // -mul2n mulnA -expnSr. by rewrite -[q in _ * q.+1](addKn q q) addnn => _; apply: IHq. Qed. Definition ifnz T n (x y : T) := if n is 0 then y else x. Variant ifnz_spec T n (x y : T) : T -> Type := | IfnzPos of n > 0 : ifnz_spec n x y x | IfnzZero of n = 0 : ifnz_spec n x y y. Lemma ifnzP T n (x y : T) : ifnz_spec n x y (ifnz n x y). Proof. by case: n => [|n]; [right | left]. Qed. (* The list of divisors and the Euler function are computed directly from *) (* the decomposition, using a merge_sort variant sort of the divisor list. *) Definition add_divisors f divs := let: (p, e) := f in let add1 divs' := merge leq (map (NatTrec.mul p) divs') divs in iter e add1 divs. Import NatTrec. Definition add_totient_factor f m := let: (p, e) := f in p.-1 * p ^ e.-1 * m. Definition cons_pfactor (p e : nat) pd := ifnz e ((p, e) :: pd) pd. Notation "p ^? e :: pd" := (cons_pfactor p e pd) (at level 30, e at level 30, pd at level 60) : nat_scope. End PrimeDecompAux. (* For pretty-printing. *) Definition NumFactor (f : nat * nat) := ([Num of f.1], f.2). Definition pfactor p e := p ^ e. Section prime_decomp. Import NatTrec. Local Fixpoint prime_decomp_rec m k a b c e := let p := k.*2.+1 in if a is a'.+1 then if b - (ifnz e 1 k - c) is b'.+1 then [rec m, k, a', b', ifnz c c.-1 (ifnz e p.-2 1), e] else if (b == 0) && (c == 0) then let b' := k + a' in [rec b'.*2.+3, k, a', b', k.-1, e.+1] else let bc' := ifnz e (ifnz b (k, 0) (edivn2 0 c)) (b, c) in p ^? e :: ifnz a' [rec m, k.+1, a'.-1, bc'.1 + a', bc'.2, 0] [:: (m, 1)] else if (b == 0) && (c == 0) then [:: (p, e.+2)] else p ^? e :: [:: (m, 1)] where "[ 'rec' m , k , a , b , c , e ]" := (prime_decomp_rec m k a b c e). Definition prime_decomp n := let: (e2, m2) := elogn2 0 n.-1 n.-1 in if m2 < 2 then 2 ^? e2 :: 3 ^? m2 :: [::] else let: (a, bc) := edivn m2.-2 3 in let: (b, c) := edivn (2 - bc) 2 in 2 ^? e2 :: [rec m2.*2.+1, 1, a, b, c, 0]. End prime_decomp. Definition primes n := unzip1 (prime_decomp n). Definition prime p := if prime_decomp p is [:: (_ , 1)] then true else false. Definition nat_pred := simpl_pred nat. Definition pi_arg := nat. Coercion pi_arg_of_nat (n : nat) : pi_arg := n. Coercion pi_arg_of_fin_pred T pT (A : @fin_pred_sort T pT) : pi_arg := #|A|. Arguments pi_arg_of_nat n /. Arguments pi_arg_of_fin_pred {T pT} A /. Definition pi_of (n : pi_arg) : nat_pred := [pred p in primes n]. Notation "\pi ( n )" := (pi_of n) (format "\pi ( n )") : nat_scope. Notation "\p 'i' ( A )" := \pi(#|A|) (format "\p 'i' ( A )") : nat_scope. Definition pdiv n := head 1 (primes n). Definition max_pdiv n := last 1 (primes n). Definition divisors n := foldr add_divisors [:: 1] (prime_decomp n). Definition totient n := foldr add_totient_factor (n > 0) (prime_decomp n). (* Correctness of the decomposition algorithm. *) Lemma prime_decomp_correct : let pd_val pd := \prod_(f <- pd) pfactor f.1 f.2 in let lb_dvd q m := ~~ has [pred d | d %| m] (index_iota 2 q) in let pf_ok f := lb_dvd f.1 f.1 && (0 < f.2) in let pd_ord q pd := path ltn q (unzip1 pd) in let pd_ok q n pd := [/\ n = pd_val pd, all pf_ok pd & pd_ord q pd] in forall n, n > 0 -> pd_ok 1 n (prime_decomp n). Proof. rewrite unlock => pd_val lb_dvd pf_ok pd_ord pd_ok. have leq_pd_ok m p q pd: q <= p -> pd_ok p m pd -> pd_ok q m pd. rewrite /pd_ok /pd_ord; case: pd => [|[r _] pd] //= leqp [<- ->]. by case/andP=> /(leq_trans _)->. have apd_ok m e q p pd: lb_dvd p p || (e == 0) -> q < p -> pd_ok p m pd -> pd_ok q (p ^ e * m) (p ^? e :: pd). - case: e => [|e]; rewrite orbC /= => pr_p ltqp. by rewrite mul1n; apply: leq_pd_ok; apply: ltnW. by rewrite /pd_ok /pd_ord /pf_ok /= pr_p ltqp => [[<- -> ->]]. case=> // n _; rewrite /prime_decomp. case: elogn2P => e2 m2 -> {n}; case: m2 => [|[|abc]]; try exact: apd_ok. rewrite [_.-2]/= !ltnS ltn0 natTrecE; case: edivnP => a bc ->{abc}. case: edivnP => b c def_bc /= ltc2 ltbc3; apply: (apd_ok) => //. move def_m: _.*2.+1 => m; set k := {2}1; rewrite -[2]/k.*2; set e := 0. pose p := k.*2.+1; rewrite -{1}[m]mul1n -[1]/(p ^ e)%N. have{def_m bc def_bc ltc2 ltbc3}: let kb := (ifnz e k 1).*2 in [&& k > 0, p < m, lb_dvd p m, c < kb & lb_dvd p p || (e == 0)] /\ m + (b * kb + c).*2 = p ^ 2 + (a * p).*2. - rewrite -def_m [in lb_dvd _ _]def_m; split=> //=; last first. by rewrite -def_bc addSn -doubleD 2!addSn -addnA subnKC // addnC. rewrite ltc2 /lb_dvd /index_iota /= dvdn2 -def_m. by rewrite [_.+2]lock /= odd_double. have [n] := ubnP a. elim: n => // n IHn in a (k) p m b c (e) * => /ltnSE-le_a_n []. set kb := _.*2; set d := _ + c => /and5P[lt0k ltpm leppm ltc pr_p def_m]. have def_k1: k.-1.+1 = k := ltn_predK lt0k. have def_kb1: kb.-1.+1 = kb by rewrite /kb -def_k1; case e. have eq_bc_0: (b == 0) && (c == 0) = (d == 0). by rewrite addn_eq0 muln_eq0 orbC -def_kb1. have lt1p: 1 < p by rewrite ltnS double_gt0. have co_p_2: coprime p 2 by rewrite /coprime gcdnC gcdnE modn2 /= odd_double. have if_d0: d = 0 -> [/\ m = (p + a.*2) * p, lb_dvd p p & lb_dvd p (p + a.*2)]. move=> d0; have{d0} def_m: m = (p + a.*2) * p. by rewrite d0 addn0 -!mul2n mulnA -mulnDl in def_m *. split=> //; apply/hasPn=> r /(hasPn leppm); apply: contra => /= dv_r. by rewrite def_m dvdn_mull. by rewrite def_m dvdn_mulr. case def_a: a => [|a'] /= in le_a_n *; rewrite !natTrecE -/p {}eq_bc_0. case: d if_d0 def_m => [[//| def_m {}pr_p pr_m'] _ | d _ def_m] /=. rewrite def_m def_a addn0 mulnA -2!expnSr. by split; rewrite /pd_ord /pf_ok /= ?muln1 ?pr_p ?leqnn. apply: apd_ok; rewrite // /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm. rewrite /pf_ok !andbT /=; split=> //; apply: contra leppm. case/hasP=> r /=; rewrite mem_index_iota => /andP[lt1r ltrm] dvrm; apply/hasP. have [ltrp | lepr] := ltnP r p. by exists r; rewrite // mem_index_iota lt1r. case/dvdnP: dvrm => q def_q; exists q; last by rewrite def_q /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1r)) -def_q mul1n ltrm. move: def_m; rewrite def_a addn0 -(@ltn_pmul2r p) // mulnn => <-. apply: (@leq_ltn_trans m); first by rewrite def_q leq_mul. by rewrite -addn1 leq_add2l. have def_k2: k.*2 = ifnz e 1 k * kb. by rewrite /kb; case: (e) => [|e']; rewrite (mul1n, muln2). case def_b': (b - _) => [|b']; last first. have ->: ifnz e k.*2.-1 1 = kb.-1 by rewrite /kb; case e. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split=> //. rewrite lt0k ltpm leppm pr_p andbT /=. by case: ifnzP; [move/ltn_predK->; apply: ltnW | rewrite def_kb1]. apply: (@addIn p.*2). rewrite -2!addnA -!doubleD -addnA -mulSnr -def_a -def_m /d. have ->: b * kb = b' * kb + (k.*2 - c * kb + kb). rewrite addnCA addnC -mulSnr -def_b' def_k2 -mulnBl -mulnDl subnK //. by rewrite ltnW // -subn_gt0 def_b'. rewrite -addnA; congr (_ + (_ + _).*2). case: (c) ltc; first by rewrite -addSnnS def_kb1 subn0 addn0 addnC. rewrite /kb; case e => [[] // _ | e' c' _] /=; last first. by rewrite subnDA subnn addnC addSnnS. by rewrite mul1n -doubleB -doubleD subn1 !addn1 def_k1. have ltdp: d < p. move/eqP: def_b'; rewrite subn_eq0 -(@leq_pmul2r kb); last first. by rewrite -def_kb1. rewrite mulnBl -def_k2 ltnS -(leq_add2r c); move/leq_trans; apply. have{} ltc: c < k.*2. by apply: (leq_trans ltc); rewrite leq_double /kb; case e. rewrite -{2}(subnK (ltnW ltc)) leq_add2r leq_sub2l //. by rewrite -def_kb1 mulnS leq_addr. case def_d: d if_d0 => [|d'] => [[//|{ltdp pr_p}def_m pr_p pr_m'] | _]. rewrite eqxx -doubleS -addnS -def_a doubleD -addSn -/p def_m. rewrite mulnCA mulnC -expnSr. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split. rewrite lt0k -addn1 leq_add2l {1}def_a pr_m' pr_p /= def_k1 -addnn. by rewrite leq_addr. rewrite -addnA -doubleD addnCA def_a addSnnS def_k1 -(addnC k) -mulnSr. by rewrite -[_.*2.+1]/p mulnDl doubleD addnA -mul2n mulnA mul2n -mulSn. have next_pm: lb_dvd p.+2 m. rewrite /lb_dvd /index_iota (addKn 2) -(subnK lt1p) iotaD has_cat. apply/norP; split; rewrite //= orbF subnKC // orbC. apply/norP; split; apply/dvdnP=> [[q def_q]]. case/hasP: leppm; exists 2; first by rewrite /p -(subnKC lt0k). by rewrite /= def_q dvdn_mull // dvdn2 /= odd_double. move/(congr1 (dvdn p)): def_m; rewrite -!mul2n mulnA -mulnDl. rewrite dvdn_mull // dvdn_addr; last by rewrite def_q dvdn_mull. case/dvdnP=> r; rewrite mul2n => def_r; move: ltdp (congr1 odd def_r). rewrite odd_double -ltn_double def_r -mul2n ltn_pmul2r //. by case: r def_r => [|[|[]]] //; rewrite def_d // mul1n /= odd_double. apply: apd_ok => //; case: a' def_a le_a_n => [|a'] def_a => [_ | lta] /=. rewrite /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm /pf_ok !andbT /=. split=> //; apply: contra next_pm. case/hasP=> q; rewrite mem_index_iota => /andP[lt1q ltqm] dvqm; apply/hasP. have [ltqp | lepq] := ltnP q p.+2. by exists q; rewrite // mem_index_iota lt1q. case/dvdnP: dvqm => r def_r; exists r; last by rewrite def_r /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1q)) -def_r mul1n ltqm /=. rewrite -(@ltn_pmul2l p.+2) //; apply: (@leq_ltn_trans m). by rewrite def_r mulnC leq_mul. rewrite -addn2 mulnn sqrnD mul2n muln2 -addnn addnACA. by rewrite def_a mul1n in def_m; rewrite -def_m addnS /= ltnS -addnA leq_addr. set bc := ifnz _ _ _; apply: leq_pd_ok (leqnSn _) _. rewrite -doubleS -{1}[m]mul1n -[1]/(k.+1.*2.+1 ^ 0)%N. apply: IHn; first exact: ltnW. rewrite doubleS -/p [ifnz 0 _ _]/=; do 2?split => //. rewrite orbT next_pm /= -(leq_add2r d.*2) def_m 2!addSnnS -doubleS leq_add. - move: ltc; rewrite /kb {}/bc andbT; case e => //= e' _; case: ifnzP => //. by case: edivn2P. - by rewrite -[ltnLHS]muln1 ltn_pmul2l. by rewrite leq_double def_a mulSn (leq_trans ltdp) ?leq_addr. rewrite mulnDl !muln2 -addnA addnCA doubleD addnCA. rewrite (_ : _ + bc.2 = d); last first. rewrite /d {}/bc /kb -muln2. case: (e) (b) def_b' => //= _ []; first by case: edivn2P. by case c; do 2?case; rewrite // mul1n /= muln2. rewrite def_m 3!doubleS addnC -(addn2 p) sqrnD mul2n muln2 -3!addnA. congr (_ + _); rewrite 4!addnS -!doubleD; congr _.*2.+2.+2. by rewrite def_a -add2n mulnDl -addnA -muln2 -mulnDr mul2n. Qed. Lemma primePn n : reflect (n < 2 \/ exists2 d, 1 < d < n & d %| n) (~~ prime n). Proof. rewrite /prime; case: n => [|[|p2]]; try by do 2!left. case: (@prime_decomp_correct p2.+2) => //; rewrite unlock. case: prime_decomp => [|[q [|[|e]]] pd] //=; last first; last by rewrite andbF. rewrite {1}/pfactor 2!expnS -!mulnA /=. case: (_ ^ _ * _) => [|u -> _ /andP[lt1q _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. have lt0q := ltnW lt1q; rewrite lt1q -[ltnLHS]muln1 ltn_pmul2l //. by rewrite -[2]muln1 leq_mul. rewrite {1}/pfactor expn1; case: pd => [|[r e] pd] /=; last first. case: e => [|e] /=; first by rewrite !andbF. rewrite {1}/pfactor expnS -mulnA. case: (_ ^ _ * _) => [|u -> _ /and3P[lt1q ltqr _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. by rewrite lt1q -[ltnLHS]mul1n ltn_mul // -[q.+1]muln1 leq_mul. rewrite muln1 !andbT => def_q pr_q lt1q; right=> [[]] // [d]. by rewrite def_q -mem_index_iota => in_d_2q dv_d_q; case/hasP: pr_q; exists d. Qed. Lemma primeNsig n : ~~ prime n -> 2 <= n -> { d : nat | 1 < d < n & d %| n }. Proof. by move=> /primePn; case: ltnP => // lt1n nP _; apply/sig2W; case: nP. Qed. Lemma primeP p : reflect (p > 1 /\ forall d, d %| p -> xpred2 1 p d) (prime p). Proof. rewrite -[prime p]negbK; have [npr_p | pr_p] := primePn p. right=> [[lt1p pr_p]]; case: npr_p => [|[d n1pd]]. by rewrite ltnNge lt1p. by move/pr_p=> /orP[] /eqP def_d; rewrite def_d ltnn ?andbF in n1pd. have [lep1 | lt1p] := leqP; first by case: pr_p; left. left; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]; case: pr_p; right. exists d; rewrite // andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_nt_dvdP d p : prime p -> d != 1 -> reflect (d = p) (d %| p). Proof. case/primeP=> _ min_p d_neq1; apply: (iffP idP) => [/min_p|-> //]. by rewrite (negPf d_neq1) /= => /eqP. Qed. Arguments primeP {p}. Arguments primePn {n}. Lemma prime_gt1 p : prime p -> 1 < p. Proof. by case/primeP. Qed. Lemma prime_gt0 p : prime p -> 0 < p. Proof. by move/prime_gt1; apply: ltnW. Qed. #[global] Hint Resolve prime_gt1 prime_gt0 : core. Lemma prod_prime_decomp n : n > 0 -> n = \prod_(f <- prime_decomp n) f.1 ^ f.2. Proof. by case/prime_decomp_correct. Qed. Lemma even_prime p : prime p -> p = 2 \/ odd p. Proof. move=> pr_p; case odd_p: (odd p); [by right | left]. have: 2 %| p by rewrite dvdn2 odd_p. by case/primeP: pr_p => _ dv_p /dv_p/(2 =P p). Qed. Lemma prime_oddPn p : prime p -> reflect (p = 2) (~~ odd p). Proof. by move=> p_pr; apply: (iffP idP) => [|-> //]; case/even_prime: p_pr => ->. Qed. Lemma odd_prime_gt2 p : odd p -> prime p -> p > 2. Proof. by move=> odd_p /prime_gt1; apply: odd_gt2. Qed. Lemma mem_prime_decomp n p e : (p, e) \in prime_decomp n -> [/\ prime p, e > 0 & p ^ e %| n]. Proof. case: (posnP n) => [-> //| /prime_decomp_correct[def_n mem_pd ord_pd pd_pe]]. have /andP[pr_p ->] := allP mem_pd _ pd_pe; split=> //; last first. case/splitPr: pd_pe def_n => pd1 pd2 ->. by rewrite big_cat big_cons /= mulnCA dvdn_mulr. have lt1p: 1 < p. apply: (allP (order_path_min ltn_trans ord_pd)). by apply/mapP; exists (p, e). apply/primeP; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]. case/hasP: pr_p; exists d => //. rewrite mem_index_iota andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_coprime p m : prime p -> coprime p m = ~~ (p %| m). Proof. case/primeP=> p_gt1 p_pr; apply/eqP/negP=> [d1 | ndv_pm]. case/dvdnP=> k def_m; rewrite -(addn0 m) def_m gcdnMDl gcdn0 in d1. by rewrite d1 in p_gt1. by apply: gcdn_def => // d /p_pr /orP[] /eqP->. Qed. Lemma dvdn_prime2 p q : prime p -> prime q -> (p %| q) = (p == q). Proof. move=> pr_p pr_q; apply: negb_inj. by rewrite eqn_dvd negb_and -!prime_coprime // coprime_sym orbb. Qed. Lemma Euclid_dvd1 p : prime p -> (p %| 1) = false. Proof. by rewrite dvdn1; case: eqP => // ->. Qed. Lemma Euclid_dvdM m n p : prime p -> (p %| m * n) = (p %| m) || (p %| n). Proof. move=> pr_p; case dv_pm: (p %| m); first exact: dvdn_mulr. by rewrite Gauss_dvdr // prime_coprime // dv_pm. Qed. Lemma Euclid_dvd_prod (I : Type) (r : seq I) (P : pred I) (f : I -> nat) p : prime p -> p %| \prod_(i <- r | P i) f i = \big[orb/false]_(i <- r | P i) (p %| f i). Proof. move=> pP; apply: big_morph=> [x y|]; [exact: Euclid_dvdM | exact: Euclid_dvd1]. Qed. Lemma Euclid_dvdX m n p : prime p -> (p %| m ^ n) = (p %| m) && (n > 0). Proof. case: n => [|n] pr_p; first by rewrite andbF Euclid_dvd1. by apply: (inv_inj negbK); rewrite !andbT -!prime_coprime // coprime_pexpr. Qed. Lemma mem_primes p n : (p \in primes n) = [&& prime p, n > 0 & p %| n]. Proof. rewrite andbCA; have [-> // | /= n_gt0] := posnP. apply/mapP/andP=> [[[q e]]|[pr_p]] /=. case/mem_prime_decomp=> pr_q e_gt0 /dvdnP [u ->] -> {p}. by rewrite -(prednK e_gt0) expnS mulnCA dvdn_mulr. rewrite [n in _ %| n]prod_prime_decomp // big_seq. apply big_ind => [| u v IHu IHv | [q e] /= mem_qe dv_p_qe]. - by rewrite Euclid_dvd1. - by rewrite Euclid_dvdM // => /orP[]. exists (q, e) => //=; case/mem_prime_decomp: mem_qe => pr_q _ _. by rewrite Euclid_dvdX // dvdn_prime2 // in dv_p_qe; case: eqP dv_p_qe. Qed. Lemma sorted_primes n : sorted ltn (primes n). Proof. by case: (posnP n) => [-> // | /prime_decomp_correct[_ _]]; apply: path_sorted. Qed. Lemma all_prime_primes n : all prime (primes n). Proof. by apply/allP => p; rewrite mem_primes => /and3P[]. Qed. Lemma eq_primes m n : (primes m =i primes n) <-> (primes m = primes n). Proof. split=> [eqpr| -> //]. by apply: (irr_sorted_eq ltn_trans ltnn); rewrite ?sorted_primes. Qed. Lemma primes_uniq n : uniq (primes n). Proof. exact: (sorted_uniq ltn_trans ltnn (sorted_primes n)). Qed. (* The smallest prime divisor *) Lemma pi_pdiv n : (pdiv n \in \pi(n)) = (n > 1). Proof. case: n => [|[|n]] //; rewrite /pdiv !inE /primes. have:= prod_prime_decomp (ltn0Sn n.+1); rewrite unlock. by case: prime_decomp => //= pf pd _; rewrite mem_head. Qed. Lemma pdiv_prime n : 1 < n -> prime (pdiv n). Proof. by rewrite -pi_pdiv mem_primes; case/and3P. Qed. Lemma pdiv_dvd n : pdiv n %| n. Proof. by case: n (pi_pdiv n) => [|[|n]] //; rewrite mem_primes=> /and3P[]. Qed. Lemma pi_max_pdiv n : (max_pdiv n \in \pi(n)) = (n > 1). Proof. rewrite !inE -pi_pdiv /max_pdiv /pdiv !inE. by case: (primes n) => //= p ps; rewrite mem_head mem_last. Qed. Lemma max_pdiv_prime n : n > 1 -> prime (max_pdiv n). Proof. by rewrite -pi_max_pdiv mem_primes => /andP[]. Qed. Lemma max_pdiv_dvd n : max_pdiv n %| n. Proof. by case: n (pi_max_pdiv n) => [|[|n]] //; rewrite mem_primes => /andP[]. Qed. Lemma pdiv_leq n : 0 < n -> pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // pdiv_dvd. Qed. Lemma max_pdiv_leq n : 0 < n -> max_pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // max_pdiv_dvd. Qed. Lemma pdiv_gt0 n : 0 < pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?pdiv_prime. Qed. Lemma max_pdiv_gt0 n : 0 < max_pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?max_pdiv_prime. Qed. #[global] Hint Resolve pdiv_gt0 max_pdiv_gt0 : core. Lemma pdiv_min_dvd m d : 1 < d -> d %| m -> pdiv m <= d. Proof. case: (posnP m) => [->|mpos] lt1d dv_d_m; first exact: ltnW. rewrite /pdiv; apply: leq_trans (pdiv_leq (ltnW lt1d)). have: pdiv d \in primes m. by rewrite mem_primes mpos pdiv_prime // (dvdn_trans (pdiv_dvd d)). case: (primes m) (sorted_primes m) => //= p pm ord_pm; rewrite inE. by case/predU1P => [-> | /(allP (order_path_min ltn_trans ord_pm)) /ltnW]. Qed. Lemma max_pdiv_max n p : p \in \pi(n) -> p <= max_pdiv n. Proof. rewrite /max_pdiv !inE => n_p. case/splitPr: n_p (sorted_primes n) => p1 p2; rewrite last_cat -cat_rcons /=. rewrite headI /= cat_path -(last_cons 0) -headI last_rcons; case/andP=> _. move/(order_path_min ltn_trans); case/lastP: p2 => //= p2 q. by rewrite all_rcons last_rcons ltn_neqAle -andbA => /and3P[]. Qed. Lemma ltn_pdiv2_prime n : 0 < n -> n < pdiv n ^ 2 -> prime n. Proof. case def_n: n => [|[|n']] // _; rewrite -def_n => lt_n_p2. suffices ->: n = pdiv n by rewrite pdiv_prime ?def_n. apply/eqP; rewrite eqn_leq leqNgt andbC pdiv_leq; last by rewrite def_n. apply/contraL: lt_n_p2 => lt_pm_m; case/dvdnP: (pdiv_dvd n) => q def_q. rewrite -leqNgt [leqRHS]def_q leq_pmul2r // pdiv_min_dvd //. by rewrite -[pdiv n]mul1n [ltnRHS]def_q ltn_pmul2r in lt_pm_m. by rewrite def_q dvdn_mulr. Qed. Lemma primePns n : reflect (n < 2 \/ exists p, [/\ prime p, p ^ 2 <= n & p %| n]) (~~ prime n). Proof. apply: (iffP idP) => [npr_p|]; last first. case=> [|[p [pr_p le_p2_n dv_p_n]]]; first by case: n => [|[]]. apply/negP=> pr_n; move: dv_p_n le_p2_n; rewrite dvdn_prime2 //; move/eqP->. by rewrite leqNgt -[ltnLHS]muln1 ltn_pmul2l ?prime_gt1 ?prime_gt0. have [lt1p|] := leqP; [right | by left]. exists (pdiv n); rewrite pdiv_dvd pdiv_prime //; split=> //. by case: leqP npr_p => // /ltn_pdiv2_prime -> //; exact: ltnW. Qed. Arguments primePns {n}. Lemma pdivP n : n > 1 -> {p | prime p & p %| n}. Proof. by move=> lt1n; exists (pdiv n); rewrite ?pdiv_dvd ?pdiv_prime. Qed. Lemma primes_eq0 n : (primes n == [::]) = (n < 2). Proof. case: n => [|[|n']]//=; have [//|p pp pn] := @pdivP (n'.+2). suff: p \in primes n'.+2 by case: primes. by rewrite mem_primes pp pn. Qed. Lemma primesM m n p : m > 0 -> n > 0 -> (p \in primes (m * n)) = (p \in primes m) || (p \in primes n). Proof. move=> m_gt0 n_gt0; rewrite !mem_primes muln_gt0 m_gt0 n_gt0. by case pr_p: (prime p); rewrite // Euclid_dvdM. Qed. Lemma primesX m n : n > 0 -> primes (m ^ n) = primes m. Proof. case: n => // n _; rewrite expnS; have [-> // | m_gt0] := posnP m. apply/eq_primes => /= p; elim: n => [|n IHn]; first by rewrite muln1. by rewrite primesM ?(expn_gt0, expnS, IHn, orbb, m_gt0). Qed. Lemma primes_prime p : prime p -> primes p = [:: p]. Proof. move=> pr_p; apply: (irr_sorted_eq ltn_trans ltnn) => // [|q]. exact: sorted_primes. rewrite mem_seq1 mem_primes prime_gt0 //=. by apply/andP/idP=> [[pr_q q_p] | /eqP-> //]; rewrite -dvdn_prime2. Qed. Lemma coprime_has_primes m n : 0 < m -> 0 < n -> coprime m n = ~~ has [in primes m] (primes n). Proof. move=> m_gt0 n_gt0; apply/eqP/hasPn=> [mn1 p | no_p_mn]. rewrite /= !mem_primes m_gt0 n_gt0 /= => /andP[pr_p p_n]. have:= prime_gt1 pr_p; rewrite pr_p ltnNge -mn1 /=; apply: contra => p_m. by rewrite dvdn_leq ?gcdn_gt0 ?m_gt0 // dvdn_gcd ?p_m. apply/eqP; rewrite eqn_leq gcdn_gt0 m_gt0 andbT leqNgt; apply/negP. move/pdiv_prime; set p := pdiv _ => pr_p. move/implyP: (no_p_mn p); rewrite /= !mem_primes m_gt0 n_gt0 pr_p /=. by rewrite !(dvdn_trans (pdiv_dvd _)) // (dvdn_gcdl, dvdn_gcdr). Qed. Lemma pdiv_id p : prime p -> pdiv p = p. Proof. by move=> p_pr; rewrite /pdiv primes_prime. Qed. Lemma pdiv_pfactor p k : prime p -> pdiv (p ^ k.+1) = p. Proof. by move=> p_pr; rewrite /pdiv primesX ?primes_prime. Qed. (* Primes are unbounded. *) Lemma prime_above m : {p | m < p & prime p}. Proof. have /pdivP[p pr_p p_dv_m1]: 1 < m`! + 1 by rewrite addn1 ltnS fact_gt0. exists p => //; rewrite ltnNge; apply: contraL p_dv_m1 => p_le_m. by rewrite dvdn_addr ?dvdn_fact ?prime_gt0 // gtnNdvd ?prime_gt1. Qed. (* "prime" logarithms and p-parts. *) Fixpoint logn_rec d m r := match r, edivn m d with | r'.+1, (_.+1 as m', 0) => (logn_rec d m' r').+1 | _, _ => 0 end. Definition logn p m := if prime p then logn_rec p m m else 0. Lemma lognE p m : logn p m = if [&& prime p, 0 < m & p %| m] then (logn p (m %/ p)).+1 else 0. Proof. rewrite /logn /dvdn; case p_pr: (prime p) => //. case def_m: m => // [m']; rewrite !andTb [LHS]/= -def_m /divn modn_def. case: edivnP def_m => [[|q] [|r] -> _] // def_m; congr _.+1; rewrite [_.1]/=. have{m def_m}: q < m'. by rewrite -ltnS -def_m addn0 mulnC -{1}[q.+1]mul1n ltn_pmul2r // prime_gt1. elim/ltn_ind: m' {q}q.+1 (ltn0Sn q) => -[_ []|r IHr m] //= m_gt0 le_mr. rewrite -[m in logn_rec _ _ m]prednK //=. case: edivnP => [[|q] [|_] def_q _] //; rewrite addn0 in def_q. have{def_q} lt_qm1: q < m.-1. by rewrite -[q.+1]muln1 -ltnS prednK // def_q ltn_pmul2l // prime_gt1. have{le_mr} le_m1r: m.-1 <= r by rewrite -ltnS prednK. by rewrite (IHr r) ?(IHr m.-1) // (leq_trans lt_qm1). Qed. Lemma logn_gt0 p n : (0 < logn p n) = (p \in primes n). Proof. by rewrite lognE -mem_primes; case: {+}(p \in _). Qed. Lemma ltn_log0 p n : n < p -> logn p n = 0. Proof. by case: n => [|n] ltnp; rewrite lognE ?andbF // gtnNdvd ?andbF. Qed. Lemma logn0 p : logn p 0 = 0. Proof. by rewrite /logn if_same. Qed. Lemma logn1 p : logn p 1 = 0. Proof. by rewrite lognE dvdn1 /= andbC; case: eqP => // ->. Qed. Lemma pfactor_gt0 p n : 0 < p ^ logn p n. Proof. by rewrite expn_gt0 lognE; case: (posnP p) => // ->. Qed. #[global] Hint Resolve pfactor_gt0 : core. Lemma pfactor_dvdn p n m : prime p -> m > 0 -> (p ^ n %| m) = (n <= logn p m). Proof. move=> p_pr; elim: n m => [|n IHn] m m_gt0; first exact: dvd1n. rewrite lognE p_pr m_gt0 /=; case dv_pm: (p %| m); last first. apply/dvdnP=> [] [/= q def_m]. by rewrite def_m expnS mulnCA dvdn_mulr in dv_pm. case/dvdnP: dv_pm m_gt0 => q ->{m}; rewrite muln_gt0 => /andP[p_gt0 q_gt0]. by rewrite expnSr dvdn_pmul2r // mulnK // IHn. Qed. Lemma pfactor_dvdnn p n : p ^ logn p n %| n. Proof. case: n => // n; case pr_p: (prime p); first by rewrite pfactor_dvdn. by rewrite lognE pr_p dvd1n. Qed. Lemma logn_prime p q : prime q -> logn p q = (p == q). Proof. move=> pr_q; have q_gt0 := prime_gt0 pr_q; rewrite lognE q_gt0 /=. case pr_p: (prime p); last by case: eqP pr_p pr_q => // -> ->. by rewrite dvdn_prime2 //; case: eqP => // ->; rewrite divnn q_gt0 logn1. Qed. Lemma pfactor_coprime p n : prime p -> n > 0 -> {m | coprime p m & n = m * p ^ logn p n}. Proof. move=> p_pr n_gt0; set k := logn p n. have dv_pk_n: p ^ k %| n by rewrite pfactor_dvdn. exists (n %/ p ^ k); last by rewrite divnK. rewrite prime_coprime // -(@dvdn_pmul2r (p ^ k)) ?expn_gt0 ?prime_gt0 //. by rewrite -expnS divnK // pfactor_dvdn // ltnn. Qed. Lemma pfactorK p n : prime p -> logn p (p ^ n) = n. Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply/eqP; rewrite eqn_leq -pfactor_dvdn // dvdnn andbT. by rewrite -(leq_exp2l _ _ (prime_gt1 p_pr)) dvdn_leq // pfactor_dvdn. Qed. Lemma pfactorKpdiv p n : prime p -> logn (pdiv (p ^ n)) (p ^ n) = n. Proof. by case: n => // n p_pr; rewrite pdiv_pfactor ?pfactorK. Qed. Lemma dvdn_leq_log p m n : 0 < n -> m %| n -> logn p m <= logn p n. Proof. move=> n_gt0 dv_m_n; have m_gt0 := dvdn_gt0 n_gt0 dv_m_n. case p_pr: (prime p); last by do 2!rewrite lognE p_pr /=. by rewrite -pfactor_dvdn //; apply: dvdn_trans dv_m_n; rewrite pfactor_dvdn. Qed. Lemma ltn_logl p n : 0 < n -> logn p n < n. Proof. move=> n_gt0; have [p_gt1 | p_le1] := boolP (1 < p). by rewrite (leq_trans (ltn_expl _ p_gt1)) // dvdn_leq ?pfactor_dvdnn. by rewrite lognE (contraNF (@prime_gt1 _)). Qed. Lemma logn_Gauss p m n : coprime p m -> logn p (m * n) = logn p n. Proof. move=> co_pm; case p_pr: (prime p); last by rewrite /logn p_pr. have [-> | n_gt0] := posnP n; first by rewrite muln0. have [m0 | m_gt0] := posnP m; first by rewrite m0 prime_coprime ?dvdn0 in co_pm. have mn_gt0: m * n > 0 by rewrite muln_gt0 m_gt0. apply/eqP; rewrite eqn_leq andbC dvdn_leq_log ?dvdn_mull //. set k := logn p _; have: p ^ k %| m * n by rewrite pfactor_dvdn. by rewrite Gauss_dvdr ?coprimeXl // -pfactor_dvdn. Qed. Lemma logn_coprime p m : coprime p m -> logn p m = 0. Proof. by move=> coprime_pm; rewrite -[m]muln1 logn_Gauss// logn1. Qed. Lemma lognM p m n : 0 < m -> 0 < n -> logn p (m * n) = logn p m + logn p n. Proof. case p_pr: (prime p); last by rewrite /logn p_pr. have xlp := pfactor_coprime p_pr. case/xlp=> m' co_m' def_m /xlp[n' co_n' def_n] {xlp}. rewrite [in LHS]def_m [in LHS]def_n mulnCA -mulnA -expnD !logn_Gauss //. exact: pfactorK. Qed. Lemma lognX p m n : logn p (m ^ n) = n * logn p m. Proof. case p_pr: (prime p); last by rewrite /logn p_pr muln0. elim: n => [|n IHn]; first by rewrite logn1. have [->|m_gt0] := posnP m; first by rewrite exp0n // lognE andbF muln0. by rewrite expnS lognM ?IHn // expn_gt0 m_gt0. Qed. Lemma logn_div p m n : m %| n -> logn p (n %/ m) = logn p n - logn p m. Proof. rewrite dvdn_eq => /eqP def_n. case: (posnP n) => [-> |]; first by rewrite div0n logn0. by rewrite -{1 3}def_n muln_gt0 => /andP[q_gt0 m_gt0]; rewrite lognM ?addnK. Qed. Lemma dvdn_pfactor p d n : prime p -> reflect (exists2 m, m <= n & d = p ^ m) (d %| p ^ n). Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply: (iffP idP) => [dv_d_pn|[m le_m_n ->]]; last first. by rewrite -(subnK le_m_n) expnD dvdn_mull. exists (logn p d); first by rewrite -(pfactorK n p_pr) dvdn_leq_log. have d_gt0: d > 0 by apply: dvdn_gt0 dv_d_pn. case: (pfactor_coprime p_pr d_gt0) => q co_p_q def_d. rewrite [LHS]def_d ((q =P 1) _) ?mul1n // -dvdn1. suff: q %| p ^ n * 1 by rewrite Gauss_dvdr // coprime_sym coprimeXl. by rewrite muln1 (dvdn_trans _ dv_d_pn) // def_d dvdn_mulr. Qed. Lemma prime_decompE n : prime_decomp n = [seq (p, logn p n) | p <- primes n]. Proof. case: n => // n; pose f0 := (0, 0); rewrite -map_comp. apply: (@eq_from_nth _ f0) => [|i lt_i_n]; first by rewrite size_map. rewrite (nth_map f0) //; case def_f: (nth _ _ i) => [p e] /=. congr (_, _); rewrite [n.+1]prod_prime_decomp //. have: (p, e) \in prime_decomp n.+1 by rewrite -def_f mem_nth. case/mem_prime_decomp=> pr_p _ _. rewrite (big_nth f0) big_mkord (bigD1 (Ordinal lt_i_n)) //=. rewrite def_f mulnC logn_Gauss ?pfactorK //. apply big_ind => [|m1 m2 com1 com2| [j ltj] /=]; first exact: coprimen1. by rewrite coprimeMr com1. rewrite -val_eqE /= => nji; case def_j: (nth _ _ j) => [q e1] /=. have: (q, e1) \in prime_decomp n.+1 by rewrite -def_j mem_nth. case/mem_prime_decomp=> pr_q e1_gt0 _; rewrite coprime_pexpr //. rewrite prime_coprime // dvdn_prime2 //; apply: contra nji => eq_pq. rewrite -(nth_uniq 0 _ _ (primes_uniq n.+1)) ?size_map //=. by rewrite !(nth_map f0) // def_f def_j /= eq_sym. Qed. (* Some combinatorial formulae. *) Lemma divn_count_dvd d n : n %/ d = \sum_(1 <= i < n.+1) (d %| i). Proof. have [-> | d_gt0] := posnP d; first by rewrite big_add1 divn0 big1. apply: (@addnI (d %| 0)); rewrite -(@big_ltn _ 0 _ 0 _ (dvdn d)) // big_mkord. rewrite (partition_big (fun i : 'I_n.+1 => inord (i %/ d)) 'I_(n %/ d).+1) //=. rewrite dvdn0 add1n -[_.+1 in LHS]card_ord -sum1_card. apply: eq_bigr => [[q ?] _]. rewrite (bigD1 (inord (q * d))) /eq_op /= !inordK ?ltnS -?leq_divRL ?mulnK //. rewrite dvdn_mull ?big1 // => [[i /= ?] /andP[/eqP <- /negPf]]. by rewrite eq_sym dvdn_eq inordK ?ltnS ?leq_div2r // => ->. Qed. Lemma logn_count_dvd p n : prime p -> logn p n = \sum_(1 <= k < n) (p ^ k %| n). Proof. rewrite big_add1 => p_prime; case: n => [|n]; first by rewrite logn0 big_geq. rewrite big_mkord -big_mkcond (eq_bigl _ _ (fun _ => pfactor_dvdn _ _ _)) //=. by rewrite big_ord_narrow ?sum1_card ?card_ord // -ltnS ltn_logl. Qed. (* Truncated real log. *) Definition trunc_log p n := let fix loop n k := if k is k'.+1 then if p <= n then (loop (n %/ p) k').+1 else 0 else 0 in if p <= 1 then 0 else loop n n. Lemma trunc_log0 p : trunc_log p 0 = 0. Proof. by case: p => [] // []. Qed. Lemma trunc_log1 p : trunc_log p 1 = 0. Proof. by case: p => [|[]]. Qed. Lemma trunc_log_bounds p n : 1 < p -> 0 < n -> let k := trunc_log p n in p ^ k <= n < p ^ k.+1. Proof. rewrite {+}/trunc_log => p_gt1; have p_gt0 := ltnW p_gt1. rewrite [p <= 1]leqNgt p_gt1 /=. set loop := (loop in loop n n); set m := n; rewrite [in n in loop m n]/m. have: m <= n by []; elim: n m => [|n IHn] [|m] //= /ltnSE-le_m_n _. have [le_p_n | // ] := leqP p _; rewrite 2!expnSr -leq_divRL -?ltn_divLR //. by apply: IHn; rewrite ?divn_gt0 // -ltnS (leq_trans (ltn_Pdiv _ _)). Qed. Lemma trunc_logP p n : 1 < p -> 0 < n -> p ^ trunc_log p n <= n. Proof. by move=> p_gt1 /(trunc_log_bounds p_gt1)/andP[]. Qed. Lemma trunc_log_ltn p n : 1 < p -> n < p ^ (trunc_log p n).+1. Proof. have [-> | n_gt0] := posnP n; first by rewrite trunc_log0 => /ltnW. by case/trunc_log_bounds/(_ n_gt0)/andP. Qed. Lemma trunc_log_max p k j : 1 < p -> p ^ j <= k -> j <= trunc_log p k. Proof. move=> p_gt1 le_pj_k; rewrite -ltnS -(@ltn_exp2l p) //. exact: leq_ltn_trans (trunc_log_ltn _ _). Qed. Lemma trunc_log_eq0 p n : (trunc_log p n == 0) = (p <= 1) || (n <= p.-1). Proof. case: p => [|[|p]]; case: n => // n; rewrite /= ltnS. have /= /andP[] := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+1). case: trunc_log => [//|k] b1 b2. apply/idP/idP => [/eqP sk0 | nlep]; first by move: b2; rewrite sk0. symmetry; rewrite -[_ == _]/false /is_true -b1; apply/negbTE; rewrite -ltnNge. move: nlep; rewrite -ltnS => nlep; apply: (leq_ltn_trans nlep). by rewrite -[leqLHS]expn1; apply: leq_pexp2l. Qed. Lemma trunc_log_gt0 p n : (0 < trunc_log p n) = (1 < p) && (p.-1 < n). Proof. by rewrite ltnNge leqn0 trunc_log_eq0 negb_or -!ltnNge. Qed. Lemma trunc_log0n n : trunc_log 0 n = 0. Proof. by []. Qed. Lemma trunc_log1n n : trunc_log 1 n = 0. Proof. by []. Qed. Lemma leq_trunc_log p m n : m <= n -> trunc_log p m <= trunc_log p n. Proof. move=> mlen; case: p => [|[|p]]; rewrite ?trunc_log0n ?trunc_log1n //. case: m mlen => [|m] mlen; first by rewrite trunc_log0. apply/trunc_log_max => //; apply: leq_trans mlen; exact: trunc_logP. Qed. Lemma trunc_log_eq p n k : 1 < p -> p ^ n <= k < p ^ n.+1 -> trunc_log p k = n. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/anti_leq. rewrite trunc_log_max// andbT -ltnS -(ltn_exp2l _ _ p_gt1). apply: leq_ltn_trans kLpn; apply: trunc_logP => //. by apply: leq_trans npLk; rewrite expn_gt0 ltnW. Qed. Lemma trunc_lognn p : 1 < p -> trunc_log p p = 1. Proof. by case: p => [|[|p]] // _; rewrite /trunc_log ltnSn divnn. Qed. Lemma trunc_expnK p n : 1 < p -> trunc_log p (p ^ n) = n. Proof. by move=> ?; apply: trunc_log_eq; rewrite // leqnn ltn_exp2l /=. Qed. Lemma trunc_logMp p n : 1 < p -> 0 < n -> trunc_log p (p * n) = (trunc_log p n).+1. Proof. case: p => [//|p] => p_gt0 n_gt0; apply: trunc_log_eq => //. rewrite expnS leq_pmul2l// trunc_logP//=. by rewrite expnS ltn_pmul2l// trunc_log_ltn. Qed. Lemma trunc_log2_double n : 0 < n -> trunc_log 2 n.*2 = (trunc_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n trunc_logMp. Qed. Lemma trunc_log2S n : 1 < n -> trunc_log 2 n = (trunc_log 2 n./2).+1. Proof. move=> n_gt1. rewrite -trunc_log2_double ?half_gt0//. rewrite -[n in LHS]odd_double_half. case: odd => //; rewrite add1n. apply: trunc_log_eq => //. rewrite leqW ?trunc_logP //= ?double_gt0 ?half_gt0//. rewrite trunc_log2_double ?half_gt0// expnS. by rewrite -doubleS mul2n leq_double trunc_log_ltn. Qed. (* Truncated up real logarithm *) Definition up_log p n := if (p <= 1) then 0 else let v := trunc_log p n in if n <= p ^ v then v else v.+1. Lemma up_log0 p : up_log p 0 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log1 p : up_log p 1 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log_eq0 p n : (up_log p n == 0) = (p <= 1) || (n <= 1). Proof. case: p => // [] [] // p. case: n => [|[|n]]; rewrite /up_log //=. have /= := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+2). by case: (leqP _ n.+1); case: trunc_log. Qed. Lemma up_log_gt0 p n : (0 < up_log p n) = (1 < p) && (1 < n). Proof. by rewrite ltnNge leqn0 up_log_eq0 negb_or -!ltnNge. Qed. Lemma up_log_bounds p n : 1 < p -> 1 < n -> let k := up_log p n in p ^ k.-1 < n <= p ^ k. Proof. move=> p_gt1 n_gt1. have n_gt0 : 0 < n by apply: leq_trans n_gt1. rewrite /up_log (leqNgt p 1) p_gt1 /=. have /= /andP[tpLn nLtpS] := trunc_log_bounds p_gt1 n_gt0. have [nLnp|npLn] := leqP n (p ^ trunc_log p n); last by rewrite npLn ltnW. rewrite nLnp (leq_trans _ tpLn) // ltn_exp2l // prednK ?leqnn //. by case: trunc_log (leq_trans n_gt1 nLnp). Qed. Lemma up_logP p n : 1 < p -> n <= p ^ up_log p n. Proof. case: n => [|[|n]] // p_gt1; first by rewrite up_log1. by have /andP[] := up_log_bounds p_gt1 (isT: 1 < n.+2). Qed. Lemma up_log_gtn p n : 1 < p -> 1 < n -> p ^ (up_log p n).-1 < n. Proof. by case: n => [|[|n]] p_gt1 n_gt1 //; have /andP[] := up_log_bounds p_gt1 n_gt1. Qed. Lemma up_log_min p k j : 1 < p -> k <= p ^ j -> up_log p k <= j. Proof. case: k => [|[|k]] // p_gt1 kLj; rewrite ?(up_log0, up_log1) //. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt1 // -(@ltn_exp2l p) //. by apply: leq_trans (up_log_gtn p_gt1 (isT : 1 < k.+2)) _. Qed. Lemma leq_up_log p m n : m <= n -> up_log p m <= up_log p n. Proof. move=> mLn; case: p => [|[|p]] //. by apply/up_log_min => //; apply: leq_trans mLn (up_logP _ _). Qed. Lemma up_log_eq p n k : 1 < p -> p ^ n < k <= p ^ n.+1 -> up_log p k = n.+1. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/eqP; rewrite eqn_leq. apply/andP; split; first by apply: up_log_min. rewrite -(ltn_exp2l _ _ p_gt1) //. by apply: leq_trans npLk (up_logP _ _). Qed. Lemma up_lognn p : 1 < p -> up_log p p = 1. Proof. by move=> p_gt1; apply: up_log_eq; rewrite p_gt1 /=. Qed. Lemma up_expnK p n : 1 < p -> up_log p (p ^ n) = n. Proof. case: n => [|n] p_gt1 /=; first by rewrite up_log1. by apply: up_log_eq; rewrite // leqnn andbT ltn_exp2l. Qed. Lemma up_logMp p n : 1 < p -> 0 < n -> up_log p (p * n) = (up_log p n).+1. Proof. case: p => [//|p] p_gt0. case: n => [//|[|n]] _; first by rewrite muln1 up_lognn// up_log1. apply: up_log_eq => //. rewrite expnS leq_pmul2l// up_logP// andbT. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt0 //. by rewrite expnS ltn_pmul2l// up_log_gtn. Qed. Lemma up_log2_double n : 0 < n -> up_log 2 n.*2 = (up_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n up_logMp. Qed. Lemma up_log2S n : 0 < n -> up_log 2 n.+1 = (up_log 2 (n./2.+1)).+1. Proof. case: n=> // [] [|n] // _. apply: up_log_eq => //; apply/andP; split. apply: leq_trans (_ : n./2.+1.*2 < n.+3); last first. by rewrite doubleS !ltnS -[leqRHS]odd_double_half leq_addl. have /= /andP[H1n _] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). by rewrite ltnS -leq_double -mul2n -expnS prednK ?up_log_gt0 // in H1n. rewrite -[_./2.+1]/(n./2.+2). have /= /andP[_ H2n] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). rewrite -leq_double -!mul2n -expnS in H2n. apply: leq_trans H2n. rewrite mul2n !doubleS !ltnS. by rewrite -[leqLHS]odd_double_half -add1n leq_add2r; case: odd. Qed. Lemma up_log_trunc_log p n : 1 < p -> 1 < n -> up_log p n = (trunc_log p n.-1).+1. Proof. move=> p_gt1 n_gt1; apply: up_log_eq => //. rewrite -[n]prednK ?ltnS -?pred_Sn ?[0 < n]ltnW//. by rewrite trunc_logP ?ltn_predRL// trunc_log_ltn. Qed. Lemma trunc_log_up_log p n : 1 < p -> 0 < n -> trunc_log p n = (up_log p n.+1).-1. Proof. by move=> ? ?; rewrite up_log_trunc_log. Qed. (* pi- parts *) (* Testing for membership in set of prime factors. *) Canonical nat_pred_pred := Eval hnf in [predType of nat_pred]. Coercion nat_pred_of_nat (p : nat) : nat_pred := pred1 p. Section NatPreds. Variables (n : nat) (pi : nat_pred). Definition negn : nat_pred := [predC pi]. Definition pnat : pred nat := fun m => (m > 0) && all [in pi] (primes m). Definition partn := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. End NatPreds. Notation "pi ^'" := (negn pi) : nat_scope. Notation "pi .-nat" := (pnat pi) : nat_scope. Notation "n `_ pi" := (partn n pi) : nat_scope. Section PnatTheory. Implicit Types (n p : nat) (pi rho : nat_pred). Lemma negnK pi : pi^'^' =i pi. Proof. by move=> p; apply: negbK. Qed. Lemma eq_negn pi1 pi2 : pi1 =i pi2 -> pi1^' =i pi2^'. Proof. by move=> eq_pi n; rewrite inE eq_pi. Qed. Lemma eq_piP m n : \pi(m) =i \pi(n) <-> \pi(m) = \pi(n). Proof. rewrite /pi_of; have eqs := irr_sorted_eq ltn_trans ltnn. by split=> [|-> //] /(eqs _ _ (sorted_primes m) (sorted_primes n)) ->. Qed. Lemma part_gt0 pi n : 0 < n`_pi. Proof. exact: prodn_gt0. Qed. Hint Resolve part_gt0 : core. Lemma sub_in_partn pi1 pi2 n : {in \pi(n), {subset pi1 <= pi2}} -> n`_pi1 %| n`_pi2. Proof. move=> pi12; rewrite ![n`__]big_mkcond /=. apply (big_ind2 (fun m1 m2 => m1 %| m2)) => // [*|p _]; first exact: dvdn_mul. rewrite lognE -mem_primes; case: ifP => pi1p; last exact: dvd1n. by case: ifP => pr_p; [rewrite pi12 | rewrite if_same]. Qed. Lemma eq_in_partn pi1 pi2 n : {in \pi(n), pi1 =i pi2} -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply/eqP; rewrite eqn_dvd ?sub_in_partn // => p /pi12->. Qed. Lemma eq_partn pi1 pi2 n : pi1 =i pi2 -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply: eq_in_partn => p _. Qed. Lemma partnNK pi n : n`_pi^'^' = n`_pi. Proof. by apply: eq_partn; apply: negnK. Qed. Lemma widen_partn m pi n : n <= m -> n`_pi = \prod_(0 <= p < m.+1 | p \in pi) p ^ logn p n. Proof. move=> le_n_m; rewrite big_mkcond /=. rewrite [n`_pi](big_nat_widen _ _ m.+1) // big_mkcond /=. apply: eq_bigr => p _; rewrite ltnS lognE. by case: and3P => [[_ n_gt0 p_dv_n]|]; rewrite ?if_same // andbC dvdn_leq. Qed. Lemma eq_partn_from_log m n (pi : nat_pred) : 0 < m -> 0 < n -> {in pi, logn^~ m =1 logn^~ n} -> m`_pi = n`_pi. Proof. move=> m0 n0 eq_log; rewrite !(@widen_partn (maxn m n)) ?leq_maxl ?leq_maxr//. by apply: eq_bigr => p /eq_log ->. Qed. Lemma partn0 pi : 0`_pi = 1. Proof. by apply: big1_seq => [] [|n]; rewrite andbC. Qed. Lemma partn1 pi : 1`_pi = 1. Proof. by apply: big1_seq => [] [|[|n]]; rewrite andbC. Qed. Lemma partnM pi m n : m > 0 -> n > 0 -> (m * n)`_pi = m`_pi * n`_pi. Proof. have le_pmul m' n': m' > 0 -> n' <= m' * n' by move/prednK <-; apply: leq_addr. move=> mpos npos; rewrite !(@widen_partn (n * m)) 3?(le_pmul, mulnC) //. rewrite !big_mkord -big_split; apply: eq_bigr => p _ /=. by rewrite lognM // expnD. Qed. Lemma partnX pi m n : (m ^ n)`_pi = m`_pi ^ n. Proof. elim: n => [|n IHn]; first exact: partn1. rewrite expnS; have [->|m_gt0] := posnP m; first by rewrite partn0 exp1n. by rewrite expnS partnM ?IHn // expn_gt0 m_gt0. Qed. Lemma partn_dvd pi m n : n > 0 -> m %| n -> m`_pi %| n`_pi. Proof. move=> n_gt0 dvmn; case/dvdnP: dvmn n_gt0 => q ->{n}. by rewrite muln_gt0 => /andP[q_gt0 m_gt0]; rewrite partnM ?dvdn_mull. Qed. Lemma p_part p n : n`_p = p ^ logn p n. Proof. case (posnP (logn p n)) => [log0 |]. by rewrite log0 [n`_p]big1_seq // => q /andP [/eqP ->]; rewrite log0. rewrite logn_gt0 mem_primes; case/and3P=> _ n_gt0 dv_p_n. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. by rewrite [n`_p]big_mkord (big_pred1 (Ordinal le_p_n)). Qed. Lemma p_part_eq1 p n : (n`_p == 1) = (p \notin \pi(n)). Proof. rewrite mem_primes p_part lognE; case: and3P => // [[p_pr _ _]]. by rewrite -dvdn1 pfactor_dvdn // logn1. Qed. Lemma p_part_gt1 p n : (n`_p > 1) = (p \in \pi(n)). Proof. by rewrite ltn_neqAle part_gt0 andbT eq_sym p_part_eq1 negbK. Qed. Lemma primes_part pi n : primes n`_pi = filter [in pi] (primes n). Proof. have ltnT := ltn_trans; have [->|n_gt0] := posnP n; first by rewrite partn0. apply: (irr_sorted_eq ltnT ltnn); rewrite ?(sorted_primes, sorted_filter) //. move=> p; rewrite mem_filter /= !mem_primes n_gt0 part_gt0 /=. apply/andP/and3P=> [[p_pr] | [pi_p p_pr dv_p_n]]. rewrite /partn; apply big_ind => [|n1 n2 IHn1 IHn2|q pi_q]. - by rewrite dvdn1; case: eqP p_pr => // ->. - by rewrite Euclid_dvdM //; case/orP. rewrite -{1}(expn1 p) pfactor_dvdn // lognX muln_gt0. rewrite logn_gt0 mem_primes n_gt0 - andbA /=; case/and3P=> pr_q dv_q_n. by rewrite logn_prime //; case: eqP => // ->. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. rewrite [n`_pi]big_mkord (bigD1 (Ordinal le_p_n)) //= dvdn_mulr //. by rewrite lognE p_pr n_gt0 dv_p_n expnS dvdn_mulr. Qed. Lemma filter_pi_of n m : n < m -> filter \pi(n) (index_iota 0 m) = primes n. Proof. move=> lt_n_m; have ltnT := ltn_trans; apply: (irr_sorted_eq ltnT ltnn). - by rewrite sorted_filter // iota_ltn_sorted. - exact: sorted_primes. move=> p; rewrite mem_filter mem_index_iota /= mem_primes; case: and3P => //. by case=> _ n_gt0 dv_p_n; apply: leq_ltn_trans lt_n_m; apply: dvdn_leq. Qed. Lemma partn_pi n : n > 0 -> n`_\pi(n) = n. Proof. move=> n_gt0; rewrite [RHS]prod_prime_decomp // prime_decompE big_map. by rewrite -[n`__]big_filter filter_pi_of. Qed. Lemma partnT n : n > 0 -> n`_predT = n. Proof. move=> n_gt0; rewrite -[RHS]partn_pi // [RHS]/partn big_mkcond /=. by apply: eq_bigr => p _; rewrite -logn_gt0; case: (logn p _). Qed. Lemma eqn_from_log m n : 0 < m -> 0 < n -> logn^~ m =1 logn^~ n -> m = n. Proof. by move=> ? ? /(@in1W _ predT)/eq_partn_from_log; rewrite !partnT// => ->. Qed. Lemma partnC pi n : n > 0 -> n`_pi * n`_pi^' = n. Proof. move=> n_gt0; rewrite -[RHS]partnT /partn //. do 2!rewrite mulnC big_mkcond /=; rewrite -big_split; apply: eq_bigr => p _ /=. by rewrite mulnC inE /=; case: (p \in pi); rewrite /= (muln1, mul1n). Qed. Lemma dvdn_part pi n : n`_pi %| n. Proof. by case: n => // n; rewrite -{2}[n.+1](@partnC pi) // dvdn_mulr. Qed. Lemma logn_part p m : logn p m`_p = logn p m. Proof. case p_pr: (prime p); first by rewrite p_part pfactorK. by rewrite lognE (lognE p m) p_pr. Qed. Lemma partn_lcm pi m n : m > 0 -> n > 0 -> (lcmn m n)`_pi = lcmn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: lcmn m n > 0 by rewrite lcmn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_lcm !partn_dvd ?dvdn_lcml ?dvdn_lcmr //. rewrite -(dvdn_pmul2r (part_gt0 pi^' (lcmn m n))) partnC // dvdn_lcm !andbT. rewrite -[m in m %| _](partnC pi m_gt0) andbC -[n in n %| _](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_lcml ?dvdn_lcmr. Qed. Lemma partn_gcd pi m n : m > 0 -> n > 0 -> (gcdn m n)`_pi = gcdn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: gcdn m n > 0 by rewrite gcdn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_gcd !partn_dvd ?dvdn_gcdl ?dvdn_gcdr //=. rewrite -(dvdn_pmul2r (part_gt0 pi^' (gcdn m n))) partnC // dvdn_gcd. rewrite -[m in _ %| m](partnC pi m_gt0) andbC -[n in _%| n](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_gcdl ?dvdn_gcdr. Qed. Lemma partn_biglcm (I : finType) (P : pred I) F pi : (forall i, P i -> F i > 0) -> (\big[lcmn/1%N]_(i | P i) F i)`_pi = \big[lcmn/1%N]_(i | P i) (F i)`_pi. Proof. move=> F_gt0; set m := \big[lcmn/1%N]_(i | P i) F i. have m_gt0: 0 < m by elim/big_ind: m => // p q p_gt0; rewrite lcmn_gt0 p_gt0. apply/eqP; rewrite eqn_dvd andbC; apply/andP; split. by apply/dvdn_biglcmP=> i Pi; rewrite partn_dvd // (@biglcmn_sup _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' m)) partnC //. apply/dvdn_biglcmP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biglcmn_sup _ i). by rewrite partn_dvd // (@biglcmn_sup _ i). Qed. Lemma partn_biggcd (I : finType) (P : pred I) F pi : #|SimplPred P| > 0 -> (forall i, P i -> F i > 0) -> (\big[gcdn/0]_(i | P i) F i)`_pi = \big[gcdn/0]_(i | P i) (F i)`_pi. Proof. move=> ntP F_gt0; set d := \big[gcdn/0]_(i | P i) F i. have d_gt0: 0 < d. case/card_gt0P: ntP => i /= Pi; have:= F_gt0 i Pi. rewrite !lt0n -!dvd0n; apply: contra => dv0d. by rewrite (dvdn_trans dv0d) // (@biggcdn_inf _ i). apply/eqP; rewrite eqn_dvd; apply/andP; split. by apply/dvdn_biggcdP=> i Pi; rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' d)) partnC //. apply/dvdn_biggcdP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biggcdn_inf _ i). by rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). Qed. Lemma logn_gcd p m n : 0 < m -> 0 < n -> logn p (gcdn m n) = minn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; case p_pr: (prime p); last by rewrite /logn p_pr. by apply: (@expnI p); rewrite ?prime_gt1// expn_min -!p_part partn_gcd. Qed. Lemma logn_lcm p m n : 0 < m -> 0 < n -> logn p (lcmn m n) = maxn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; rewrite /lcmn logn_div ?dvdn_mull ?dvdn_gcdr//. by rewrite lognM// logn_gcd// -addn_min_max addnC addnK. Qed. Lemma sub_in_pnat pi rho n : {in \pi(n), {subset pi <= rho}} -> pi.-nat n -> rho.-nat n. Proof. rewrite /pnat => subpi /andP[-> pi_n]. by apply/allP=> p pr_p; apply: subpi => //; apply: (allP pi_n). Qed. Lemma eq_in_pnat pi rho n : {in \pi(n), pi =i rho} -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply/idP/idP; apply: sub_in_pnat => p /eqpi->. Qed. Lemma eq_pnat pi rho n : pi =i rho -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply: eq_in_pnat => p _. Qed. Lemma pnatNK pi n : pi^'^'.-nat n = pi.-nat n. Proof. exact: eq_pnat (negnK pi). Qed. Lemma pnatI pi rho n : [predI pi & rho].-nat n = pi.-nat n && rho.-nat n. Proof. by rewrite /pnat andbCA all_predI !andbA andbb. Qed. Lemma pnatM pi m n : pi.-nat (m * n) = pi.-nat m && pi.-nat n. Proof. rewrite /pnat muln_gt0 andbCA -andbA andbCA. case: posnP => // n_gt0; case: posnP => //= m_gt0. apply/allP/andP=> [pi_mn | [pi_m pi_n] p]. by split; apply/allP=> p m_p; apply: pi_mn; rewrite primesM // m_p ?orbT. by rewrite primesM // => /orP[]; [apply: (allP pi_m) | apply: (allP pi_n)]. Qed. Lemma pnatX pi m n : pi.-nat (m ^ n) = pi.-nat m || (n == 0). Proof. by case: n => [|n]; rewrite orbC // /pnat expn_gt0 orbC primesX. Qed. Lemma part_pnat pi n : pi.-nat n`_pi. Proof. rewrite /pnat primes_part part_gt0. by apply/allP=> p; rewrite mem_filter => /andP[]. Qed. Lemma pnatE pi p : prime p -> pi.-nat p = (p \in pi). Proof. by move=> pr_p; rewrite /pnat prime_gt0 ?primes_prime //= andbT. Qed. Lemma pnat_id p : prime p -> p.-nat p. Proof. by move=> pr_p; rewrite pnatE ?inE /=. Qed. Lemma coprime_pi' m n : m > 0 -> n > 0 -> coprime m n = \pi(m)^'.-nat n. Proof. by move=> m_gt0 n_gt0; rewrite /pnat n_gt0 all_predC coprime_has_primes. Qed. Lemma pnat_pi n : n > 0 -> \pi(n).-nat n. Proof. by rewrite /pnat => ->; apply/allP. Qed. Lemma pi_of_dvd m n : m %| n -> n > 0 -> {subset \pi(m) <= \pi(n)}. Proof. move=> m_dv_n n_gt0 p; rewrite !mem_primes n_gt0 => /and3P[-> _ p_dv_m]. exact: dvdn_trans p_dv_m m_dv_n. Qed. Lemma pi_ofM m n : m > 0 -> n > 0 -> \pi(m * n) =i [predU \pi(m) & \pi(n)]. Proof. by move=> m_gt0 n_gt0 p; apply: primesM. Qed. Lemma pi_of_part pi n : n > 0 -> \pi(n`_pi) =i [predI \pi(n) & pi]. Proof. by move=> n_gt0 p; rewrite /pi_of primes_part mem_filter andbC. Qed. Lemma pi_of_exp p n : n > 0 -> \pi(p ^ n) = \pi(p). Proof. by move=> n_gt0; rewrite /pi_of primesX. Qed. Lemma pi_of_prime p : prime p -> \pi(p) =i (p : nat_pred). Proof. by move=> pr_p q; rewrite /pi_of primes_prime // mem_seq1. Qed. Lemma p'natEpi p n : n > 0 -> p^'.-nat n = (p \notin \pi(n)). Proof. by case: n => // n _; rewrite /pnat all_predC has_pred1. Qed. Lemma p'natE p n : prime p -> p^'.-nat n = ~~ (p %| n). Proof. case: n => [|n] p_pr; first by case: p p_pr. by rewrite p'natEpi // mem_primes p_pr. Qed. Lemma pnatPpi pi n p : pi.-nat n -> p \in \pi(n) -> p \in pi. Proof. by case/andP=> _ /allP; apply. Qed. Lemma pnat_dvd m n pi : m %| n -> pi.-nat n -> pi.-nat m. Proof. by case/dvdnP=> q ->; rewrite pnatM; case/andP. Qed. Lemma pnat_div m n pi : m %| n -> pi.-nat n -> pi.-nat (n %/ m). Proof. case/dvdnP=> q ->; rewrite pnatM andbC => /andP[]. by case: m => // m _; rewrite mulnK. Qed. Lemma pnat_coprime pi m n : pi.-nat m -> pi^'.-nat n -> coprime m n. Proof. case/andP=> m_gt0 pi_m /andP[n_gt0 pi'_n]; rewrite coprime_has_primes //. by apply/hasPn=> p /(allP pi'_n); apply/contra/allP. Qed. Lemma p'nat_coprime pi m n : pi^'.-nat m -> pi.-nat n -> coprime m n. Proof. by move=> pi'm pi_n; rewrite (pnat_coprime pi'm) ?pnatNK. Qed. Lemma sub_pnat_coprime pi rho m n : {subset rho <= pi^'} -> pi.-nat m -> rho.-nat n -> coprime m n. Proof. by move=> pi'rho pi_m /(sub_in_pnat (in1W pi'rho)); apply: pnat_coprime. Qed. Lemma coprime_partC pi m n : coprime m`_pi n`_pi^'. Proof. by apply: (@pnat_coprime pi); apply: part_pnat. Qed. Lemma pnat_1 pi n : pi.-nat n -> pi^'.-nat n -> n = 1. Proof. by move=> pi_n pi'_n; rewrite -(eqnP (pnat_coprime pi_n pi'_n)) gcdnn. Qed. Lemma part_pnat_id pi n : pi.-nat n -> n`_pi = n. Proof. case/andP=> n_gt0 pi_n; rewrite -[RHS]partnT // /partn big_mkcond /=. apply: eq_bigr=> p _; have [->|] := posnP (logn p n); first by rewrite if_same. by rewrite logn_gt0 => /(allP pi_n)/= ->. Qed. Lemma part_p'nat pi n : pi^'.-nat n -> n`_pi = 1. Proof. case/andP=> n_gt0 pi'_n; apply: big1_seq => p /andP[pi_p _]. by have [-> //|] := posnP (logn p n); rewrite logn_gt0; case/(allP pi'_n)/negP. Qed. Lemma partn_eq1 pi n : n > 0 -> (n`_pi == 1) = pi^'.-nat n. Proof. move=> n_gt0; apply/eqP/idP=> [pi_n_1|]; last exact: part_p'nat. by rewrite -(partnC pi n_gt0) pi_n_1 mul1n part_pnat. Qed. Lemma pnatP pi n : n > 0 -> reflect (forall p, prime p -> p %| n -> p \in pi) (pi.-nat n). Proof. move=> n_gt0; rewrite /pnat n_gt0. apply: (iffP allP) => /= pi_n p => [pr_p p_n|]. by rewrite pi_n // mem_primes pr_p n_gt0. by rewrite mem_primes n_gt0 /=; case/andP; move: p. Qed. Lemma pi_pnat pi p n : p.-nat n -> p \in pi -> pi.-nat n. Proof. move=> p_n pi_p; have [n_gt0 _] := andP p_n. by apply/pnatP=> // q q_pr /(pnatP _ n_gt0 p_n _ q_pr)/eqnP->. Qed. Lemma p_natP p n : p.-nat n -> {k | n = p ^ k}. Proof. by move=> p_n; exists (logn p n); rewrite -p_part part_pnat_id. Qed. Lemma pi'_p'nat pi p n : pi^'.-nat n -> p \in pi -> p^'.-nat n. Proof. by move=> pi'n pi_p; apply: sub_in_pnat pi'n => q _; apply: contraNneq => ->. Qed. Lemma pi_p'nat p pi n : pi.-nat n -> p \in pi^' -> p^'.-nat n. Proof. by move=> pi_n; apply: pi'_p'nat; rewrite pnatNK. Qed. Lemma partn_part pi rho n : {subset pi <= rho} -> n`_rho`_pi = n`_pi. Proof. move=> pi_sub_rho; have [->|n_gt0] := posnP n; first by rewrite !partn0 partn1. rewrite -[in RHS](partnC rho n_gt0) partnM //. suffices: pi^'.-nat n`_rho^' by move/part_p'nat->; rewrite muln1. by apply: sub_in_pnat (part_pnat _ _) => q _; apply/contra/pi_sub_rho. Qed. Lemma partnI pi rho n : n`_[predI pi & rho] = n`_pi`_rho. Proof. rewrite -(@partnC [predI pi & rho] _`_rho) //. symmetry; rewrite 2?partn_part; try by move=> p /andP []. rewrite mulnC part_p'nat ?mul1n // pnatNK pnatI part_pnat andbT. exact: pnat_dvd (dvdn_part _ _) (part_pnat _ _). Qed. Lemma odd_2'nat n : odd n = 2^'.-nat n. Proof. by case: n => // n; rewrite p'natE // dvdn2 negbK. Qed. End PnatTheory. #[global] Hint Resolve part_gt0 : core. (************************************) (* Properties of the divisors list. *) (************************************) Lemma divisors_correct n : n > 0 -> [/\ uniq (divisors n), sorted leq (divisors n) & forall d, (d \in divisors n) = (d %| n)]. Proof. move/prod_prime_decomp=> def_n; rewrite {4}def_n {def_n}. have: all prime (primes n) by apply/allP=> p; rewrite mem_primes; case/andP. have:= primes_uniq n; rewrite /primes /divisors; move/prime_decomp: n. elim=> [|[p e] pd] /=; first by split=> // d; rewrite big_nil dvdn1 mem_seq1. rewrite big_cons /=; move: (foldr _ _ pd) => divs. move=> IHpd /andP[npd_p Upd] /andP[pr_p pr_pd]. have lt0p: 0 < p by apply: prime_gt0. have {IHpd Upd}[Udivs Odivs mem_divs] := IHpd Upd pr_pd. have ndivs_p m: p * m \notin divs. suffices: p \notin divs; rewrite !mem_divs. by apply: contra => /dvdnP[n ->]; rewrite mulnCA dvdn_mulr. have ndv_p_1: ~~(p %| 1) by rewrite dvdn1 neq_ltn orbC prime_gt1. rewrite big_seq; elim/big_ind: _ => [//|u v npu npv|[q f] /= pd_qf]. by rewrite Euclid_dvdM //; apply/norP. elim: (f) => // f'; rewrite expnS Euclid_dvdM // orbC negb_or => -> {f'}/=. have pd_q: q \in unzip1 pd by apply/mapP; exists (q, f). by apply: contra npd_p; rewrite dvdn_prime2 // ?(allP pr_pd) // => /eqP->. elim: e => [|e] /=; first by split=> // d; rewrite mul1n. have Tmulp_inj: injective (NatTrec.mul p). by move=> u v /eqP; rewrite !natTrecE eqn_pmul2l // => /eqP. move: (iter e _ _) => divs' [Udivs' Odivs' mem_divs']; split=> [||d]. - rewrite merge_uniq cat_uniq map_inj_uniq // Udivs Udivs' andbT /=. apply/hasP=> [[d dv_d /mapP[d' _ def_d]]]. by case/idPn: dv_d; rewrite def_d natTrecE. - rewrite (merge_sorted leq_total) //; case: (divs') Odivs' => //= d ds. rewrite (@map_path _ _ _ _ leq xpred0) ?has_pred0 // => u v _. by rewrite !natTrecE leq_pmul2l. rewrite mem_merge mem_cat; case dv_d_p: (p %| d). case/dvdnP: dv_d_p => d' ->{d}; rewrite mulnC (negbTE (ndivs_p d')) orbF. rewrite expnS -mulnA dvdn_pmul2l // -mem_divs'. by rewrite -(mem_map Tmulp_inj divs') natTrecE. case pdiv_d: (_ \in _). by case/mapP: pdiv_d dv_d_p => d' _ ->; rewrite natTrecE dvdn_mulr. rewrite mem_divs Gauss_dvdr // coprime_sym. by rewrite coprimeXl ?prime_coprime ?dv_d_p. Qed. Lemma sorted_divisors n : sorted leq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma divisors_uniq n : uniq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma sorted_divisors_ltn n : sorted ltn (divisors n). Proof. by rewrite ltn_sorted_uniq_leq divisors_uniq sorted_divisors. Qed. Lemma dvdn_divisors d m : 0 < m -> (d %| m) = (d \in divisors m). Proof. by case/divisors_correct. Qed. Lemma divisor1 n : 1 \in divisors n. Proof. by case: n => // n; rewrite -dvdn_divisors // dvd1n. Qed. Lemma divisors_id n : 0 < n -> n \in divisors n. Proof. by move/dvdn_divisors <-. Qed. (* Big sum / product lemmas*) Lemma dvdn_sum d I r (K : pred I) F : (forall i, K i -> d %| F i) -> d %| \sum_(i <- r | K i) F i. Proof. by move=> dF; elim/big_ind: _ => //; apply: dvdn_add. Qed. Lemma dvdn_partP n m : 0 < n -> reflect (forall p, p \in \pi(n) -> n`_p %| m) (n %| m). Proof. move=> n_gt0; apply: (iffP idP) => n_dvd_m => [p _|]. by apply: dvdn_trans n_dvd_m; apply: dvdn_part. have [-> // | m_gt0] := posnP m. rewrite -(partnT n_gt0) -(partnT m_gt0). rewrite !(@widen_partn (m + n)) ?leq_addl ?leq_addr // /in_mem /=. elim/big_ind2: _ => // [* | q _]; first exact: dvdn_mul. have [-> // | ] := posnP (logn q n); rewrite logn_gt0 => q_n. have pr_q: prime q by move: q_n; rewrite mem_primes; case/andP. by have:= n_dvd_m q q_n; rewrite p_part !pfactor_dvdn // pfactorK. Qed. Lemma modn_partP n a b : 0 < n -> reflect (forall p : nat, p \in \pi(n) -> a = b %[mod n`_p]) (a == b %[mod n]). Proof. move=> n_gt0; wlog le_b_a: a b / b <= a. move=> IH; case: (leqP b a) => [|/ltnW] /IH {IH}// IH. by rewrite eq_sym; apply: (iffP IH) => eqab p /eqab. rewrite eqn_mod_dvd //; apply: (iffP (dvdn_partP _ n_gt0)) => eqab p /eqab; by rewrite -eqn_mod_dvd // => /eqP. Qed. (* The Euler totient function *) Lemma totientE n : n > 0 -> totient n = \prod_(p <- primes n) (p.-1 * p ^ (logn p n).-1). Proof. move=> n_gt0; rewrite /totient n_gt0 prime_decompE unlock. by elim: (primes n) => //= [p pr ->]; rewrite !natTrecE. Qed. Lemma totient_gt0 n : (0 < totient n) = (0 < n). Proof. case: n => // n; rewrite totientE // big_seq_cond prodn_cond_gt0 // => p. by rewrite mem_primes muln_gt0 expn_gt0; case: p => [|[|]]. Qed. Lemma totient_pfactor p e : prime p -> e > 0 -> totient (p ^ e) = p.-1 * p ^ e.-1. Proof. move=> p_pr e_gt0; rewrite totientE ?expn_gt0 ?prime_gt0 //. by rewrite primesX // primes_prime // unlock /= muln1 pfactorK. Qed. Lemma totient_prime p : prime p -> totient p = p.-1. Proof. by move=> p_prime; rewrite -{1}[p]expn1 totient_pfactor // muln1. Qed. Lemma totient_coprime m n : coprime m n -> totient (m * n) = totient m * totient n. Proof. move=> co_mn; have [-> //| m_gt0] := posnP m. have [->|n_gt0] := posnP n; first by rewrite !muln0. rewrite !totientE ?muln_gt0 ?m_gt0 //. have /(perm_big _)->: perm_eq (primes (m * n)) (primes m ++ primes n). apply: uniq_perm => [||p]; first exact: primes_uniq. by rewrite cat_uniq !primes_uniq -coprime_has_primes // co_mn. by rewrite mem_cat primesM. rewrite big_cat /= !big_seq. congr (_ * _); apply: eq_bigr => p; rewrite mem_primes => /and3P[_ _ dvp]. rewrite (mulnC m) logn_Gauss //; move: co_mn. by rewrite -(divnK dvp) coprimeMl => /andP[]. rewrite logn_Gauss //; move: co_mn. by rewrite coprime_sym -(divnK dvp) coprimeMl => /andP[]. Qed. Lemma totient_count_coprime n : totient n = \sum_(0 <= d < n) coprime n d. Proof. elim/ltn_ind: n => // n IHn. case: (leqP n 1) => [|lt1n]; first by rewrite unlock; case: (n) => [|[]]. pose p := pdiv n; have p_pr: prime p by apply: pdiv_prime. have p1 := prime_gt1 p_pr; have p0 := ltnW p1. pose np := n`_p; pose np' := n`_p^'. have co_npp': coprime np np' by rewrite coprime_partC. have [n0 np0 np'0]: [/\ n > 0, np > 0 & np' > 0] by rewrite ltnW ?part_gt0. have def_n: n = np * np' by rewrite partnC. have lnp0: 0 < logn p n by rewrite lognE p_pr n0 pdiv_dvd. pose in_mod k (k0 : k > 0) d := Ordinal (ltn_pmod d k0). rewrite {1}def_n totient_coprime // {IHn}(IHn np') ?big_mkord; last first. by rewrite def_n ltn_Pmull // /np p_part -(expn0 p) ltn_exp2l. have ->: totient np = #|[pred d : 'I_np | coprime np d]|. rewrite [np in LHS]p_part totient_pfactor //=; set q := p ^ _. apply: (@addnI (1 * q)); rewrite -mulnDl [1 + _]prednK // mul1n. have def_np: np = p * q by rewrite -expnS prednK // -p_part. pose mulp := [fun d : 'I_q => in_mod _ np0 (p * d)]. rewrite -def_np -{1}[np]card_ord -(cardC [in codom mulp]). rewrite card_in_image => [|[d1 ltd1] [d2 ltd2] /= _ _ []]; last first. move/eqP; rewrite def_np -!muln_modr ?modn_small //. by rewrite eqn_pmul2l // => eq_op12; apply/eqP. rewrite card_ord; congr (q + _); apply: eq_card => d /=. rewrite !inE [np in coprime np _]p_part coprime_pexpl ?prime_coprime //. congr (~~ _); apply/codomP/idP=> [[d' -> /=] | /dvdnP[r def_d]]. by rewrite def_np -muln_modr // dvdn_mulr. do [rewrite mulnC; case: d => d ltd /=] in def_d *. have ltr: r < q by rewrite -(ltn_pmul2l p0) -def_np -def_d. by exists (Ordinal ltr); apply: val_inj; rewrite /= -def_d modn_small. pose h (d : 'I_n) := (in_mod _ np0 d, in_mod _ np'0 d). pose h' (d : 'I_np * 'I_np') := in_mod _ n0 (chinese np np' d.1 d.2). rewrite -!big_mkcond -sum_nat_const pair_big (reindex_onto h h') => [|[d d'] _]. apply: eq_bigl => [[d ltd] /=]; rewrite !inE -val_eqE /= andbC !coprime_modr. by rewrite def_n -chinese_mod // -coprimeMl -def_n modn_small ?eqxx. apply/eqP; rewrite /eq_op /= /eq_op /= !modn_dvdm ?dvdn_part //. by rewrite chinese_modl // chinese_modr // !modn_small ?eqxx ?ltn_ord. Qed. Lemma totient_gt1 n : (totient n > 1) = (n > 2). Proof. case: n => [|[|[|[|n']]]]//=; set n := n'.+4; rewrite [RHS]isT. wlog [q] : / exists k, k.+3 \in primes n; last first. rewrite mem_primes => /and3P[qp ngt0 qn]. have [[|k]// cqk ->] := pfactor_coprime qp ngt0. rewrite totient_coprime 1?coprime_sym ?coprimeXl//. rewrite totient_pfactor// -?pfactor_dvdn// mulnCA/= (@leq_trans q.+2)//. by rewrite leq_pmulr// muln_gt0 totient_gt0 expn_gt0. have := @prod_prime_decomp n isT; rewrite prime_decompE big_map/=. case: (primes n) (all_prime_primes n) (sorted_primes n) => [|[|[|p']]// [|[|[|[|q']]] r]]//=; first by rewrite big_nil. case: p' => [_ _|p' _ _ _]; last by apply; exists p'; rewrite ?mem_head. rewrite big_seq1; case: logn => [|[|k]]//= ->. by rewrite totient_pfactor//= mul1n (@leq_pexp2l 2 1)//. by move=> _ _ _; apply; exists q'=> //; rewrite !in_cons eqxx orbT. Qed.
action.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun ssrnotations eqtype. From mathcomp Require Import ssrnat div seq prime fintype bigop finset. From mathcomp Require Import fingroup morphism perm automorphism quotient. (******************************************************************************) (* Group action: orbits, stabilisers, transitivity. *) (* is_action D to == the function to : T -> aT -> T defines an action *) (* of D : {set aT} on T. *) (* action D T == structure for a function defining an action of D. *) (* act_dom to == the domain D of to : action D rT. *) (* {action: aT &-> T} == structure for a total action. *) (* := action [set: aT] T *) (* TotalAction to1 toM == the constructor for total actions; to1 and toM *) (* are the proofs of the action identities for 1 and *) (* a * b, respectively. *) (* is_groupAction R to == to is a group action on range R: for all a in D, *) (* the permutation induced by to a is in Aut R. Thus *) (* the action of D must be trivial outside R. *) (* groupAction D R == the structure for group actions of D on R. This *) (* is a telescope on action D rT. *) (* gact_range to == the range R of to : groupAction D R. *) (* GroupAction toAut == constructs a groupAction for action to from *) (* toAut : actm to @* D \subset Aut R (actm to is *) (* the morphism to {perm rT} associated to 'to'). *) (* orbit to A x == the orbit of x under the action of A via to. *) (* orbit_transversal to A S == a transversal of the partition orbit to A @: S *) (* of S, provided A acts on S via to. *) (* amove to A x y == the set of a in A whose action sends x to y. *) (* 'C_A[x | to] == the stabiliser of x : rT in A :&: D. *) (* 'C_A(S | to) == the pointwise stabiliser of S : {set rT} in D :&: A. *) (* 'N_A(S | to) == the global stabiliser of S : {set rT} in D :&: A. *) (* 'Fix_(S | to)[a] == the set of fixpoints of a in S. *) (* 'Fix_(S | to)(A) == the set of fixpoints of A in S. *) (* In the first three _A can be omitted and defaults to the domain D of to; *) (* in the last two S can be omitted and defaults to [set: T], so 'Fix_to[a] *) (* is the set of all fixpoints of a. *) (* The domain restriction ensures that stabilisers have a canonical group *) (* structure, but note that 'Fix sets are generally not groups. Indeed, we *) (* provide alternative definitions when to is a group action on R: *) (* 'C_(G | to)(A) == the centraliser in R :&: G of the group action of *) (* D :&: A via to *) (* 'C_(G | to)[a] == the centraliser in R :&: G of a \in D, via to. *) (* These sets are groups when G is; G can be omitted: 'C(|to)(A) is the *) (* centraliser in R of the action of D :&: A via to. *) (* [acts A, on S | to] == A \subset D acts on the set S via to. *) (* {acts A, on S | to} == A acts on the set S (Prop statement). *) (* {acts A, on group G | to} == [acts A, on S | to] /\ G \subset R, i.e., *) (* A \subset D acts on G \subset R, via *) (* to : groupAction D R. *) (* [transitive A, on S | to] == A acts transitively on S. *) (* [faithful A, on S | to] == A acts faithfully on S. *) (* acts_irreducibly to A G == A acts irreducibly via the groupAction to *) (* on the nontrivial group G, i.e., A does *) (* not act on any nontrivial subgroup of G. *) (* Important caveat: the definitions of orbit, amove, 'Fix_(S | to)(A), *) (* transitive and faithful assume that A is a subset of the domain D. As most *) (* of the permutation actions we consider are total this is usually harmless. *) (* (Note that the theory of partial actions is only partially developed.) *) (* In all of the above, to is expected to be the actual action structure, *) (* not merely the function. There is a special scope %act for actions, and *) (* constructions and notations for many classical actions: *) (* 'P == natural action of a permutation group via aperm. *) (* 'J == internal group action (conjugation) via conjg (_ ^ _). *) (* 'R == regular group action (right translation) via mulg (_ * _). *) (* (However, to limit ambiguity, _ * _ is NOT a canonical action.) *) (* to^* == the action induced by to on {set rT} via to^* (== setact to). *) (* 'Js == the internal action on subsets via _ :^ _, equivalent to 'J^*. *) (* 'Rs == the regular action on subsets via rcoset, equivalent to 'R^*. *) (* 'JG == the conjugation action on {group rT} via (_ :^ _)%G. *) (* to / H == the action induced by to on coset_of H via qact to H, and *) (* restricted to (qact_dom to H) == 'N(rcosets H 'N(H) | to^* ). *) (* 'Q == the action induced to cosets by conjugation; the domain is *) (* qact_dom 'J H, which is provably equal to 'N(H). *) (* to %% A == the action of coset_of A via modact to A, with domain D / A *) (* and support restricted to 'C(D :&: A | to). *) (* to \ sAD == the action of A via ract to sAD == to, if sAD : A \subset D. *) (* [Aut G] == the permutation action restricted to Aut G, via autact G. *) (* <[nRA]> == the action of A on R via actby nRA == to in A and on R, and *) (* the trivial action elsewhere; here nRA : [acts A, on R | to] *) (* or nRA : {acts A, on group R | to}. *) (* to^? == the action induced by to on sT : @subType rT P, via subact to *) (* with domain subact_dom P to == 'N([set x | P x] | to). *) (* <<phi>> == the action of phi : D >-> {perm rT}, via mact phi. *) (* to \o f == the composite action (with domain f @*^-1 D) of the action to *) (* with f : {morphism G >-> aT}, via comp_act to f. Here f must *) (* be the actual morphism object (e.g., coset_morphism H), not *) (* the underlying function (e.g., coset H). *) (* The explicit application of an action to is usually written (to%act x a), *) (* but %act can be omitted if to is an abstract action or a set action to^*. *) (* Note that this form will simplify and expose the acting function. *) (* There is a %gact scope for group actions; the notations above are *) (* recognised in %gact when they denote canonical group actions. *) (* Actions can be used to define morphisms: *) (* actperm to == the morphism D >-> {perm rT} induced by to. *) (* actm to a == if a \in D the function on D induced by the action to, else *) (* the identity function. If to is a group action with range R *) (* then actm to a is canonically a morphism on R. *) (* We also define here the restriction operation on permutations (the domain *) (* of this operations is a stabiliser), and local automorphism groups: *) (* restr_perm S p == if p acts on S, the permutation with support in S that *) (* coincides with p on S; else the identity. Note that *) (* restr_perm is a permutation group morphism that maps *) (* Aut G to Aut S when S is a subgroup of G. *) (* Aut_in A G == the local permutation group 'N_A(G | 'P) / 'C_A(G | 'P) *) (* Usually A is an automorphism group, and then Aut_in A G *) (* is isomorphic to a subgroup of Aut G, specifically *) (* restr_perm @* A. *) (* Finally, gproduct.v will provide a semi-direct group construction that *) (* maps an external group action to an internal one; the theory of morphisms *) (* between such products makes use of the following definition: *) (* morph_act to to' f fA <=> the action of to' on the images of f and fA is *) (* the image of the action of to, i.e., for all x and a we *) (* have f (to x a) = to' (f x) (fA a). Note that there is *) (* no mention of the domains of to and to'; if needed, this *) (* predicate should be restricted via the {in ...} notation *) (* and domain conditions should be added. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope action_scope. Declare Scope groupAction_scope. Import GroupScope. Section ActionDef. Variables (aT : finGroupType) (D : {set aT}) (rT : Type). Implicit Types a b : aT. Implicit Type x : rT. Definition act_morph to x := forall a b, to x (a * b) = to (to x a) b. Definition is_action to := left_injective to /\ forall x, {in D &, act_morph to x}. Record action := Action {act :> rT -> aT -> rT; _ : is_action act}. Definition clone_action to := let: Action _ toP := to return {type of Action for to} -> action in fun k => k toP. End ActionDef. (* Need to close the Section here to avoid re-declaring all Argument Scopes *) Delimit Scope action_scope with act. Bind Scope action_scope with action. Arguments act_morph {aT rT%_type} to x%_g. Arguments is_action {aT} D%_g {rT} to. Arguments act {aT D%_g rT%_type} to%_act x%_g a%_g : rename. Arguments clone_action [aT D%_g rT%_type to%_act] _. Notation "{ 'action' aT &-> T }" := (action [set: aT] T) (format "{ 'action' aT &-> T }") : type_scope. Notation "[ 'action' 'of' to ]" := (clone_action (@Action _ _ _ to)) (format "[ 'action' 'of' to ]") : form_scope. Definition act_dom aT D rT of @action aT D rT := D. Section TotalAction. Variables (aT : finGroupType) (rT : Type) (to : rT -> aT -> rT). Hypotheses (to1 : to^~ 1 =1 id) (toM : forall x, act_morph to x). Lemma is_total_action : is_action setT to. Proof. split=> [a | x a b _ _] /=; last by rewrite toM. by apply: can_inj (to^~ a^-1) _ => x; rewrite -toM ?mulgV. Qed. Definition TotalAction := Action is_total_action. End TotalAction. Section ActionDefs. Variables (aT aT' : finGroupType) (D : {set aT}) (D' : {set aT'}). Definition morph_act rT rT' (to : action D rT) (to' : action D' rT') f fA := forall x a, f (to x a) = to' (f x) (fA a). Variable rT : finType. (* Most definitions require a finType structure on rT *) Implicit Type to : action D rT. Implicit Type A : {set aT}. Implicit Type S : {set rT}. Definition actm to a := if a \in D then to^~ a else id. Definition setact to S a := [set to x a | x in S]. Definition orbit to A x := to x @: A. Definition amove to A x y := [set a in A | to x a == y]. Definition afix to A := [set x | A \subset [set a | to x a == x]]. Definition astab S to := D :&: [set a | S \subset [set x | to x a == x]]. Definition astabs S to := D :&: [set a | S \subset to^~ a @^-1: S]. Definition acts_on A S to := {in A, forall a x, (to x a \in S) = (x \in S)}. Definition atrans A S to := S \in orbit to A @: S. Definition faithful A S to := A :&: astab S to \subset [1]. End ActionDefs. Arguments setact {aT D%_g rT} to%_act S%_g a%_g. Arguments orbit {aT D%_g rT} to%_act A%_g x%_g. Arguments amove {aT D%_g rT} to%_act A%_g x%_g y%_g. Arguments afix {aT D%_g rT} to%_act A%_g. Arguments astab {aT D%_g rT} S%_g to%_act. Arguments astabs {aT D%_g rT} S%_g to%_act. Arguments acts_on {aT D%_g rT} A%_g S%_g to%_act. Arguments atrans {aT D%_g rT} A%_g S%_g to%_act. Arguments faithful {aT D%_g rT} A%_g S%_g to%_act. Notation "to ^*" := (setact to) : function_scope. Prenex Implicits orbit amove. Notation "''Fix_' to ( A )" := (afix to A) (to at level 2, format "''Fix_' to ( A )") : group_scope. (* camlp4 grammar factoring *) Notation "''Fix_' ( to ) ( A )" := 'Fix_to(A) (only parsing) : group_scope. Notation "''Fix_' ( S | to ) ( A )" := (S :&: 'Fix_to(A)) (format "''Fix_' ( S | to ) ( A )") : group_scope. Notation "''Fix_' to [ a ]" := ('Fix_to([set a])) (to at level 2, format "''Fix_' to [ a ]") : group_scope. Notation "''Fix_' ( S | to ) [ a ]" := (S :&: 'Fix_to[a]) (format "''Fix_' ( S | to ) [ a ]") : group_scope. Notation "''C' ( S | to )" := (astab S to) : group_scope. Notation "''C_' A ( S | to )" := (A :&: 'C(S | to)) : group_scope. Notation "''C_' ( A ) ( S | to )" := 'C_A(S | to) (only parsing) : group_scope. Notation "''C' [ x | to ]" := ('C([set x] | to)) : group_scope. Notation "''C_' A [ x | to ]" := (A :&: 'C[x | to]) : group_scope. Notation "''C_' ( A ) [ x | to ]" := 'C_A[x | to] (only parsing) : group_scope. Notation "''N' ( S | to )" := (astabs S to) (format "''N' ( S | to )") : group_scope. Notation "''N_' A ( S | to )" := (A :&: 'N(S | to)) (A at level 2, format "''N_' A ( S | to )") : group_scope. Notation "[ 'acts' A , 'on' S | to ]" := (A \subset pred_of_set 'N(S | to)) (format "[ 'acts' A , 'on' S | to ]") : form_scope. Notation "{ 'acts' A , 'on' S | to }" := (acts_on A S to) (format "{ 'acts' A , 'on' S | to }") : type_scope. Notation "[ 'transitive' A , 'on' S | to ]" := (atrans A S to) (format "[ 'transitive' A , 'on' S | to ]") : form_scope. Notation "[ 'faithful' A , 'on' S | to ]" := (faithful A S to) (format "[ 'faithful' A , 'on' S | to ]") : form_scope. Section RawAction. (* Lemmas that do not require the group structure on the action domain. *) (* Some lemmas like actMin would be actually be valid for arbitrary rT, *) (* e.g., for actions on a function type, but would be difficult to use *) (* as a view due to the confusion between parameters and assumptions. *) Variables (aT : finGroupType) (D : {set aT}) (rT : finType) (to : action D rT). Implicit Types (a : aT) (x y : rT) (A B : {set aT}) (S T : {set rT}). Lemma act_inj : left_injective to. Proof. by case: to => ? []. Qed. Arguments act_inj : clear implicits. Lemma actMin x : {in D &, act_morph to x}. Proof. by case: to => ? []. Qed. Lemma actmEfun a : a \in D -> actm to a = to^~ a. Proof. by rewrite /actm => ->. Qed. Lemma actmE a : a \in D -> actm to a =1 to^~ a. Proof. by move=> Da; rewrite actmEfun. Qed. Lemma setactE S a : to^* S a = [set to x a | x in S]. Proof. by []. Qed. Lemma mem_setact S a x : x \in S -> to x a \in to^* S a. Proof. exact: imset_f. Qed. Lemma card_setact S a : #|to^* S a| = #|S|. Proof. by apply: card_imset; apply: act_inj. Qed. Lemma setact_is_action : is_action D to^*. Proof. split=> [a R S eqRS | a b Da Db S]; last first. by rewrite /setact /= -imset_comp; apply: eq_imset => x; apply: actMin. apply/setP=> x; apply/idP/idP=> /(mem_setact a). by rewrite eqRS => /imsetP[y Sy /act_inj->]. by rewrite -eqRS => /imsetP[y Sy /act_inj->]. Qed. Canonical set_action := Action setact_is_action. Lemma orbitE A x : orbit to A x = to x @: A. Proof. by []. Qed. Lemma orbitP A x y : reflect (exists2 a, a \in A & to x a = y) (y \in orbit to A x). Proof. by apply: (iffP imsetP) => [] [a]; exists a. Qed. Lemma mem_orbit A x a : a \in A -> to x a \in orbit to A x. Proof. exact: imset_f. Qed. Lemma afixP A x : reflect (forall a, a \in A -> to x a = x) (x \in 'Fix_to(A)). Proof. rewrite inE; apply: (iffP subsetP) => [xfix a /xfix | xfix a Aa]. by rewrite inE => /eqP. by rewrite inE xfix. Qed. Lemma afixS A B : A \subset B -> 'Fix_to(B) \subset 'Fix_to(A). Proof. by move=> sAB; apply/subsetP=> u /[!inE]; apply: subset_trans. Qed. Lemma afixU A B : 'Fix_to(A :|: B) = 'Fix_to(A) :&: 'Fix_to(B). Proof. by apply/setP=> x; rewrite !inE subUset. Qed. Lemma afix1P a x : reflect (to x a = x) (x \in 'Fix_to[a]). Proof. by rewrite inE sub1set inE; apply: eqP. Qed. Lemma astabIdom S : 'C_D(S | to) = 'C(S | to). Proof. by rewrite setIA setIid. Qed. Lemma astab_dom S : {subset 'C(S | to) <= D}. Proof. by move=> a /setIP[]. Qed. Lemma astab_act S a x : a \in 'C(S | to) -> x \in S -> to x a = x. Proof. rewrite 2!inE => /andP[_ cSa] Sx; apply/eqP. by have /[1!inE] := subsetP cSa x Sx. Qed. Lemma astabS S1 S2 : S1 \subset S2 -> 'C(S2 | to) \subset 'C(S1 | to). Proof. by move=> sS12; apply/subsetP=> x /[!inE] /andP[->]; apply: subset_trans. Qed. Lemma astabsIdom S : 'N_D(S | to) = 'N(S | to). Proof. by rewrite setIA setIid. Qed. Lemma astabs_dom S : {subset 'N(S | to) <= D}. Proof. by move=> a /setIdP[]. Qed. Lemma astabs_act S a x : a \in 'N(S | to) -> (to x a \in S) = (x \in S). Proof. rewrite 2!inE subEproper properEcard => /andP[_]. rewrite (card_preimset _ (act_inj _)) ltnn andbF orbF => /eqP{2}->. by rewrite inE. Qed. Lemma astab_sub S : 'C(S | to) \subset 'N(S | to). Proof. apply/subsetP=> a cSa; rewrite !inE (astab_dom cSa). by apply/subsetP=> x Sx; rewrite inE (astab_act cSa). Qed. Lemma astabsC S : 'N(~: S | to) = 'N(S | to). Proof. apply/setP=> a; apply/idP/idP=> nSa; rewrite !inE (astabs_dom nSa). by rewrite -setCS -preimsetC; apply/subsetP=> x; rewrite inE astabs_act. by rewrite preimsetC setCS; apply/subsetP=> x; rewrite inE astabs_act. Qed. Lemma astabsI S T : 'N(S | to) :&: 'N(T | to) \subset 'N(S :&: T | to). Proof. apply/subsetP=> a; rewrite !inE -!andbA preimsetI => /and4P[-> nSa _ nTa] /=. by rewrite setISS. Qed. Lemma astabs_setact S a : a \in 'N(S | to) -> to^* S a = S. Proof. move=> nSa; apply/eqP; rewrite eqEcard card_setact leqnn andbT. by apply/subsetP=> _ /imsetP[x Sx ->]; rewrite astabs_act. Qed. Lemma astab1_set S : 'C[S | set_action] = 'N(S | to). Proof. apply/setP=> a; apply/idP/idP=> nSa. case/setIdP: nSa => Da; rewrite !inE Da sub1set inE => /eqP defS. by apply/subsetP=> x Sx; rewrite inE -defS mem_setact. by rewrite !inE (astabs_dom nSa) sub1set inE /= astabs_setact. Qed. Lemma astabs_set1 x : 'N([set x] | to) = 'C[x | to]. Proof. apply/eqP; rewrite eqEsubset astab_sub andbC setIS //. by apply/subsetP=> a; rewrite ?(inE,sub1set). Qed. Lemma acts_dom A S : [acts A, on S | to] -> A \subset D. Proof. by move=> nSA; rewrite (subset_trans nSA) ?subsetIl. Qed. Lemma acts_act A S : [acts A, on S | to] -> {acts A, on S | to}. Proof. by move=> nAS a Aa x; rewrite astabs_act ?(subsetP nAS). Qed. Lemma astabCin A S : A \subset D -> (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)). Proof. move=> sAD; apply/subsetP/subsetP=> [sAC x xS | sSF a aA]. by apply/afixP=> a aA; apply: astab_act (sAC _ aA) xS. rewrite !inE (subsetP sAD _ aA); apply/subsetP=> x xS. by move/afixP/(_ _ aA): (sSF _ xS) => /[1!inE] ->. Qed. Section ActsSetop. Variables (A : {set aT}) (S T : {set rT}). Hypotheses (AactS : [acts A, on S | to]) (AactT : [acts A, on T | to]). Lemma astabU : 'C(S :|: T | to) = 'C(S | to) :&: 'C(T | to). Proof. by apply/setP=> a; rewrite !inE subUset; case: (a \in D). Qed. Lemma astabsU : 'N(S | to) :&: 'N(T | to) \subset 'N(S :|: T | to). Proof. by rewrite -(astabsC S) -(astabsC T) -(astabsC (S :|: T)) setCU astabsI. Qed. Lemma astabsD : 'N(S | to) :&: 'N(T | to) \subset 'N(S :\: T| to). Proof. by rewrite setDE -(astabsC T) astabsI. Qed. Lemma actsI : [acts A, on S :&: T | to]. Proof. by apply: subset_trans (astabsI S T); rewrite subsetI AactS. Qed. Lemma actsU : [acts A, on S :|: T | to]. Proof. by apply: subset_trans astabsU; rewrite subsetI AactS. Qed. Lemma actsD : [acts A, on S :\: T | to]. Proof. by apply: subset_trans astabsD; rewrite subsetI AactS. Qed. End ActsSetop. Lemma acts_in_orbit A S x y : [acts A, on S | to] -> y \in orbit to A x -> x \in S -> y \in S. Proof. by move=> nSA/imsetP[a Aa ->{y}] Sx; rewrite (astabs_act _ (subsetP nSA a Aa)). Qed. Lemma subset_faithful A B S : B \subset A -> [faithful A, on S | to] -> [faithful B, on S | to]. Proof. by move=> sAB; apply: subset_trans; apply: setSI. Qed. Section Reindex. Variables (vT : Type) (idx : vT) (op : Monoid.com_law idx) (S : {set rT}). Lemma reindex_astabs a F : a \in 'N(S | to) -> \big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a). Proof. move=> nSa; rewrite (reindex_inj (act_inj a)); apply: eq_bigl => x. exact: astabs_act. Qed. Lemma reindex_acts A a F : [acts A, on S | to] -> a \in A -> \big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a). Proof. by move=> nSA /(subsetP nSA); apply: reindex_astabs. Qed. End Reindex. End RawAction. Arguments act_inj {aT D rT} to a [x1 x2] : rename. Notation "to ^*" := (set_action to) : action_scope. Arguments orbitP {aT D rT to A x y}. Arguments afixP {aT D rT to A x}. Arguments afix1P {aT D rT to a x}. Arguments reindex_astabs [aT D rT] to [vT idx op S] a [F]. Arguments reindex_acts [aT D rT] to [vT idx op S A a F]. Section PartialAction. (* Lemmas that require a (partial) group domain. *) Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Implicit Types a : aT. Implicit Types x y : rT. Implicit Types A B : {set aT}. Implicit Types G H : {group aT}. Implicit Types S : {set rT}. Lemma act1 x : to x 1 = x. Proof. by apply: (act_inj to 1); rewrite -actMin ?mulg1. Qed. Lemma actKin : {in D, right_loop invg to}. Proof. by move=> a Da /= x; rewrite -actMin ?groupV // mulgV act1. Qed. Lemma actKVin : {in D, rev_right_loop invg to}. Proof. by move=> a Da /= x; rewrite -{2}(invgK a) actKin ?groupV. Qed. Lemma setactVin S a : a \in D -> to^* S a^-1 = to^~ a @^-1: S. Proof. by move=> Da; apply: can2_imset_pre; [apply: actKVin | apply: actKin]. Qed. Lemma actXin x a i : a \in D -> to x (a ^+ i) = iter i (to^~ a) x. Proof. move=> Da; elim: i => /= [|i <-]; first by rewrite act1. by rewrite expgSr actMin ?groupX. Qed. Lemma afix1 : 'Fix_to(1) = setT. Proof. by apply/setP=> x; rewrite !inE sub1set inE act1 eqxx. Qed. Lemma afixD1 G : 'Fix_to(G^#) = 'Fix_to(G). Proof. by rewrite -{2}(setD1K (group1 G)) afixU afix1 setTI. Qed. Lemma orbit_refl G x : x \in orbit to G x. Proof. by rewrite -{1}[x]act1 mem_orbit. Qed. Local Notation orbit_rel A := (fun x y => x \in orbit to A y). Lemma contra_orbit G x y : x \notin orbit to G y -> x != y. Proof. by apply: contraNneq => ->; apply: orbit_refl. Qed. Lemma orbit_in_sym G : G \subset D -> symmetric (orbit_rel G). Proof. move=> sGD; apply: symmetric_from_pre => x y /imsetP[a Ga]. by move/(canLR (actKin (subsetP sGD a Ga))) <-; rewrite mem_orbit ?groupV. Qed. Lemma orbit_in_trans G : G \subset D -> transitive (orbit_rel G). Proof. move=> sGD _ _ z /imsetP[a Ga ->] /imsetP[b Gb ->]. by rewrite -actMin ?mem_orbit ?groupM // (subsetP sGD). Qed. Lemma orbit_in_eqP G x y : G \subset D -> reflect (orbit to G x = orbit to G y) (x \in orbit to G y). Proof. move=> sGD; apply: (iffP idP) => [yGx|<-]; last exact: orbit_refl. by apply/setP=> z; apply/idP/idP=> /orbit_in_trans-> //; rewrite orbit_in_sym. Qed. Lemma orbit_in_transl G x y z : G \subset D -> y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z). Proof. by move=> sGD Gxy; rewrite !(orbit_in_sym sGD _ z) (orbit_in_eqP y x sGD Gxy). Qed. Lemma orbit_act_in x a G : G \subset D -> a \in G -> orbit to G (to x a) = orbit to G x. Proof. by move=> sGD /mem_orbit/orbit_in_eqP->. Qed. Lemma orbit_actr_in x a G y : G \subset D -> a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x). Proof. by move=> sGD /mem_orbit/orbit_in_transl->. Qed. Lemma orbit_inv_in A x y : A \subset D -> (y \in orbit to A^-1 x) = (x \in orbit to A y). Proof. move/subsetP=> sAD; apply/imsetP/imsetP=> [] [a Aa ->]. by exists a^-1; rewrite -?mem_invg ?actKin // -groupV sAD -?mem_invg. by exists a^-1; rewrite ?memV_invg ?actKin // sAD. Qed. Lemma orbit_lcoset_in A a x : A \subset D -> a \in D -> orbit to (a *: A) x = orbit to A (to x a). Proof. move/subsetP=> sAD Da; apply/setP=> y; apply/imsetP/imsetP=> [] [b Ab ->{y}]. by exists (a^-1 * b); rewrite -?actMin ?mulKVg // ?sAD -?mem_lcoset. by exists (a * b); rewrite ?mem_mulg ?set11 ?actMin // sAD. Qed. Lemma orbit_rcoset_in A a x y : A \subset D -> a \in D -> (to y a \in orbit to (A :* a) x) = (y \in orbit to A x). Proof. move=> sAD Da; rewrite -orbit_inv_in ?mul_subG ?sub1set // invMg. by rewrite invg_set1 orbit_lcoset_in ?inv_subG ?groupV ?actKin ?orbit_inv_in. Qed. Lemma orbit_conjsg_in A a x y : A \subset D -> a \in D -> (to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x). Proof. move=> sAD Da; rewrite conjsgE. by rewrite orbit_lcoset_in ?groupV ?mul_subG ?sub1set ?actKin ?orbit_rcoset_in. Qed. Lemma orbit1P G x : reflect (orbit to G x = [set x]) (x \in 'Fix_to(G)). Proof. apply: (iffP afixP) => [xfix | xfix a Ga]. apply/eqP; rewrite eq_sym eqEsubset sub1set -{1}[x]act1 imset_f //=. by apply/subsetP=> y; case/imsetP=> a Ga ->; rewrite inE xfix. by apply/set1P; rewrite -xfix imset_f. Qed. Lemma card_orbit1 G x : #|orbit to G x| = 1%N -> orbit to G x = [set x]. Proof. move=> orb1; apply/eqP; rewrite eq_sym eqEcard {}orb1 cards1. by rewrite sub1set orbit_refl. Qed. Lemma orbit_partition G S : [acts G, on S | to] -> partition (orbit to G @: S) S. Proof. move=> actsGS; have sGD := acts_dom actsGS. have eqiG: {in S & &, equivalence_rel [rel x y | y \in orbit to G x]}. by move=> x y z * /=; rewrite orbit_refl; split=> // /orbit_in_eqP->. congr (partition _ _): (equivalence_partitionP eqiG). apply: eq_in_imset => x Sx; apply/setP=> y. by rewrite inE /= andb_idl // => /acts_in_orbit->. Qed. Definition orbit_transversal A S := transversal (orbit to A @: S) S. Lemma orbit_transversalP G S (P := orbit to G @: S) (X := orbit_transversal G S) : [acts G, on S | to] -> [/\ is_transversal X P S, X \subset S, {in X &, forall x y, (y \in orbit to G x) = (x == y)} & forall x, x \in S -> exists2 a, a \in G & to x a \in X]. Proof. move/orbit_partition; rewrite -/P => partP. have [/eqP defS tiP _] := and3P partP. have trXP: is_transversal X P S := transversalP partP. have sXS: X \subset S := transversal_sub trXP. split=> // [x y Xx Xy /= | x Sx]. have Sx := subsetP sXS x Xx. rewrite -(inj_in_eq (pblock_inj trXP)) // eq_pblock ?defS //. by rewrite (def_pblock tiP (imset_f _ Sx)) ?orbit_refl. have /imsetP[y Xy defxG]: orbit to G x \in pblock P @: X. by rewrite (pblock_transversal trXP) ?imset_f. suffices /orbitP[a Ga def_y]: y \in orbit to G x by exists a; rewrite ?def_y. by rewrite defxG mem_pblock defS (subsetP sXS). Qed. Lemma group_set_astab S : group_set 'C(S | to). Proof. apply/group_setP; split=> [|a b cSa cSb]. by rewrite !inE group1; apply/subsetP=> x _; rewrite inE act1. rewrite !inE groupM ?(@astab_dom _ _ _ to S) //; apply/subsetP=> x Sx. by rewrite inE actMin ?(@astab_dom _ _ _ to S) ?(astab_act _ Sx). Qed. Canonical astab_group S := group (group_set_astab S). Lemma afix_gen_in A : A \subset D -> 'Fix_to(<<A>>) = 'Fix_to(A). Proof. move=> sAD; apply/eqP; rewrite eqEsubset afixS ?sub_gen //=. by rewrite -astabCin gen_subG ?astabCin. Qed. Lemma afix_cycle_in a : a \in D -> 'Fix_to(<[a]>) = 'Fix_to[a]. Proof. by move=> Da; rewrite afix_gen_in ?sub1set. Qed. Lemma afixYin A B : A \subset D -> B \subset D -> 'Fix_to(A <*> B) = 'Fix_to(A) :&: 'Fix_to(B). Proof. by move=> sAD sBD; rewrite afix_gen_in ?afixU // subUset sAD. Qed. Lemma afixMin G H : G \subset D -> H \subset D -> 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H). Proof. by move=> sGD sHD; rewrite -afix_gen_in ?mul_subG // genM_join afixYin. Qed. Lemma sub_astab1_in A x : A \subset D -> (A \subset 'C[x | to]) = (x \in 'Fix_to(A)). Proof. by move=> sAD; rewrite astabCin ?sub1set. Qed. Lemma group_set_astabs S : group_set 'N(S | to). Proof. apply/group_setP; split=> [|a b cSa cSb]. by rewrite !inE group1; apply/subsetP=> x Sx; rewrite inE act1. rewrite !inE groupM ?(@astabs_dom _ _ _ to S) //; apply/subsetP=> x Sx. by rewrite inE actMin ?(@astabs_dom _ _ _ to S) ?astabs_act. Qed. Canonical astabs_group S := group (group_set_astabs S). Lemma astab_norm S : 'N(S | to) \subset 'N('C(S | to)). Proof. apply/subsetP=> a nSa; rewrite inE sub_conjg; apply/subsetP=> b cSb. have [Da Db] := (astabs_dom nSa, astab_dom cSb). rewrite mem_conjgV !inE groupJ //; apply/subsetP=> x Sx. rewrite inE !actMin ?groupM ?groupV //. by rewrite (astab_act cSb) ?actKVin ?astabs_act ?groupV. Qed. Lemma astab_normal S : 'C(S | to) <| 'N(S | to). Proof. by rewrite /normal astab_sub astab_norm. Qed. Lemma acts_sub_orbit G S x : [acts G, on S | to] -> (orbit to G x \subset S) = (x \in S). Proof. move/acts_act=> GactS. apply/subsetP/idP=> [| Sx y]; first by apply; apply: orbit_refl. by case/orbitP=> a Ga <-{y}; rewrite GactS. Qed. Lemma acts_orbit G x : G \subset D -> [acts G, on orbit to G x | to]. Proof. move/subsetP=> sGD; apply/subsetP=> a Ga; rewrite !inE sGD //. apply/subsetP=> _ /imsetP[b Gb ->]. by rewrite inE -actMin ?sGD // imset_f ?groupM. Qed. Lemma acts_subnorm_fix A : [acts 'N_D(A), on 'Fix_to(D :&: A) | to]. Proof. apply/subsetP=> a nAa; have [Da _] := setIP nAa; rewrite !inE Da. apply/subsetP=> x Cx /[1!inE]; apply/afixP=> b DAb. have [Db _]:= setIP DAb; rewrite -actMin // conjgCV actMin ?groupJ ?groupV //. by rewrite /= (afixP Cx) // memJ_norm // groupV (subsetP (normsGI _ _) _ nAa). Qed. Lemma atrans_orbit G x : [transitive G, on orbit to G x | to]. Proof. by apply: imset_f; apply: orbit_refl. Qed. Section OrbitStabilizer. Variables (G : {group aT}) (x : rT). Hypothesis sGD : G \subset D. Let ssGD := subsetP sGD. Lemma amove_act a : a \in G -> amove to G x (to x a) = 'C_G[x | to] :* a. Proof. move=> Ga; apply/setP=> b; have Da := ssGD Ga. rewrite mem_rcoset !(inE, sub1set) !groupMr ?groupV //. by case Gb: (b \in G); rewrite //= actMin ?groupV ?ssGD ?(canF_eq (actKVin Da)). Qed. Lemma amove_orbit : amove to G x @: orbit to G x = rcosets 'C_G[x | to] G. Proof. apply/setP => Ha; apply/imsetP/rcosetsP=> [[y] | [a Ga ->]]. by case/imsetP=> b Gb -> ->{Ha y}; exists b => //; rewrite amove_act. by rewrite -amove_act //; exists (to x a); first apply: mem_orbit. Qed. Lemma amoveK : {in orbit to G x, cancel (amove to G x) (fun Ca => to x (repr Ca))}. Proof. move=> _ /orbitP[a Ga <-]; rewrite amove_act //= -[G :&: _]/(gval _). case: repr_rcosetP => b; rewrite !(inE, sub1set)=> /and3P[Gb _ xbx]. by rewrite actMin ?ssGD ?(eqP xbx). Qed. Lemma orbit_stabilizer : orbit to G x = [set to x (repr Ca) | Ca in rcosets 'C_G[x | to] G]. Proof. rewrite -amove_orbit -imset_comp /=; apply/setP=> z. by apply/idP/imsetP=> [xGz | [y xGy ->]]; first exists z; rewrite /= ?amoveK. Qed. Lemma act_reprK : {in rcosets 'C_G[x | to] G, cancel (to x \o repr) (amove to G x)}. Proof. move=> _ /rcosetsP[a Ga ->] /=; rewrite amove_act ?rcoset_repr //. rewrite -[G :&: _]/(gval _); case: repr_rcosetP => b /setIP[Gb _]. exact: groupM. Qed. End OrbitStabilizer. Lemma card_orbit_in G x : G \subset D -> #|orbit to G x| = #|G : 'C_G[x | to]|. Proof. move=> sGD; rewrite orbit_stabilizer 1?card_in_imset //. exact: can_in_inj (act_reprK _). Qed. Lemma card_orbit_in_stab G x : G \subset D -> (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|. Proof. by move=> sGD; rewrite mulnC card_orbit_in ?Lagrange ?subsetIl. Qed. Lemma acts_sum_card_orbit G S : [acts G, on S | to] -> \sum_(T in orbit to G @: S) #|T| = #|S|. Proof. by move/orbit_partition/card_partition. Qed. Lemma astab_setact_in S a : a \in D -> 'C(to^* S a | to) = 'C(S | to) :^ a. Proof. move=> Da; apply/setP=> b; rewrite mem_conjg !inE -mem_conjg conjGid //. apply: andb_id2l => Db; rewrite sub_imset_pre; apply: eq_subset_r => x. by rewrite !inE !actMin ?groupM ?groupV // invgK (canF_eq (actKVin Da)). Qed. Lemma astab1_act_in x a : a \in D -> 'C[to x a | to] = 'C[x | to] :^ a. Proof. by move=> Da; rewrite -astab_setact_in // /setact imset_set1. Qed. Theorem Frobenius_Cauchy G S : [acts G, on S | to] -> \sum_(a in G) #|'Fix_(S | to)[a]| = (#|orbit to G @: S| * #|G|)%N. Proof. move=> GactS; have sGD := acts_dom GactS. transitivity (\sum_(a in G) \sum_(x in 'Fix_(S | to)[a]) 1%N). by apply: eq_bigr => a _; rewrite -sum1_card. rewrite (exchange_big_dep [in S]) /= => [|a x _]; last by case/setIP. rewrite (set_partition_big _ (orbit_partition GactS)) -sum_nat_const /=. apply: eq_bigr => _ /imsetP[x Sx ->]. rewrite -(card_orbit_in_stab x sGD) -sum_nat_const. apply: eq_bigr => y; rewrite orbit_in_sym // => /imsetP[a Ga defx]. rewrite defx astab1_act_in ?(subsetP sGD) //. rewrite -{2}(conjGid Ga) -conjIg cardJg -sum1_card setIA (setIidPl sGD). by apply: eq_bigl => b; rewrite !(sub1set, inE) -(acts_act GactS Ga) -defx Sx. Qed. Lemma atrans_dvd_index_in G S : G \subset D -> [transitive G, on S | to] -> #|S| %| #|G : 'C_G(S | to)|. Proof. move=> sGD /imsetP[x Sx {1}->]; rewrite card_orbit_in //. by rewrite indexgS // setIS // astabS // sub1set. Qed. Lemma atrans_dvd_in G S : G \subset D -> [transitive G, on S | to] -> #|S| %| #|G|. Proof. move=> sGD transG; apply: dvdn_trans (atrans_dvd_index_in sGD transG) _. exact: dvdn_indexg. Qed. Lemma atransPin G S : G \subset D -> [transitive G, on S | to] -> forall x, x \in S -> orbit to G x = S. Proof. by move=> sGD /imsetP[y _ ->] x; apply/orbit_in_eqP. Qed. Lemma atransP2in G S : G \subset D -> [transitive G, on S | to] -> {in S &, forall x y, exists2 a, a \in G & y = to x a}. Proof. by move=> sGD transG x y /(atransPin sGD transG) <- /imsetP. Qed. Lemma atrans_acts_in G S : G \subset D -> [transitive G, on S | to] -> [acts G, on S | to]. Proof. move=> sGD transG; apply/subsetP=> a Ga; rewrite !inE (subsetP sGD) //. by apply/subsetP=> x /(atransPin sGD transG) <-; rewrite inE imset_f. Qed. Lemma subgroup_transitivePin G H S x : x \in S -> H \subset G -> G \subset D -> [transitive G, on S | to] -> reflect ('C_G[x | to] * H = G) [transitive H, on S | to]. Proof. move=> Sx sHG sGD trG; have sHD := subset_trans sHG sGD. apply: (iffP idP) => [trH | defG]. rewrite group_modr //; apply/setIidPl/subsetP=> a Ga. have Sxa: to x a \in S by rewrite (acts_act (atrans_acts_in sGD trG)). have [b Hb xab]:= atransP2in sHD trH Sxa Sx. have Da := subsetP sGD a Ga; have Db := subsetP sHD b Hb. rewrite -(mulgK b a) mem_mulg ?groupV // !inE groupM //= sub1set inE. by rewrite actMin -?xab. apply/imsetP; exists x => //; apply/setP=> y; rewrite -(atransPin sGD trG Sx). apply/imsetP/imsetP=> [] [a]; last by exists a; first apply: (subsetP sHG). rewrite -defG => /imset2P[c b /setIP[_ cxc] Hb ->] ->. exists b; rewrite ?actMin ?(astab_dom cxc) ?(subsetP sHD) //. by rewrite (astab_act cxc) ?inE. Qed. End PartialAction. Arguments orbit_transversal {aT D%_g rT} to%_act A%_g S%_g. Arguments orbit_in_eqP {aT D rT to G x y}. Arguments orbit1P {aT D rT to G x}. Arguments contra_orbit [aT D rT] to G [x y]. Notation "''C' ( S | to )" := (astab_group to S) : Group_scope. Notation "''C_' A ( S | to )" := (setI_group A 'C(S | to)) : Group_scope. Notation "''C_' ( A ) ( S | to )" := (setI_group A 'C(S | to)) (only parsing) : Group_scope. Notation "''C' [ x | to ]" := (astab_group to [set x%g]) : Group_scope. Notation "''C_' A [ x | to ]" := (setI_group A 'C[x | to]) : Group_scope. Notation "''C_' ( A ) [ x | to ]" := (setI_group A 'C[x | to]) (only parsing) : Group_scope. Notation "''N' ( S | to )" := (astabs_group to S) : Group_scope. Notation "''N_' A ( S | to )" := (setI_group A 'N(S | to)) : Group_scope. Section TotalActions. (* These lemmas are only established for total actions (domain = [set: rT]) *) Variable (aT : finGroupType) (rT : finType). Variable to : {action aT &-> rT}. Implicit Types (a b : aT) (x y z : rT) (A B : {set aT}) (G H : {group aT}). Implicit Type S : {set rT}. Lemma actM x a b : to x (a * b) = to (to x a) b. Proof. by rewrite actMin ?inE. Qed. Lemma actK : right_loop invg to. Proof. by move=> a; apply: actKin; rewrite inE. Qed. Lemma actKV : rev_right_loop invg to. Proof. by move=> a; apply: actKVin; rewrite inE. Qed. Lemma actX x a n : to x (a ^+ n) = iter n (to^~ a) x. Proof. by elim: n => [|n /= <-]; rewrite ?act1 // -actM expgSr. Qed. Lemma actCJ a b x : to (to x a) b = to (to x b) (a ^ b). Proof. by rewrite !actM actK. Qed. Lemma actCJV a b x : to (to x a) b = to (to x (b ^ a^-1)) a. Proof. by rewrite (actCJ _ a) conjgKV. Qed. Lemma orbit_sym G x y : (x \in orbit to G y) = (y \in orbit to G x). Proof. exact/orbit_in_sym/subsetT. Qed. Lemma orbit_trans G x y z : x \in orbit to G y -> y \in orbit to G z -> x \in orbit to G z. Proof. exact/orbit_in_trans/subsetT. Qed. Lemma orbit_eqP G x y : reflect (orbit to G x = orbit to G y) (x \in orbit to G y). Proof. exact/orbit_in_eqP/subsetT. Qed. Lemma orbit_transl G x y z : y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z). Proof. exact/orbit_in_transl/subsetT. Qed. Lemma orbit_act G a x: a \in G -> orbit to G (to x a) = orbit to G x. Proof. exact/orbit_act_in/subsetT. Qed. Lemma orbit_actr G a x y : a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x). Proof. by move/mem_orbit/orbit_transl; apply. Qed. Lemma orbit_eq_mem G x y : (orbit to G x == orbit to G y) = (x \in orbit to G y). Proof. exact: sameP eqP (orbit_eqP G x y). Qed. Lemma orbit_inv A x y : (y \in orbit to A^-1 x) = (x \in orbit to A y). Proof. by rewrite orbit_inv_in ?subsetT. Qed. Lemma orbit_lcoset A a x : orbit to (a *: A) x = orbit to A (to x a). Proof. by rewrite orbit_lcoset_in ?subsetT ?inE. Qed. Lemma orbit_rcoset A a x y : (to y a \in orbit to (A :* a) x) = (y \in orbit to A x). Proof. by rewrite orbit_rcoset_in ?subsetT ?inE. Qed. Lemma orbit_conjsg A a x y : (to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x). Proof. by rewrite orbit_conjsg_in ?subsetT ?inE. Qed. Lemma astabP S a : reflect (forall x, x \in S -> to x a = x) (a \in 'C(S | to)). Proof. apply: (iffP idP) => [cSa x|cSa]; first exact: astab_act. by rewrite !inE; apply/subsetP=> x Sx; rewrite inE cSa. Qed. Lemma astab1P x a : reflect (to x a = x) (a \in 'C[x | to]). Proof. by rewrite !inE sub1set inE; apply: eqP. Qed. Lemma sub_astab1 A x : (A \subset 'C[x | to]) = (x \in 'Fix_to(A)). Proof. by rewrite sub_astab1_in ?subsetT. Qed. Lemma astabC A S : (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)). Proof. by rewrite astabCin ?subsetT. Qed. Lemma afix_cycle a : 'Fix_to(<[a]>) = 'Fix_to[a]. Proof. by rewrite afix_cycle_in ?inE. Qed. Lemma afix_gen A : 'Fix_to(<<A>>) = 'Fix_to(A). Proof. by rewrite afix_gen_in ?subsetT. Qed. Lemma afixM G H : 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H). Proof. by rewrite afixMin ?subsetT. Qed. Lemma astabsP S a : reflect (forall x, (to x a \in S) = (x \in S)) (a \in 'N(S | to)). Proof. apply: (iffP idP) => [nSa x|nSa]; first exact: astabs_act. by rewrite !inE; apply/subsetP=> x; rewrite inE nSa. Qed. Lemma card_orbit G x : #|orbit to G x| = #|G : 'C_G[x | to]|. Proof. by rewrite card_orbit_in ?subsetT. Qed. Lemma dvdn_orbit G x : #|orbit to G x| %| #|G|. Proof. by rewrite card_orbit dvdn_indexg. Qed. Lemma card_orbit_stab G x : (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|. Proof. by rewrite mulnC card_orbit Lagrange ?subsetIl. Qed. Lemma actsP A S : reflect {acts A, on S | to} [acts A, on S | to]. Proof. apply: (iffP idP) => [nSA x|nSA]; first exact: acts_act. by apply/subsetP=> a Aa /[!inE]; apply/subsetP=> x; rewrite inE nSA. Qed. Arguments actsP {A S}. Lemma setact_orbit A x b : to^* (orbit to A x) b = orbit to (A :^ b) (to x b). Proof. apply/setP=> y; apply/idP/idP=> /imsetP[_ /imsetP[a Aa ->] ->{y}]. by rewrite actCJ mem_orbit ?memJ_conjg. by rewrite -actCJ mem_setact ?mem_orbit. Qed. Lemma astab_setact S a : 'C(to^* S a | to) = 'C(S | to) :^ a. Proof. apply/setP=> b; rewrite mem_conjg. apply/astabP/astabP=> stab x => [Sx|]. by rewrite conjgE invgK !actM stab ?actK //; apply/imsetP; exists x. by case/imsetP=> y Sy ->{x}; rewrite -actM conjgCV actM stab. Qed. Lemma astab1_act x a : 'C[to x a | to] = 'C[x | to] :^ a. Proof. by rewrite -astab_setact /setact imset_set1. Qed. Lemma atransP G S : [transitive G, on S | to] -> forall x, x \in S -> orbit to G x = S. Proof. by case/imsetP=> x _ -> y; apply/orbit_eqP. Qed. Lemma atransP2 G S : [transitive G, on S | to] -> {in S &, forall x y, exists2 a, a \in G & y = to x a}. Proof. by move=> GtrS x y /(atransP GtrS) <- /imsetP. Qed. Lemma atrans_acts G S : [transitive G, on S | to] -> [acts G, on S | to]. Proof. move=> GtrS; apply/subsetP=> a Ga; rewrite !inE. by apply/subsetP=> x /(atransP GtrS) <-; rewrite inE imset_f. Qed. Lemma atrans_supgroup G H S : G \subset H -> [transitive G, on S | to] -> [transitive H, on S | to] = [acts H, on S | to]. Proof. move=> sGH trG; apply/idP/idP=> [|actH]; first exact: atrans_acts. case/imsetP: trG => x Sx defS; apply/imsetP; exists x => //. by apply/eqP; rewrite eqEsubset acts_sub_orbit ?Sx // defS imsetS. Qed. Lemma atrans_acts_card G S : [transitive G, on S | to] = [acts G, on S | to] && (#|orbit to G @: S| == 1%N). Proof. apply/idP/andP=> [GtrS | [nSG]]. split; first exact: atrans_acts. rewrite ((_ @: S =P [set S]) _) ?cards1 // eqEsubset sub1set. apply/andP; split=> //; apply/subsetP=> _ /imsetP[x Sx ->]. by rewrite inE (atransP GtrS). rewrite eqn_leq andbC lt0n => /andP[/existsP[X /imsetP[x Sx X_Gx]]]. rewrite (cardD1 X) {X}X_Gx imset_f // ltnS leqn0 => /eqP GtrS. apply/imsetP; exists x => //; apply/eqP. rewrite eqEsubset acts_sub_orbit // Sx andbT. apply/subsetP=> y Sy; have:= card0_eq GtrS (orbit to G y). by rewrite !inE /= imset_f // andbT => /eqP <-; apply: orbit_refl. Qed. Lemma atrans_dvd G S : [transitive G, on S | to] -> #|S| %| #|G|. Proof. by case/imsetP=> x _ ->; apply: dvdn_orbit. Qed. (* This is Aschbacher (5.2) *) Lemma acts_fix_norm A B : A \subset 'N(B) -> [acts A, on 'Fix_to(B) | to]. Proof. move=> nAB; have:= acts_subnorm_fix to B; rewrite !setTI. exact: subset_trans. Qed. Lemma faithfulP A S : reflect (forall a, a \in A -> {in S, to^~ a =1 id} -> a = 1) [faithful A, on S | to]. Proof. apply: (iffP subsetP) => [Cto1 a Aa Ca | Cto1 a]. by apply/set1P; rewrite Cto1 // inE Aa; apply/astabP. by case/setIP=> Aa /astabP Ca; apply/set1P; apply: Cto1. Qed. (* This is the first part of Aschbacher (5.7) *) Lemma astab_trans_gcore G S u : [transitive G, on S | to] -> u \in S -> 'C(S | to) = gcore 'C[u | to] G. Proof. move=> transG Su; apply/eqP; rewrite eqEsubset. rewrite gcore_max ?astabS ?sub1set //=; last first. exact: subset_trans (atrans_acts transG) (astab_norm _ _). apply/subsetP=> x cSx; apply/astabP=> uy. case/(atransP2 transG Su) => y Gy ->{uy}. by apply/astab1P; rewrite astab1_act (bigcapP cSx). Qed. (* This is Aschbacher (5.20) *) Theorem subgroup_transitiveP G H S x : x \in S -> H \subset G -> [transitive G, on S | to] -> reflect ('C_G[x | to] * H = G) [transitive H, on S | to]. Proof. by move=> Sx sHG; apply: subgroup_transitivePin (subsetT G). Qed. (* This is Aschbacher (5.21) *) Lemma trans_subnorm_fixP x G H S : let C := 'C_G[x | to] in let T := 'Fix_(S | to)(H) in [transitive G, on S | to] -> x \in S -> H \subset C -> reflect ((H :^: G) ::&: C = H :^: C) [transitive 'N_G(H), on T | to]. Proof. move=> C T trGS Sx sHC; have actGS := acts_act (atrans_acts trGS). have:= sHC; rewrite subsetI sub_astab1 => /andP[sHG cHx]. have Tx: x \in T by rewrite inE Sx. apply: (iffP idP) => [trN | trC]. apply/setP=> Ha; apply/setIdP/imsetP=> [[]|[a Ca ->{Ha}]]; last first. by rewrite conj_subG //; case/setIP: Ca => Ga _; rewrite imset_f. case/imsetP=> a Ga ->{Ha}; rewrite subsetI !sub_conjg => /andP[_ sHCa]. have Txa: to x a^-1 \in T. by rewrite inE -sub_astab1 astab1_act actGS ?Sx ?groupV. have [b] := atransP2 trN Tx Txa; case/setIP=> Gb nHb cxba. exists (b * a); last by rewrite conjsgM (normP nHb). by rewrite inE groupM //; apply/astab1P; rewrite actM -cxba actKV. apply/imsetP; exists x => //; apply/setP=> y; apply/idP/idP=> [Ty|]. have [Sy cHy]:= setIP Ty; have [a Ga defy] := atransP2 trGS Sx Sy. have: H :^ a^-1 \in H :^: C. rewrite -trC inE subsetI imset_f 1?conj_subG ?groupV // sub_conjgV. by rewrite -astab1_act -defy sub_astab1. case/imsetP=> b /setIP[Gb /astab1P cxb] defHb. rewrite defy -{1}cxb -actM mem_orbit // inE groupM //. by apply/normP; rewrite conjsgM -defHb conjsgKV. case/imsetP=> a /setIP[Ga nHa] ->{y}. by rewrite inE actGS // Sx (acts_act (acts_fix_norm _) nHa). Qed. End TotalActions. Arguments astabP {aT rT to S a}. Arguments orbit_eqP {aT rT to G x y}. Arguments astab1P {aT rT to x a}. Arguments astabsP {aT rT to S a}. Arguments atransP {aT rT to G S}. Arguments actsP {aT rT to A S}. Arguments faithfulP {aT rT to A S}. Section Restrict. Variables (aT : finGroupType) (D : {set aT}) (rT : Type). Variables (to : action D rT) (A : {set aT}). Definition ract of A \subset D := act to. Variable sAD : A \subset D. Lemma ract_is_action : is_action A (ract sAD). Proof. rewrite /ract; case: to => f [injf fM]. by split=> // x; apply: (sub_in2 (subsetP sAD)). Qed. Canonical raction := Action ract_is_action. Lemma ractE : raction =1 to. Proof. by []. Qed. (* Other properties of raction need rT : finType; we defer them *) (* until after the definition of actperm. *) End Restrict. Notation "to \ sAD" := (raction to sAD) (at level 50) : action_scope. Section ActBy. Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Definition actby_cond (A : {set aT}) R (to : action D rT) : Prop := [acts A, on R | to]. Definition actby A R to of actby_cond A R to := fun x a => if (x \in R) && (a \in A) then to x a else x. Variables (A : {group aT}) (R : {set rT}) (to : action D rT). Hypothesis nRA : actby_cond A R to. Lemma actby_is_action : is_action A (actby nRA). Proof. rewrite /actby; split=> [a x y | x a b Aa Ab /=]; last first. rewrite Aa Ab groupM // !andbT actMin ?(subsetP (acts_dom nRA)) //. by case Rx: (x \in R); rewrite ?(acts_act nRA) ?Rx. case Aa: (a \in A); rewrite ?andbF ?andbT //. case Rx: (x \in R); case Ry: (y \in R) => // eqxy; first exact: act_inj eqxy. by rewrite -eqxy (acts_act nRA Aa) Rx in Ry. by rewrite eqxy (acts_act nRA Aa) Ry in Rx. Qed. Canonical action_by := Action actby_is_action. Local Notation "<[nRA]>" := action_by : action_scope. Lemma actbyE x a : x \in R -> a \in A -> <[nRA]>%act x a = to x a. Proof. by rewrite /= /actby => -> ->. Qed. Lemma afix_actby B : 'Fix_<[nRA]>(B) = ~: R :|: 'Fix_to(A :&: B). Proof. apply/setP=> x; rewrite !inE /= /actby. case: (x \in R); last by apply/subsetP=> a _ /[!inE]. apply/subsetP/subsetP=> [cBx a | cABx a Ba] /[!inE]. by case/andP=> Aa /cBx; rewrite inE Aa. by case: ifP => //= Aa; have:= cABx a; rewrite !inE Aa => ->. Qed. Lemma astab_actby S : 'C(S | <[nRA]>) = 'C_A(R :&: S | to). Proof. apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE. case Aa: (a \in A) => //=; apply/subsetP/subsetP=> cRSa x => [|Sx]. by case/setIP=> Rx /cRSa; rewrite !inE actbyE. by have:= cRSa x; rewrite !inE /= /actby Aa Sx; case: (x \in R) => //; apply. Qed. Lemma astabs_actby S : 'N(S | <[nRA]>) = 'N_A(R :&: S | to). Proof. apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE. case Aa: (a \in A) => //=; apply/subsetP/subsetP=> nRSa x => [|Sx]. by case/setIP=> Rx /nRSa; rewrite !inE actbyE ?(acts_act nRA) ?Rx. have:= nRSa x; rewrite !inE /= /actby Aa Sx ?(acts_act nRA) //. by case: (x \in R) => //; apply. Qed. Lemma acts_actby (B : {set aT}) S : [acts B, on S | <[nRA]>] = (B \subset A) && [acts B, on R :&: S | to]. Proof. by rewrite astabs_actby subsetI. Qed. End ActBy. Notation "<[ nRA ] >" := (action_by nRA) : action_scope. Section SubAction. Variables (aT : finGroupType) (D : {group aT}). Variables (rT : finType) (sP : pred rT) (sT : subFinType sP) (to : action D rT). Implicit Type A : {set aT}. Implicit Type u : sT. Implicit Type S : {set sT}. Definition subact_dom := 'N([set x | sP x] | to). Canonical subact_dom_group := [group of subact_dom]. Implicit Type Na : {a | a \in subact_dom}. Lemma sub_act_proof u Na : sP (to (val u) (val Na)). Proof. by case: Na => a /= /(astabs_act (val u)); rewrite !inE valP. Qed. Definition subact u a := if insub a is Some Na then Sub _ (sub_act_proof u Na) else u. Lemma val_subact u a : val (subact u a) = if a \in subact_dom then to (val u) a else val u. Proof. by rewrite /subact -if_neg; case: insubP => [Na|] -> //=; rewrite SubK => ->. Qed. Lemma subact_is_action : is_action subact_dom subact. Proof. split=> [a u v eq_uv | u a b Na Nb]; apply: val_inj. move/(congr1 val): eq_uv; rewrite !val_subact. by case: (a \in _); first move/act_inj. have Da := astabs_dom Na; have Db := astabs_dom Nb. by rewrite !val_subact Na Nb groupM ?actMin. Qed. Canonical subaction := Action subact_is_action. Lemma astab_subact S : 'C(S | subaction) = subact_dom :&: 'C(val @: S | to). Proof. apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa. have [Da _] := setIP sDa; rewrite !inE Da. apply/subsetP/subsetP=> [cSa _ /imsetP[x Sx ->] | cSa x Sx] /[!inE]. by have:= cSa x Sx; rewrite inE -val_eqE val_subact sDa. by have:= cSa _ (imset_f val Sx); rewrite inE -val_eqE val_subact sDa. Qed. Lemma astabs_subact S : 'N(S | subaction) = subact_dom :&: 'N(val @: S | to). Proof. apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa. have [Da _] := setIP sDa; rewrite !inE Da. apply/subsetP/subsetP=> [nSa _ /imsetP[x Sx ->] | nSa x Sx] /[!inE]. by have /[1!inE]/(imset_f val) := nSa x Sx; rewrite val_subact sDa. have /[1!inE]/imsetP[y Sy def_y] := nSa _ (imset_f val Sx). by rewrite ((_ a =P y) _) // -val_eqE val_subact sDa def_y. Qed. Lemma afix_subact A : A \subset subact_dom -> 'Fix_subaction(A) = val @^-1: 'Fix_to(A). Proof. move/subsetP=> sAD; apply/setP=> u. rewrite !inE !(sameP setIidPl eqP); congr (_ == A). apply/setP=> a /[!inE]; apply: andb_id2l => Aa. by rewrite -val_eqE val_subact sAD. Qed. End SubAction. Notation "to ^?" := (subaction _ to) (format "to ^?") : action_scope. Section QuotientAction. Variables (aT : finGroupType) (D : {group aT}) (rT : finGroupType). Variables (to : action D rT) (H : {group rT}). Definition qact_dom := 'N(rcosets H 'N(H) | to^*). Canonical qact_dom_group := [group of qact_dom]. Local Notation subdom := (subact_dom (coset_range H) to^*). Fact qact_subdomE : subdom = qact_dom. Proof. by congr 'N(_|_); apply/setP=> Hx; rewrite !inE genGid. Qed. Lemma qact_proof : qact_dom \subset subdom. Proof. by rewrite qact_subdomE. Qed. Definition qact : coset_of H -> aT -> coset_of H := act (to^*^? \ qact_proof). Canonical quotient_action := [action of qact]. Lemma acts_qact_dom : [acts qact_dom, on 'N(H) | to]. Proof. apply/subsetP=> a nNa; rewrite !inE (astabs_dom nNa); apply/subsetP=> x Nx. have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f. rewrite inE -(astabs_act _ nNa) => /rcosetsP[y Ny defHy]. have: to x a \in H :* y by rewrite -defHy (imset_f (to^~a)) ?rcoset_refl. by apply: subsetP; rewrite mul_subG ?sub1set ?normG. Qed. Lemma qactEcond x a : x \in 'N(H) -> quotient_action (coset H x) a = coset H (if a \in qact_dom then to x a else x). Proof. move=> Nx; apply: val_inj; rewrite val_subact //= qact_subdomE. have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f. case nNa: (a \in _); rewrite // -(astabs_act _ nNa). rewrite !val_coset ?(acts_act acts_qact_dom nNa) //=. case/rcosetsP=> y Ny defHy; rewrite defHy; apply: rcoset_eqP. by rewrite rcoset_sym -defHy (imset_f (_^~_)) ?rcoset_refl. Qed. Lemma qactE x a : x \in 'N(H) -> a \in qact_dom -> quotient_action (coset H x) a = coset H (to x a). Proof. by move=> Nx nNa; rewrite qactEcond ?nNa. Qed. Lemma acts_quotient (A : {set aT}) (B : {set rT}) : A \subset 'N_qact_dom(B | to) -> [acts A, on B / H | quotient_action]. Proof. move=> nBA; apply: subset_trans {A}nBA _; apply/subsetP=> a /setIP[dHa nBa]. rewrite inE dHa inE; apply/subsetP=> _ /morphimP[x nHx Bx ->]. rewrite inE /= qactE //. by rewrite mem_morphim ?(acts_act acts_qact_dom) ?(astabs_act _ nBa). Qed. Lemma astabs_quotient (G : {group rT}) : H <| G -> 'N(G / H | quotient_action) = 'N_qact_dom(G | to). Proof. move=> nsHG; have [_ nHG] := andP nsHG. apply/eqP; rewrite eqEsubset acts_quotient // andbT. apply/subsetP=> a nGa; have dHa := astabs_dom nGa; have [Da _]:= setIdP dHa. rewrite inE dHa 2!inE Da; apply/subsetP=> x Gx; have nHx := subsetP nHG x Gx. rewrite -(quotientGK nsHG) 2!inE (acts_act acts_qact_dom) ?nHx //= inE. by rewrite -qactE // (astabs_act _ nGa) mem_morphim. Qed. End QuotientAction. Notation "to / H" := (quotient_action to H) : action_scope. Section ModAction. Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Implicit Types (G : {group aT}) (S : {set rT}). Section GenericMod. Variable H : {group aT}. Local Notation dom := 'N_D(H). Local Notation range := 'Fix_to(D :&: H). Let acts_dom : {acts dom, on range | to} := acts_act (acts_subnorm_fix to H). Definition modact x (Ha : coset_of H) := if x \in range then to x (repr (D :&: Ha)) else x. Lemma modactEcond x a : a \in dom -> modact x (coset H a) = (if x \in range then to x a else x). Proof. case/setIP=> Da Na; case: ifP => Cx; rewrite /modact Cx //. rewrite val_coset // -group_modr ?sub1set //. case: (repr _) / (repr_rcosetP (D :&: H) a) => a' Ha'. by rewrite actMin ?(afixP Cx _ Ha') //; case/setIP: Ha'. Qed. Lemma modactE x a : a \in D -> a \in 'N(H) -> x \in range -> modact x (coset H a) = to x a. Proof. by move=> Da Na Rx; rewrite modactEcond ?Rx // inE Da. Qed. Lemma modact_is_action : is_action (D / H) modact. Proof. split=> [Ha x y | x Ha Hb]; last first. case/morphimP=> a Na Da ->{Ha}; case/morphimP=> b Nb Db ->{Hb}. rewrite -morphM //= !modactEcond // ?groupM ?(introT setIP _) //. by case: ifP => Cx; rewrite ?(acts_dom, Cx, actMin, introT setIP _). case: (set_0Vmem (D :&: Ha)) => [Da0 | [a /setIP[Da NHa]]]. by rewrite /modact Da0 repr_set0 !act1 !if_same. have Na := subsetP (coset_norm _) _ NHa. have NDa: a \in 'N_D(H) by rewrite inE Da. rewrite -(coset_mem NHa) !modactEcond //. do 2![case: ifP]=> Cy Cx // eqxy; first exact: act_inj eqxy. by rewrite -eqxy acts_dom ?Cx in Cy. by rewrite eqxy acts_dom ?Cy in Cx. Qed. Canonical mod_action := Action modact_is_action. Section Stabilizers. Variable S : {set rT}. Hypothesis cSH : H \subset 'C(S | to). Let fixSH : S \subset 'Fix_to(D :&: H). Proof. by rewrite -astabCin ?subsetIl // subIset ?cSH ?orbT. Qed. Lemma astabs_mod : 'N(S | mod_action) = 'N(S | to) / H. Proof. apply/setP=> Ha; apply/idP/morphimP=> [nSa | [a nHa nSa ->]]. case/morphimP: (astabs_dom nSa) => a nHa Da defHa. exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE. by have:= Sx; rewrite -(astabs_act x nSa) defHa /= modactE ?(subsetP fixSH). have Da := astabs_dom nSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx. by rewrite !inE /= modactE ?(astabs_act x nSa) ?(subsetP fixSH). Qed. Lemma astab_mod : 'C(S | mod_action) = 'C(S | to) / H. Proof. apply/setP=> Ha; apply/idP/morphimP=> [cSa | [a nHa cSa ->]]. case/morphimP: (astab_dom cSa) => a nHa Da defHa. exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE. by rewrite -{2}[x](astab_act cSa) // defHa /= modactE ?(subsetP fixSH). have Da := astab_dom cSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx. by rewrite !inE /= modactE ?(astab_act cSa) ?(subsetP fixSH). Qed. End Stabilizers. Lemma afix_mod G S : H \subset 'C(S | to) -> G \subset 'N_D(H) -> 'Fix_(S | mod_action)(G / H) = 'Fix_(S | to)(G). Proof. move=> cSH /subsetIP[sGD nHG]. apply/eqP; rewrite eqEsubset !subsetI !subsetIl /= -!astabCin ?quotientS //. have cfixH F: H \subset 'C(S :&: F | to). by rewrite (subset_trans cSH) // astabS ?subsetIl. rewrite andbC astab_mod ?quotientS //=; last by rewrite astabCin ?subsetIr. by rewrite -(quotientSGK nHG) //= -astab_mod // astabCin ?quotientS ?subsetIr. Qed. End GenericMod. Lemma modact_faithful G S : [faithful G / 'C_G(S | to), on S | mod_action 'C_G(S | to)]. Proof. rewrite /faithful astab_mod ?subsetIr //=. by rewrite -quotientIG ?subsetIr ?trivg_quotient. Qed. End ModAction. Notation "to %% H" := (mod_action to H) : action_scope. Section ActPerm. (* Morphism to permutations induced by an action. *) Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Variable to : action D rT. Definition actperm a := perm (act_inj to a). Lemma actpermM : {in D &, {morph actperm : a b / a * b}}. Proof. by move=> a b Da Db; apply/permP=> x; rewrite permM !permE actMin. Qed. Canonical actperm_morphism := Morphism actpermM. Lemma actpermE a x : actperm a x = to x a. Proof. by rewrite permE. Qed. Lemma actpermK x a : aperm x (actperm a) = to x a. Proof. exact: actpermE. Qed. Lemma ker_actperm : 'ker actperm = 'C(setT | to). Proof. congr (_ :&: _); apply/setP=> a /[!inE]/=. apply/eqP/subsetP=> [a1 x _ | a1]; first by rewrite inE -actpermE a1 perm1. by apply/permP=> x; apply/eqP; have:= a1 x; rewrite !inE actpermE perm1 => ->. Qed. End ActPerm. Section RestrictActionTheory. Variables (aT : finGroupType) (D : {set aT}) (rT : finType). Variables (to : action D rT). Lemma faithful_isom (A : {group aT}) S (nSA : actby_cond A S to) : [faithful A, on S | to] -> isom A (actperm <[nSA]> @* A) (actperm <[nSA]>). Proof. by move=> ffulAS; apply/isomP; rewrite ker_actperm astab_actby setIT. Qed. Variables (A : {set aT}) (sAD : A \subset D). Lemma ractpermE : actperm (to \ sAD) =1 actperm to. Proof. by move=> a; apply/permP=> x; rewrite !permE. Qed. Lemma afix_ract B : 'Fix_(to \ sAD)(B) = 'Fix_to(B). Proof. by []. Qed. Lemma astab_ract S : 'C(S | to \ sAD) = 'C_A(S | to). Proof. by rewrite setIA (setIidPl sAD). Qed. Lemma astabs_ract S : 'N(S | to \ sAD) = 'N_A(S | to). Proof. by rewrite setIA (setIidPl sAD). Qed. Lemma acts_ract (B : {set aT}) S : [acts B, on S | to \ sAD] = (B \subset A) && [acts B, on S | to]. Proof. by rewrite astabs_ract subsetI. Qed. End RestrictActionTheory. Section MorphAct. (* Action induced by a morphism to permutations. *) Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable phi : {morphism D >-> {perm rT}}. Definition mact x a := phi a x. Lemma mact_is_action : is_action D mact. Proof. split=> [a x y | x a b Da Db]; first exact: perm_inj. by rewrite /mact morphM //= permM. Qed. Canonical morph_action := Action mact_is_action. Lemma mactE x a : morph_action x a = phi a x. Proof. by []. Qed. Lemma injm_faithful : 'injm phi -> [faithful D, on setT | morph_action]. Proof. move/injmP=> phi_inj; apply/subsetP=> a /setIP[Da /astab_act a1]. apply/set1P/phi_inj => //; apply/permP=> x. by rewrite morph1 perm1 -mactE a1 ?inE. Qed. Lemma perm_mact a : actperm morph_action a = phi a. Proof. by apply/permP=> x; rewrite permE. Qed. End MorphAct. Notation "<< phi >>" := (morph_action phi) : action_scope. Section CompAct. Variables (gT aT : finGroupType) (rT : finType). Variables (D : {set aT}) (to : action D rT). Variables (B : {set gT}) (f : {morphism B >-> aT}). Definition comp_act x e := to x (f e). Lemma comp_is_action : is_action (f @*^-1 D) comp_act. Proof. split=> [e | x e1 e2]; first exact: act_inj. move=> /morphpreP[Be1 Dfe1] /morphpreP[Be2 Dfe2]. by rewrite /comp_act morphM ?actMin. Qed. Canonical comp_action := Action comp_is_action. Lemma comp_actE x e : comp_action x e = to x (f e). Proof. by []. Qed. Lemma afix_comp (A : {set gT}) : A \subset B -> 'Fix_comp_action(A) = 'Fix_to(f @* A). Proof. move=> sAB; apply/setP=> x; rewrite !inE /morphim (setIidPr sAB). apply/subsetP/subsetP; first by move=> + _ /imsetP[a + ->] => /[apply]/[!inE]. by move=> + a Aa => /(_ (f a)); rewrite !inE imset_f// => ->. Qed. Lemma astab_comp S : 'C(S | comp_action) = f @*^-1 'C(S | to). Proof. by apply/setP=> x; rewrite !inE -andbA. Qed. Lemma astabs_comp S : 'N(S | comp_action) = f @*^-1 'N(S | to). Proof. by apply/setP=> x; rewrite !inE -andbA. Qed. End CompAct. Notation "to \o f" := (comp_action to f) : action_scope. Section PermAction. (* Natural action of permutation groups. *) Variable rT : finType. Local Notation gT := {perm rT}. Implicit Types a b c : gT. Lemma aperm_is_action : is_action setT (@aperm rT). Proof. by apply: is_total_action => [x|x a b]; rewrite apermE (perm1, permM). Qed. Canonical perm_action := Action aperm_is_action. Lemma porbitE a : porbit a = orbit perm_action <[a]>%g. Proof. by rewrite unlock. Qed. Lemma perm_act1P a : reflect (forall x, aperm x a = x) (a == 1). Proof. apply: (iffP eqP) => [-> x | a1]; first exact: act1. by apply/permP=> x; rewrite -apermE a1 perm1. Qed. Lemma perm_faithful A : [faithful A, on setT | perm_action]. Proof. apply/subsetP=> a /setIP[Da crTa]. by apply/set1P; apply/permP=> x; rewrite -apermE perm1 (astabP crTa) ?inE. Qed. Lemma actperm_id p : actperm perm_action p = p. Proof. by apply/permP=> x; rewrite permE. Qed. End PermAction. Arguments perm_act1P {rT a}. Notation "'P" := (perm_action _) : action_scope. Section ActpermOrbits. Variables (aT : finGroupType) (D : {group aT}) (rT : finType). Variable to : action D rT. Lemma orbit_morphim_actperm (A : {set aT}) : A \subset D -> orbit 'P (actperm to @* A) =1 orbit to A. Proof. move=> sAD x; rewrite morphimEsub // /orbit -imset_comp. by apply: eq_imset => a //=; rewrite actpermK. Qed. Lemma porbit_actperm (a : aT) : a \in D -> porbit (actperm to a) =1 orbit to <[a]>. Proof. move=> Da x. by rewrite porbitE -orbit_morphim_actperm ?cycle_subG ?morphim_cycle. Qed. End ActpermOrbits. Section RestrictPerm. Variables (T : finType) (S : {set T}). Definition restr_perm := actperm (<[subxx 'N(S | 'P)]>). Canonical restr_perm_morphism := [morphism of restr_perm]. Lemma restr_perm_on p : perm_on S (restr_perm p). Proof. apply/subsetP=> x; apply: contraR => notSx. by rewrite permE /= /actby (negPf notSx). Qed. Lemma triv_restr_perm p : p \notin 'N(S | 'P) -> restr_perm p = 1. Proof. move=> not_nSp; apply/permP=> x. by rewrite !permE /= /actby (negPf not_nSp) andbF. Qed. Lemma restr_permE : {in 'N(S | 'P) & S, forall p, restr_perm p =1 p}. Proof. by move=> y x nSp Sx; rewrite /= actpermE actbyE. Qed. Lemma ker_restr_perm : 'ker restr_perm = 'C(S | 'P). Proof. by rewrite ker_actperm astab_actby setIT (setIidPr (astab_sub _ _)). Qed. Lemma im_restr_perm p : restr_perm p @: S = S. Proof. exact: im_perm_on (restr_perm_on p). Qed. Lemma restr_perm_commute s : commute (restr_perm s) s. Proof. have [sC|/triv_restr_perm->] := boolP (s \in 'N(S | 'P)); last first. exact: (commute_sym (commute1 _)). apply/permP => x; have /= xsS := astabsP sC x; rewrite !permM. have [xS|xNS] := boolP (x \in S); first by rewrite ?(restr_permE) ?xsS. by rewrite !(out_perm (restr_perm_on _)) ?xsS. Qed. End RestrictPerm. Section Symmetry. Variables (T : finType) (S : {set T}). Lemma SymE : Sym S = 'C(~: S | 'P). Proof. apply/setP => s; rewrite inE; apply/idP/astabP => [sS x|/= S_id]. by rewrite inE /= apermE => /out_perm->. by apply/subsetP => x; move=> /(contra_neqN (S_id _)); rewrite inE negbK. Qed. End Symmetry. Section AutIn. Variable gT : finGroupType. Definition Aut_in A (B : {set gT}) := 'N_A(B | 'P) / 'C_A(B | 'P). Variables G H : {group gT}. Hypothesis sHG: H \subset G. Lemma Aut_restr_perm a : a \in Aut G -> restr_perm H a \in Aut H. Proof. move=> AutGa. case nHa: (a \in 'N(H | 'P)); last by rewrite triv_restr_perm ?nHa ?group1. rewrite inE restr_perm_on; apply/morphicP=> x y Hx Hy /=. by rewrite !restr_permE ?groupM // -(autmE AutGa) morphM ?(subsetP sHG). Qed. Lemma restr_perm_Aut : restr_perm H @* Aut G \subset Aut H. Proof. by apply/subsetP=> a'; case/morphimP=> a _ AutGa ->{a'}; apply: Aut_restr_perm. Qed. Lemma Aut_in_isog : Aut_in (Aut G) H \isog restr_perm H @* Aut G. Proof. rewrite /Aut_in -ker_restr_perm kerE -morphpreIdom -morphimIdom -kerE /=. by rewrite setIA (setIC _ (Aut G)) first_isog_loc ?subsetIr. Qed. Lemma Aut_sub_fullP : reflect (forall h : {morphism H >-> gT}, 'injm h -> h @* H = H -> exists g : {morphism G >-> gT}, [/\ 'injm g, g @* G = G & {in H, g =1 h}]) (Aut_in (Aut G) H \isog Aut H). Proof. rewrite (isog_transl _ Aut_in_isog) /=; set rG := _ @* _. apply: (iffP idP) => [iso_rG h injh hH| AutHinG]. have: aut injh hH \in rG; last case/morphimP=> g nHg AutGg def_g. suffices ->: rG = Aut H by apply: Aut_aut. by apply/eqP; rewrite eqEcard restr_perm_Aut /= (card_isog iso_rG). exists (autm_morphism AutGg); rewrite injm_autm im_autm; split=> // x Hx. by rewrite -(autE injh hH Hx) def_g actpermE actbyE. suffices ->: rG = Aut H by apply: isog_refl. apply/eqP; rewrite eqEsubset restr_perm_Aut /=. apply/subsetP=> h AutHh; have hH := im_autm AutHh. have [g [injg gG eq_gh]] := AutHinG _ (injm_autm AutHh) hH. have [Ng AutGg]: aut injg gG \in 'N(H | 'P) /\ aut injg gG \in Aut G. rewrite Aut_aut !inE; split=> //; apply/subsetP=> x Hx. by rewrite inE /= /aperm autE ?(subsetP sHG) // -hH eq_gh ?mem_morphim. apply/morphimP; exists (aut injg gG) => //; apply: (eq_Aut AutHh) => [|x Hx]. by rewrite (subsetP restr_perm_Aut) // mem_morphim. by rewrite restr_permE //= /aperm autE ?eq_gh ?(subsetP sHG). Qed. End AutIn. Arguments Aut_in {gT} A%_g B%_g. Section InjmAutIn. Variables (gT rT : finGroupType) (D G H : {group gT}) (f : {morphism D >-> rT}). Hypotheses (injf : 'injm f) (sGD : G \subset D) (sHG : H \subset G). Let sHD := subset_trans sHG sGD. Local Notation fGisom := (Aut_isom injf sGD). Local Notation fHisom := (Aut_isom injf sHD). Local Notation inH := (restr_perm H). Local Notation infH := (restr_perm (f @* H)). Lemma astabs_Aut_isom a : a \in Aut G -> (fGisom a \in 'N(f @* H | 'P)) = (a \in 'N(H | 'P)). Proof. move=> AutGa; rewrite !inE sub_morphim_pre // subsetI sHD /= /aperm. rewrite !(sameP setIidPl eqP) !eqEsubset !subsetIl; apply: eq_subset_r => x. rewrite !inE; apply: andb_id2l => Hx; have Gx: x \in G := subsetP sHG x Hx. have Dax: a x \in D by rewrite (subsetP sGD) // Aut_closed. by rewrite Aut_isomE // -!sub1set -morphim_set1 // injmSK ?sub1set. Qed. Lemma isom_restr_perm a : a \in Aut G -> fHisom (inH a) = infH (fGisom a). Proof. move=> AutGa; case nHa: (a \in 'N(H | 'P)); last first. by rewrite !triv_restr_perm ?astabs_Aut_isom ?nHa ?morph1. apply: (eq_Aut (Aut_Aut_isom injf sHD _)) => [|fx Hfx /=]. by rewrite (Aut_restr_perm (morphimS f sHG)) ?Aut_Aut_isom. have [x Dx Hx def_fx] := morphimP Hfx; have Gx := subsetP sHG x Hx. rewrite {1}def_fx Aut_isomE ?(Aut_restr_perm sHG) //. by rewrite !restr_permE ?astabs_Aut_isom // def_fx Aut_isomE. Qed. Lemma restr_perm_isom : isom (inH @* Aut G) (infH @* Aut (f @* G)) fHisom. Proof. apply: sub_isom; rewrite ?restr_perm_Aut ?injm_Aut_isom //=. rewrite -(im_Aut_isom injf sGD) -!morphim_comp. apply: eq_in_morphim; last exact: isom_restr_perm. (* TODO: investigate why rewrite does not match in the same order *) apply/setP=> a; rewrite in_setI [in RHS]in_setI; apply: andb_id2r => AutGa. (* the middle rewrite was rewrite 2!in_setI *) rewrite /= inE andbC inE (Aut_restr_perm sHG) //=. by symmetry; rewrite inE AutGa inE astabs_Aut_isom. Qed. Lemma injm_Aut_sub : Aut_in (Aut (f @* G)) (f @* H) \isog Aut_in (Aut G) H. Proof. do 2!rewrite isog_sym (isog_transl _ (Aut_in_isog _ _)). by rewrite isog_sym (isom_isog _ _ restr_perm_isom) // restr_perm_Aut. Qed. Lemma injm_Aut_full : (Aut_in (Aut (f @* G)) (f @* H) \isog Aut (f @* H)) = (Aut_in (Aut G) H \isog Aut H). Proof. by rewrite (isog_transl _ injm_Aut_sub) (isog_transr _ (injm_Aut injf sHD)). Qed. End InjmAutIn. Section GroupAction. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Local Notation actT := (action D rT). Definition is_groupAction (to : actT) := {in D, forall a, actperm to a \in Aut R}. Structure groupAction := GroupAction {gact :> actT; _ : is_groupAction gact}. Definition clone_groupAction to := let: GroupAction _ toA := to return {type of GroupAction for to} -> _ in fun k => k toA : groupAction. End GroupAction. Delimit Scope groupAction_scope with gact. Bind Scope groupAction_scope with groupAction. Arguments is_groupAction {aT rT D%_g} R%_g to%_act. Arguments groupAction {aT rT} D%_g R%_g. Arguments gact {aT rT D%_g R%_g} to%_gact : rename. Notation "[ 'groupAction' 'of' to ]" := (clone_groupAction (@GroupAction _ _ _ _ to)) (format "[ 'groupAction' 'of' to ]") : form_scope. Section GroupActionDefs. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Implicit Type A : {set aT}. Implicit Type S : {set rT}. Implicit Type to : groupAction D R. Definition gact_range of groupAction D R := R. Definition gacent to A := 'Fix_(R | to)(D :&: A). Definition acts_on_group A S to := [acts A, on S | to] /\ S \subset R. Coercion actby_cond_group A S to : acts_on_group A S to -> actby_cond A S to := @proj1 _ _. Definition acts_irreducibly A S to := [min S of G | G :!=: 1 & [acts A, on G | to]]. End GroupActionDefs. Arguments gacent {aT rT D%_g R%_g} to%_gact A%_g. Arguments acts_on_group {aT rT D%_g R%_g} A%_g S%_g to%_gact. Arguments acts_irreducibly {aT rT D%_g R%_g} A%_g S%_g to%_gact. Notation "''C_' ( | to ) ( A )" := (gacent to A) : group_scope. Notation "''C_' ( G | to ) ( A )" := (G :&: 'C_(|to)(A)) : group_scope. Notation "''C_' ( | to ) [ a ]" := 'C_(|to)([set a]) : group_scope. Notation "''C_' ( G | to ) [ a ]" := 'C_(G | to)([set a]) : group_scope. Notation "{ 'acts' A , 'on' 'group' G | to }" := (acts_on_group A G to) (format "{ 'acts' A , 'on' 'group' G | to }") : type_scope. Section RawGroupAction. Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}). Variable to : groupAction D R. Lemma actperm_Aut : is_groupAction R to. Proof. by case: to. Qed. Lemma im_actperm_Aut : actperm to @* D \subset Aut R. Proof. by apply/subsetP=> _ /morphimP[a _ Da ->]; apply: actperm_Aut. Qed. Lemma gact_out x a : a \in D -> x \notin R -> to x a = x. Proof. by move=> Da Rx; rewrite -actpermE (out_Aut _ Rx) ?actperm_Aut. Qed. Lemma gactM : {in D, forall a, {in R &, {morph to^~ a : x y / x * y}}}. Proof. move=> a Da /= x y; rewrite -!(actpermE to); apply: morphicP x y. by rewrite Aut_morphic ?actperm_Aut. Qed. Lemma actmM a : {in R &, {morph actm to a : x y / x * y}}. Proof. by rewrite /actm; case: ifP => //; apply: gactM. Qed. Canonical act_morphism a := Morphism (actmM a). Lemma morphim_actm : {in D, forall a (S : {set rT}), S \subset R -> actm to a @* S = to^* S a}. Proof. by move=> a Da /= S sSR; rewrite /morphim /= actmEfun ?(setIidPr _). Qed. Variables (a : aT) (A B : {set aT}) (S : {set rT}). Lemma gacentIdom : 'C_(|to)(D :&: A) = 'C_(|to)(A). Proof. by rewrite /gacent setIA setIid. Qed. Lemma gacentIim : 'C_(R | to)(A) = 'C_(|to)(A). Proof. by rewrite setIA setIid. Qed. Lemma gacentS : A \subset B -> 'C_(|to)(B) \subset 'C_(|to)(A). Proof. by move=> sAB; rewrite !(setIS, afixS). Qed. Lemma gacentU : 'C_(|to)(A :|: B) = 'C_(|to)(A) :&: 'C_(|to)(B). Proof. by rewrite -setIIr -afixU -setIUr. Qed. Hypotheses (Da : a \in D) (sAD : A \subset D) (sSR : S \subset R). Lemma gacentE : 'C_(|to)(A) = 'Fix_(R | to)(A). Proof. by rewrite -{2}(setIidPr sAD). Qed. Lemma gacent1E : 'C_(|to)[a] = 'Fix_(R | to)[a]. Proof. by rewrite /gacent [D :&: _](setIidPr _) ?sub1set. Qed. Lemma subgacentE : 'C_(S | to)(A) = 'Fix_(S | to)(A). Proof. by rewrite gacentE setIA (setIidPl sSR). Qed. Lemma subgacent1E : 'C_(S | to)[a] = 'Fix_(S | to)[a]. Proof. by rewrite gacent1E setIA (setIidPl sSR). Qed. End RawGroupAction. Section GroupActionTheory. Variables aT rT : finGroupType. Variables (D : {group aT}) (R : {group rT}) (to : groupAction D R). Implicit Type A B : {set aT}. Implicit Types G H : {group aT}. Implicit Type S : {set rT}. Implicit Types M N : {group rT}. Lemma gact1 : {in D, forall a, to 1 a = 1}. Proof. by move=> a Da; rewrite /= -actmE ?morph1. Qed. Lemma gactV : {in D, forall a, {in R, {morph to^~ a : x / x^-1}}}. Proof. by move=> a Da /= x Rx; move; rewrite -!actmE ?morphV. Qed. Lemma gactX : {in D, forall a n, {in R, {morph to^~ a : x / x ^+ n}}}. Proof. by move=> a Da /= n x Rx; rewrite -!actmE // morphX. Qed. Lemma gactJ : {in D, forall a, {in R &, {morph to^~ a : x y / x ^ y}}}. Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphJ. Qed. Lemma gactR : {in D, forall a, {in R &, {morph to^~ a : x y / [~ x, y]}}}. Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphR. Qed. Lemma gact_stable : {acts D, on R | to}. Proof. apply: acts_act; apply/subsetP=> a Da; rewrite !inE Da. apply/subsetP=> x; rewrite inE; apply: contraLR => R'xa. by rewrite -(actKin to Da x) gact_out ?groupV. Qed. Lemma group_set_gacent A : group_set 'C_(|to)(A). Proof. apply/group_setP; split=> [|x y]. by rewrite !inE group1; apply/subsetP=> a /setIP[Da _]; rewrite inE gact1. case/setIP=> Rx /afixP cAx /setIP[Ry /afixP cAy]. rewrite inE groupM //; apply/afixP=> a Aa. by rewrite gactM ?cAx ?cAy //; case/setIP: Aa. Qed. Canonical gacent_group A := Group (group_set_gacent A). Lemma gacent1 : 'C_(|to)(1) = R. Proof. by rewrite /gacent (setIidPr (sub1G _)) afix1 setIT. Qed. Lemma gacent_gen A : A \subset D -> 'C_(|to)(<<A>>) = 'C_(|to)(A). Proof. by move=> sAD; rewrite /gacent ![D :&: _](setIidPr _) ?gen_subG ?afix_gen_in. Qed. Lemma gacentD1 A : 'C_(|to)(A^#) = 'C_(|to)(A). Proof. rewrite -gacentIdom -gacent_gen ?subsetIl // setIDA genD1 ?group1 //. by rewrite gacent_gen ?subsetIl // gacentIdom. Qed. Lemma gacent_cycle a : a \in D -> 'C_(|to)(<[a]>) = 'C_(|to)[a]. Proof. by move=> Da; rewrite gacent_gen ?sub1set. Qed. Lemma gacentY A B : A \subset D -> B \subset D -> 'C_(|to)(A <*> B) = 'C_(|to)(A) :&: 'C_(|to)(B). Proof. by move=> sAD sBD; rewrite gacent_gen ?gacentU // subUset sAD. Qed. Lemma gacentM G H : G \subset D -> H \subset D -> 'C_(|to)(G * H) = 'C_(|to)(G) :&: 'C_(|to)(H). Proof. by move=> sGD sHB; rewrite -gacent_gen ?mul_subG // genM_join gacentY. Qed. Lemma astab1 : 'C(1 | to) = D. Proof. by apply/setP=> x; rewrite ?(inE, sub1set) andb_idr //; move/gact1=> ->. Qed. Lemma astab_range : 'C(R | to) = 'C(setT | to). Proof. apply/eqP; rewrite eqEsubset andbC astabS ?subsetT //=. apply/subsetP=> a cRa; have Da := astab_dom cRa; rewrite !inE Da. apply/subsetP=> x; rewrite -(setUCr R) !inE. by case/orP=> ?; [rewrite (astab_act cRa) | rewrite gact_out]. Qed. Lemma gacentC A S : A \subset D -> S \subset R -> (S \subset 'C_(|to)(A)) = (A \subset 'C(S | to)). Proof. by move=> sAD sSR; rewrite subsetI sSR astabCin // (setIidPr sAD). Qed. Lemma astab_gen S : S \subset R -> 'C(<<S>> | to) = 'C(S | to). Proof. move=> sSR; apply/setP=> a; case Da: (a \in D); last by rewrite !inE Da. by rewrite -!sub1set -!gacentC ?sub1set ?gen_subG. Qed. Lemma astabM M N : M \subset R -> N \subset R -> 'C(M * N | to) = 'C(M | to) :&: 'C(N | to). Proof. move=> sMR sNR; rewrite -astabU -astab_gen ?mul_subG // genM_join. by rewrite astab_gen // subUset sMR. Qed. Lemma astabs1 : 'N(1 | to) = D. Proof. by rewrite astabs_set1 astab1. Qed. Lemma astabs_range : 'N(R | to) = D. Proof. apply/setIidPl; apply/subsetP=> a Da; rewrite inE. by apply/subsetP=> x Rx; rewrite inE gact_stable. Qed. Lemma astabsD1 S : 'N(S^# | to) = 'N(S | to). Proof. case S1: (1 \in S); last first. by rewrite (setDidPl _) // disjoint_sym disjoints_subset sub1set inE S1. apply/eqP; rewrite eqEsubset andbC -{1}astabsIdom -{1}astabs1 setIC astabsD /=. by rewrite -{2}(setD1K S1) -astabsIdom -{1}astabs1 astabsU. Qed. Lemma gacts_range A : A \subset D -> {acts A, on group R | to}. Proof. by move=> sAD; split; rewrite ?astabs_range. Qed. Lemma acts_subnorm_gacent A : A \subset D -> [acts 'N_D(A), on 'C_(| to)(A) | to]. Proof. move=> sAD; rewrite gacentE // actsI ?astabs_range ?subsetIl //. by rewrite -{2}(setIidPr sAD) acts_subnorm_fix. Qed. Lemma acts_subnorm_subgacent A B S : A \subset D -> [acts B, on S | to] -> [acts 'N_B(A), on 'C_(S | to)(A) | to]. Proof. move=> sAD actsB; rewrite actsI //; first by rewrite subIset ?actsB. by rewrite (subset_trans _ (acts_subnorm_gacent sAD)) ?setSI ?(acts_dom actsB). Qed. Lemma acts_gen A S : S \subset R -> [acts A, on S | to] -> [acts A, on <<S>> | to]. Proof. move=> sSR actsA; apply: {A}subset_trans actsA _. apply/subsetP=> a nSa; have Da := astabs_dom nSa; rewrite !inE Da. apply: subset_trans (_ : <<S>> \subset actm to a @*^-1 <<S>>) _. rewrite gen_subG subsetI sSR; apply/subsetP=> x Sx. by rewrite inE /= actmE ?mem_gen // astabs_act. by apply/subsetP=> x /[!inE]; case/andP=> Rx; rewrite /= actmE. Qed. Lemma acts_joing A M N : M \subset R -> N \subset R -> [acts A, on M | to] -> [acts A, on N | to] -> [acts A, on M <*> N | to]. Proof. by move=> sMR sNR nMA nNA; rewrite acts_gen ?actsU // subUset sMR. Qed. Lemma injm_actm a : 'injm (actm to a). Proof. apply/injmP=> x y Rx Ry; rewrite /= /actm; case: ifP => Da //. exact: act_inj. Qed. Lemma im_actm a : actm to a @* R = R. Proof. apply/eqP; rewrite eqEcard (card_injm (injm_actm a)) // leqnn andbT. apply/subsetP=> _ /morphimP[x Rx _ ->] /=. by rewrite /actm; case: ifP => // Da; rewrite gact_stable. Qed. Lemma acts_char G M : G \subset D -> M \char R -> [acts G, on M | to]. Proof. move=> sGD /charP[sMR charM]. apply/subsetP=> a Ga; have Da := subsetP sGD a Ga; rewrite !inE Da. apply/subsetP=> x Mx; have Rx := subsetP sMR x Mx. by rewrite inE -(charM _ (injm_actm a) (im_actm a)) -actmE // mem_morphim. Qed. Lemma gacts_char G M : G \subset D -> M \char R -> {acts G, on group M | to}. (* TODO: investigate why rewrite does not match in the same order *) Proof. by move=> sGD charM; split; rewrite ?acts_char// char_sub. Qed. (* was ending with rewrite (acts_char, char_sub)// *) Section Restrict. Variables (A : {group aT}) (sAD : A \subset D). Lemma ract_is_groupAction : is_groupAction R (to \ sAD). Proof. by move=> a Aa /=; rewrite ractpermE actperm_Aut ?(subsetP sAD). Qed. Canonical ract_groupAction := GroupAction ract_is_groupAction. Lemma gacent_ract B : 'C_(|ract_groupAction)(B) = 'C_(|to)(A :&: B). Proof. by rewrite /gacent afix_ract setIA (setIidPr sAD). Qed. End Restrict. Section ActBy. Variables (A : {group aT}) (G : {group rT}) (nGAg : {acts A, on group G | to}). Lemma actby_is_groupAction : is_groupAction G <[nGAg]>. Proof. move=> a Aa; rewrite /= inE; apply/andP; split. apply/subsetP=> x; apply: contraR => Gx. by rewrite actpermE /= /actby (negbTE Gx). apply/morphicP=> x y Gx Gy; rewrite !actpermE /= /actby Aa groupM ?Gx ?Gy //=. by case nGAg; move/acts_dom; do 2!move/subsetP=> ?; rewrite gactM; auto. Qed. Canonical actby_groupAction := GroupAction actby_is_groupAction. Lemma gacent_actby B : 'C_(|actby_groupAction)(B) = 'C_(G | to)(A :&: B). Proof. rewrite /gacent afix_actby !setIA setIid setIUr setICr set0U. by have [nAG sGR] := nGAg; rewrite (setIidPr (acts_dom nAG)) (setIidPl sGR). Qed. End ActBy. Section Quotient. Variable H : {group rT}. Lemma acts_qact_dom_norm : {acts qact_dom to H, on 'N(H) | to}. Proof. move=> a HDa /= x; rewrite {2}(('N(H) =P to^~ a @^-1: 'N(H)) _) ?inE {x}//. rewrite eqEcard (card_preimset _ (act_inj _ _)) leqnn andbT. apply/subsetP=> x Nx; rewrite inE; move/(astabs_act (H :* x)): HDa. rewrite mem_rcosets mulSGid ?normG // Nx => /rcosetsP[y Ny defHy]. suffices: to x a \in H :* y by apply: subsetP; rewrite mul_subG ?sub1set ?normG. by rewrite -defHy; apply: imset_f; apply: rcoset_refl. Qed. Lemma qact_is_groupAction : is_groupAction (R / H) (to / H). Proof. move=> a HDa /=; have Da := astabs_dom HDa. rewrite inE; apply/andP; split. apply/subsetP=> Hx /=; case: (cosetP Hx) => x Nx ->{Hx}. apply: contraR => R'Hx; rewrite actpermE qactE // gact_out //. by apply: contra R'Hx; apply: mem_morphim. apply/morphicP=> Hx Hy; rewrite !actpermE. case/morphimP=> x Nx Gx ->{Hx}; case/morphimP=> y Ny Gy ->{Hy}. by rewrite -morphM ?qactE ?groupM ?gactM // morphM ?acts_qact_dom_norm. Qed. Canonical quotient_groupAction := GroupAction qact_is_groupAction. Lemma qact_domE : H \subset R -> qact_dom to H = 'N(H | to). Proof. move=> sHR; apply/setP=> a; apply/idP/idP=> nHa; have Da := astabs_dom nHa. rewrite !inE Da; apply/subsetP=> x Hx; rewrite inE -(rcoset1 H). have /rcosetsP[y Ny defHy]: to^~ a @: H \in rcosets H 'N(H). by rewrite (astabs_act _ nHa); apply/rcosetsP; exists 1; rewrite ?mulg1. by rewrite (rcoset_eqP (_ : 1 \in H :* y)) -defHy -1?(gact1 Da) mem_setact. rewrite !inE Da; apply/subsetP=> Hx /[1!inE] /rcosetsP[x Nx ->{Hx}]. apply/imsetP; exists (to x a). case Rx: (x \in R); last by rewrite gact_out ?Rx. rewrite inE; apply/subsetP=> _ /imsetP[y Hy ->]. rewrite -(actKVin to Da y) -gactJ // ?(subsetP sHR, astabs_act, groupV) //. by rewrite memJ_norm // astabs_act ?groupV. apply/eqP; rewrite rcosetE eqEcard. rewrite (card_imset _ (act_inj _ _)) !card_rcoset leqnn andbT. apply/subsetP=> _ /imsetP[y Hxy ->]; rewrite !mem_rcoset in Hxy *. have Rxy := subsetP sHR _ Hxy; rewrite -(mulgKV x y). case Rx: (x \in R); last by rewrite !gact_out ?mulgK // 1?groupMl ?Rx. by rewrite -gactV // -gactM 1?groupMr ?groupV // mulgK astabs_act. Qed. End Quotient. Section Mod. Variable H : {group aT}. Lemma modact_is_groupAction : is_groupAction 'C_(|to)(H) (to %% H). Proof. move=> Ha /morphimP[a Na Da ->]; have NDa: a \in 'N_D(H) by apply/setIP. rewrite inE; apply/andP; split. apply/subsetP=> x; rewrite 2!inE andbC actpermE /= modactEcond //. by apply: contraR; case: ifP => // E Rx; rewrite gact_out. apply/morphicP=> x y /setIP[Rx cHx] /setIP[Ry cHy]. rewrite /= !actpermE /= !modactE ?gactM //. suffices: x * y \in 'C_(|to)(H) by case/setIP. by rewrite groupM //; apply/setIP. Qed. Canonical mod_groupAction := GroupAction modact_is_groupAction. Lemma modgactE x a : H \subset 'C(R | to) -> a \in 'N_D(H) -> (to %% H)%act x (coset H a) = to x a. Proof. move=> cRH NDa /=; have [Da Na] := setIP NDa. have [Rx | notRx] := boolP (x \in R). by rewrite modactE //; apply/afixP=> b /setIP[_ /(subsetP cRH)/astab_act->]. rewrite gact_out //= /modact; case: ifP => // _; rewrite gact_out //. suffices: a \in D :&: coset H a by case/mem_repr/setIP. by rewrite inE Da val_coset // rcoset_refl. Qed. Lemma gacent_mod G M : H \subset 'C(M | to) -> G \subset 'N(H) -> 'C_(M | mod_groupAction)(G / H) = 'C_(M | to)(G). Proof. move=> cMH nHG; rewrite -gacentIdom gacentE ?subsetIl // setICA. have sHD: H \subset D by rewrite (subset_trans cMH) ?subsetIl. rewrite -quotientGI // afix_mod ?setIS // setICA -gacentIim (setIC R) -setIA. rewrite -gacentE ?subsetIl // gacentIdom setICA (setIidPr _) //. by rewrite gacentC // ?(subset_trans cMH) ?astabS ?subsetIl // setICA subsetIl. Qed. Lemma acts_irr_mod G M : H \subset 'C(M | to) -> G \subset 'N(H) -> acts_irreducibly G M to -> acts_irreducibly (G / H) M mod_groupAction. Proof. move=> cMH nHG /mingroupP[/andP[ntM nMG] minM]. apply/mingroupP; rewrite ntM astabs_mod ?quotientS //; split=> // L modL ntL. have cLH: H \subset 'C(L | to) by rewrite (subset_trans cMH) ?astabS //. apply: minM => //; case/andP: modL => ->; rewrite astabs_mod ?quotientSGK //. by rewrite (subset_trans cLH) ?astab_sub. Qed. End Mod. Lemma modact_coset_astab x a : a \in D -> (to %% 'C(R | to))%act x (coset _ a) = to x a. Proof. move=> Da; apply: modgactE => {x}//. rewrite !inE Da; apply/subsetP=> _ /imsetP[c Cc ->]. have Dc := astab_dom Cc; rewrite !inE groupJ //. apply/subsetP=> x Rx; rewrite inE conjgE !actMin ?groupM ?groupV //. by rewrite (astab_act Cc) ?actKVin // gact_stable ?groupV. Qed. Lemma acts_irr_mod_astab G M : acts_irreducibly G M to -> acts_irreducibly (G / 'C_G(M | to)) M (mod_groupAction _). Proof. move=> irrG; have /andP[_ nMG] := mingroupp irrG. apply: acts_irr_mod irrG; first exact: subsetIr. by rewrite normsI ?normG // (subset_trans nMG) // astab_norm. Qed. Section CompAct. Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> aT}). Lemma comp_is_groupAction : is_groupAction R (comp_action to f). Proof. move=> a /morphpreP[Ba Dfa]; apply: etrans (actperm_Aut to Dfa). by congr (_ \in Aut R); apply/permP=> x; rewrite !actpermE. Qed. Canonical comp_groupAction := GroupAction comp_is_groupAction. Lemma gacent_comp U : 'C_(|comp_groupAction)(U) = 'C_(|to)(f @* U). Proof. rewrite /gacent afix_comp ?subIset ?subxx //. by rewrite -(setIC U) (setIC D) morphim_setIpre. Qed. End CompAct. End GroupActionTheory. Notation "''C_' ( | to ) ( A )" := (gacent_group to A) : Group_scope. Notation "''C_' ( G | to ) ( A )" := (setI_group G 'C_(|to)(A)) : Group_scope. Notation "''C_' ( | to ) [ a ]" := (gacent_group to [set a%g]) : Group_scope. Notation "''C_' ( G | to ) [ a ]" := (setI_group G 'C_(|to)[a]) : Group_scope. Notation "to \ sAD" := (ract_groupAction to sAD) : groupAction_scope. Notation "<[ nGA ] >" := (actby_groupAction nGA) : groupAction_scope. Notation "to / H" := (quotient_groupAction to H) : groupAction_scope. Notation "to %% H" := (mod_groupAction to H) : groupAction_scope. Notation "to \o f" := (comp_groupAction to f) : groupAction_scope. (* Operator group isomorphism. *) Section MorphAction. Variables (aT1 aT2 : finGroupType) (rT1 rT2 : finType). Variables (D1 : {group aT1}) (D2 : {group aT2}). Variables (to1 : action D1 rT1) (to2 : action D2 rT2). Variables (A : {set aT1}) (R S : {set rT1}). Variables (h : rT1 -> rT2) (f : {morphism D1 >-> aT2}). Hypotheses (actsDR : {acts D1, on R | to1}) (injh : {in R &, injective h}). Hypothesis defD2 : f @* D1 = D2. Hypotheses (sSR : S \subset R) (sAD1 : A \subset D1). Hypothesis hfJ : {in S & D1, morph_act to1 to2 h f}. Lemma morph_astabs : f @* 'N(S | to1) = 'N(h @: S | to2). Proof. apply/setP=> fx; apply/morphimP/idP=> [[x D1x nSx ->] | nSx]. rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->]. by rewrite inE -hfJ ?imset_f // (astabs_act _ nSx). have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1). by rewrite defD2 (astabs_dom nSx). exists x => //; rewrite !inE D1x; apply/subsetP=> u Su. have /imsetP[u' Su' /injh def_u']: h (to1 u x) \in h @: S. by rewrite hfJ // -def_fx (astabs_act _ nSx) imset_f. by rewrite inE def_u' ?actsDR ?(subsetP sSR). Qed. Lemma morph_astab : f @* 'C(S | to1) = 'C(h @: S | to2). Proof. apply/setP=> fx; apply/morphimP/idP=> [[x D1x cSx ->] | cSx]. rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->]. by rewrite inE -hfJ // (astab_act cSx). have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1). by rewrite defD2 (astab_dom cSx). exists x => //; rewrite !inE D1x; apply/subsetP=> u Su. rewrite inE -(inj_in_eq injh) ?actsDR ?(subsetP sSR) ?hfJ //. by rewrite -def_fx (astab_act cSx) ?imset_f. Qed. Lemma morph_afix : h @: 'Fix_(S | to1)(A) = 'Fix_(h @: S | to2)(f @* A). Proof. apply/setP=> hu; apply/imsetP/setIP=> [[u /setIP[Su cAu] ->]|]. split; first by rewrite imset_f. by apply/afixP=> _ /morphimP[x D1x Ax ->]; rewrite -hfJ ?(afixP cAu). case=> /imsetP[u Su ->] /afixP c_hu_fA; exists u; rewrite // inE Su. apply/afixP=> x Ax; have Dx := subsetP sAD1 x Ax. by apply: injh; rewrite ?actsDR ?(subsetP sSR) ?hfJ // c_hu_fA ?mem_morphim. Qed. End MorphAction. Section MorphGroupAction. Variables (aT1 aT2 rT1 rT2 : finGroupType). Variables (D1 : {group aT1}) (D2 : {group aT2}). Variables (R1 : {group rT1}) (R2 : {group rT2}). Variables (to1 : groupAction D1 R1) (to2 : groupAction D2 R2). Variables (h : {morphism R1 >-> rT2}) (f : {morphism D1 >-> aT2}). Hypotheses (iso_h : isom R1 R2 h) (iso_f : isom D1 D2 f). Hypothesis hfJ : {in R1 & D1, morph_act to1 to2 h f}. Implicit Types (A : {set aT1}) (S : {set rT1}) (M : {group rT1}). Lemma morph_gastabs S : S \subset R1 -> f @* 'N(S | to1) = 'N(h @* S | to2). Proof. have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h). move=> sSR1; rewrite (morphimEsub _ sSR1). apply: (morph_astabs (gact_stable to1) (injmP injh)) => // u x. by move/(subsetP sSR1); apply: hfJ. Qed. Lemma morph_gastab S : S \subset R1 -> f @* 'C(S | to1) = 'C(h @* S | to2). Proof. have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h). move=> sSR1; rewrite (morphimEsub _ sSR1). apply: (morph_astab (gact_stable to1) (injmP injh)) => // u x. by move/(subsetP sSR1); apply: hfJ. Qed. Lemma morph_gacent A : A \subset D1 -> h @* 'C_(|to1)(A) = 'C_(|to2)(f @* A). Proof. have [[_ defD2] [injh defR2]] := (isomP iso_f, isomP iso_h). move=> sAD1; rewrite !gacentE //; last by rewrite -defD2 morphimS. rewrite morphimEsub ?subsetIl // -{1}defR2 morphimEdom. exact: (morph_afix (gact_stable to1) (injmP injh)). Qed. Lemma morph_gact_irr A M : A \subset D1 -> M \subset R1 -> acts_irreducibly (f @* A) (h @* M) to2 = acts_irreducibly A M to1. Proof. move=> sAD1 sMR1. have [[injf defD2] [injh defR2]] := (isomP iso_f, isomP iso_h). have h_eq1 := morphim_injm_eq1 injh. apply/mingroupP/mingroupP=> [] [/andP[ntM actAM] minM]. split=> [|U]; first by rewrite -h_eq1 // ntM -(injmSK injf) ?morph_gastabs. case/andP=> ntU acts_fAU sUM; have sUR1 := subset_trans sUM sMR1. apply: (injm_morphim_inj injh) => //; apply: minM; last exact: morphimS. by rewrite h_eq1 // ntU -morph_gastabs ?morphimS. split=> [|U]; first by rewrite h_eq1 // ntM -morph_gastabs ?morphimS. case/andP=> ntU acts_fAU sUhM. have sUhR1 := subset_trans sUhM (morphimS h sMR1). have sU'M: h @*^-1 U \subset M by rewrite sub_morphpre_injm. rewrite /= -(minM _ _ sU'M) ?morphpreK // -h_eq1 ?subsetIl // -(injmSK injf) //. by rewrite morph_gastabs ?(subset_trans sU'M) // morphpreK ?ntU. Qed. End MorphGroupAction. (* Conjugation and right translation actions. *) Section InternalActionDefs. Variable gT : finGroupType. Implicit Type A : {set gT}. Implicit Type G : {group gT}. (* This is not a Canonical action because it is seldom used, and it would *) (* cause too many spurious matches (any group product would be viewed as an *) (* action!). *) Definition mulgr_action := TotalAction (@mulg1 gT) (@mulgA gT). Canonical conjg_action := TotalAction (@conjg1 gT) (@conjgM gT). Lemma conjg_is_groupAction : is_groupAction setT conjg_action. Proof. move=> a _; rewrite inE; apply/andP; split; first by apply/subsetP=> x /[1!inE]. by apply/morphicP=> x y _ _; rewrite !actpermE /= conjMg. Qed. Canonical conjg_groupAction := GroupAction conjg_is_groupAction. Lemma rcoset_is_action : is_action setT (@rcoset gT). Proof. by apply: is_total_action => [A|A x y]; rewrite !rcosetE (mulg1, rcosetM). Qed. Canonical rcoset_action := Action rcoset_is_action. Canonical conjsg_action := TotalAction (@conjsg1 gT) (@conjsgM gT). Lemma conjG_is_action : is_action setT (@conjG_group gT). Proof. apply: is_total_action => [G | G x y]; apply: val_inj; rewrite /= ?act1 //. exact: actM. Qed. Definition conjG_action := Action conjG_is_action. End InternalActionDefs. Notation "'R" := (@mulgr_action _) : action_scope. Notation "'Rs" := (@rcoset_action _) : action_scope. Notation "'J" := (@conjg_action _) : action_scope. Notation "'J" := (@conjg_groupAction _) : groupAction_scope. Notation "'Js" := (@conjsg_action _) : action_scope. Notation "'JG" := (@conjG_action _) : action_scope. Notation "'Q" := ('J / _)%act : action_scope. Notation "'Q" := ('J / _)%gact : groupAction_scope. Section InternalGroupAction. Variable gT : finGroupType. Implicit Types A B : {set gT}. Implicit Types G H : {group gT}. Implicit Type x : gT. (* Various identities for actions on groups. *) Lemma orbitR G x : orbit 'R G x = x *: G. Proof. by rewrite -lcosetE. Qed. Lemma astab1R x : 'C[x | 'R] = 1. Proof. apply/trivgP/subsetP=> y cxy. by rewrite -(mulKg x y) [x * y](astab1P cxy) mulVg set11. Qed. Lemma astabR G : 'C(G | 'R) = 1. Proof. apply/trivgP/subsetP=> x cGx. by rewrite -(mul1g x) [1 * x](astabP cGx) group1. Qed. Lemma astabsR G : 'N(G | 'R) = G. Proof. apply/setP=> x; rewrite !inE -setactVin ?inE //=. by rewrite -groupV -{1 3}(mulg1 G) rcoset_sym -sub1set -mulGS -!rcosetE. Qed. Lemma atransR G : [transitive G, on G | 'R]. Proof. by rewrite /atrans -{1}(mul1g G) -orbitR imset_f. Qed. Lemma faithfulR G : [faithful G, on G | 'R]. Proof. by rewrite /faithful astabR subsetIr. Qed. Definition Cayley_repr G := actperm <[atrans_acts (atransR G)]>. Theorem Cayley_isom G : isom G (Cayley_repr G @* G) (Cayley_repr G). Proof. exact: faithful_isom (faithfulR G). Qed. Theorem Cayley_isog G : G \isog Cayley_repr G @* G. Proof. exact: isom_isog (Cayley_isom G). Qed. Lemma orbitJ G x : orbit 'J G x = x ^: G. Proof. by []. Qed. Lemma afixJ A : 'Fix_('J)(A) = 'C(A). Proof. apply/setP=> x; apply/afixP/centP=> cAx y Ay /=. by rewrite /commute conjgC cAx. by rewrite conjgE cAx ?mulKg. Qed. Lemma astabJ A : 'C(A |'J) = 'C(A). Proof. apply/setP=> x; apply/astabP/centP=> cAx y Ay /=. by apply: esym; rewrite conjgC cAx. by rewrite conjgE -cAx ?mulKg. Qed. Lemma astab1J x : 'C[x |'J] = 'C[x]. Proof. by rewrite astabJ cent_set1. Qed. Lemma astabsJ A : 'N(A | 'J) = 'N(A). Proof. by apply/setP=> x; rewrite -2!groupV !inE -conjg_preim -sub_conjg. Qed. Lemma setactJ A x : 'J^*%act A x = A :^ x. Proof. by []. Qed. Lemma gacentJ A : 'C_(|'J)(A) = 'C(A). Proof. by rewrite gacentE ?setTI ?subsetT ?afixJ. Qed. Lemma orbitRs G A : orbit 'Rs G A = rcosets A G. Proof. by []. Qed. Lemma sub_afixRs_norms G x A : (G :* x \in 'Fix_('Rs)(A)) = (A \subset G :^ x). Proof. rewrite inE /=; apply: eq_subset_r => a. rewrite inE rcosetE -(can2_eq (rcosetKV x) (rcosetK x)) -!rcosetM. rewrite eqEcard card_rcoset leqnn andbT mulgA (conjgCV x) mulgK. by rewrite -{2 3}(mulGid G) mulGS sub1set -mem_conjg. Qed. Lemma sub_afixRs_norm G x : (G :* x \in 'Fix_('Rs)(G)) = (x \in 'N(G)). Proof. by rewrite sub_afixRs_norms -groupV inE sub_conjgV. Qed. Lemma afixRs_rcosets A G : 'Fix_(rcosets G A | 'Rs)(G) = rcosets G 'N_A(G). Proof. apply/setP=> Gx; apply/setIP/rcosetsP=> [[/rcosetsP[x Ax ->]]|[x]]. by rewrite sub_afixRs_norm => Nx; exists x; rewrite // inE Ax. by case/setIP=> Ax Nx ->; rewrite -{1}rcosetE imset_f // sub_afixRs_norm. Qed. Lemma astab1Rs G : 'C[G : {set gT} | 'Rs] = G. Proof. apply/setP=> x. by apply/astab1P/idP=> /= [<- | Gx]; rewrite rcosetE ?rcoset_refl ?rcoset_id. Qed. Lemma actsRs_rcosets H G : [acts G, on rcosets H G | 'Rs]. Proof. by rewrite -orbitRs acts_orbit ?subsetT. Qed. Lemma transRs_rcosets H G : [transitive G, on rcosets H G | 'Rs]. Proof. by rewrite -orbitRs atrans_orbit. Qed. (* This is the second part of Aschbacher (5.7) *) Lemma astabRs_rcosets H G : 'C(rcosets H G | 'Rs) = gcore H G. Proof. have transGH := transRs_rcosets H G. by rewrite (astab_trans_gcore transGH (orbit_refl _ G _)) astab1Rs. Qed. Lemma orbitJs G A : orbit 'Js G A = A :^: G. Proof. by []. Qed. Lemma astab1Js A : 'C[A | 'Js] = 'N(A). Proof. by apply/setP=> x; apply/astab1P/normP. Qed. Lemma card_conjugates A G : #|A :^: G| = #|G : 'N_G(A)|. Proof. by rewrite card_orbit astab1Js. Qed. Lemma afixJG G A : (G \in 'Fix_('JG)(A)) = (A \subset 'N(G)). Proof. by apply/afixP/normsP=> nG x Ax; apply/eqP; move/eqP: (nG x Ax). Qed. Lemma astab1JG G : 'C[G | 'JG] = 'N(G). Proof. by apply/setP=> x; apply/astab1P/normP=> [/congr_group | /group_inj]. Qed. Lemma dom_qactJ H : qact_dom 'J H = 'N(H). Proof. by rewrite qact_domE ?subsetT ?astabsJ. Qed. Lemma qactJ H (Hy : coset_of H) x : 'Q%act Hy x = if x \in 'N(H) then Hy ^ coset H x else Hy. Proof. case: (cosetP Hy) => y Ny ->{Hy}. by rewrite qactEcond // dom_qactJ; case Nx: (x \in 'N(H)); rewrite ?morphJ. Qed. Lemma actsQ A B H : A \subset 'N(H) -> A \subset 'N(B) -> [acts A, on B / H | 'Q]. Proof. by move=> nHA nBA; rewrite acts_quotient // subsetI dom_qactJ nHA astabsJ. Qed. Lemma astabsQ G H : H <| G -> 'N(G / H | 'Q) = 'N(H) :&: 'N(G). Proof. by move=> nsHG; rewrite astabs_quotient // dom_qactJ astabsJ. Qed. Lemma astabQ H Abar : 'C(Abar |'Q) = coset H @*^-1 'C(Abar). Proof. apply/setP=> x; rewrite inE /= dom_qactJ morphpreE in_setI /=. apply: andb_id2l => Nx; rewrite !inE -sub1set centsC cent_set1. apply: eq_subset_r => {Abar} Hy; rewrite inE qactJ Nx (sameP eqP conjg_fixP). by rewrite (sameP cent1P eqP) (sameP commgP eqP). Qed. Lemma sub_astabQ A H Bbar : (A \subset 'C(Bbar | 'Q)) = (A \subset 'N(H)) && (A / H \subset 'C(Bbar)). Proof. rewrite astabQ -morphpreIdom subsetI; apply: andb_id2l => nHA. by rewrite -sub_quotient_pre. Qed. Lemma sub_astabQR A B H : A \subset 'N(H) -> B \subset 'N(H) -> (A \subset 'C(B / H | 'Q)) = ([~: A, B] \subset H). Proof. move=> nHA nHB; rewrite sub_astabQ nHA /= (sameP commG1P eqP). by rewrite eqEsubset sub1G andbT -quotientR // quotient_sub1 // comm_subG. Qed. Lemma astabQR A H : A \subset 'N(H) -> 'C(A / H | 'Q) = [set x in 'N(H) | [~: [set x], A] \subset H]. Proof. move=> nHA; apply/setP=> x; rewrite astabQ -morphpreIdom 2!inE -astabQ. by case nHx: (x \in _); rewrite //= -sub1set sub_astabQR ?sub1set. Qed. Lemma quotient_astabQ H Abar : 'C(Abar | 'Q) / H = 'C(Abar). Proof. by rewrite astabQ cosetpreK. Qed. Lemma conj_astabQ A H x : x \in 'N(H) -> 'C(A / H | 'Q) :^ x = 'C(A :^ x / H | 'Q). Proof. move=> nHx; apply/setP=> y; rewrite !astabQ mem_conjg !in_setI -mem_conjg. rewrite -normJ (normP nHx) quotientJ //; apply/andb_id2l => nHy. by rewrite !inE centJ morphJ ?groupV ?morphV // -mem_conjg. Qed. Section CardClass. Variable G : {group gT}. Lemma index_cent1 x : #|G : 'C_G[x]| = #|x ^: G|. Proof. by rewrite -astab1J -card_orbit. Qed. Lemma classes_partition : partition (classes G) G. Proof. by apply: orbit_partition; apply/actsP=> x Gx y; apply: groupJr. Qed. Lemma sum_card_class : \sum_(C in classes G) #|C| = #|G|. Proof. by apply: acts_sum_card_orbit; apply/actsP=> x Gx y; apply: groupJr. Qed. Lemma class_formula : \sum_(C in classes G) #|G : 'C_G[repr C]| = #|G|. Proof. rewrite -sum_card_class; apply: eq_bigr => _ /imsetP[x Gx ->]. have: x \in x ^: G by rewrite -{1}(conjg1 x) imset_f. by case/mem_repr/imsetP=> y Gy ->; rewrite index_cent1 classGidl. Qed. Lemma abelian_classP : reflect {in G, forall x, x ^: G = [set x]} (abelian G). Proof. rewrite /abelian -astabJ astabC. by apply: (iffP subsetP) => cGG x Gx; apply/orbit1P; apply: cGG. Qed. Lemma card_classes_abelian : abelian G = (#|classes G| == #|G|). Proof. have cGgt0 C: C \in classes G -> 1 <= #|C| ?= iff (#|C| == 1)%N. by case/imsetP=> x _ ->; rewrite eq_sym -index_cent1. rewrite -sum_card_class -sum1_card (leqif_sum cGgt0). apply/abelian_classP/forall_inP=> [cGG _ /imsetP[x Gx ->]| cGG x Gx]. by rewrite cGG ?cards1. apply/esym/eqP; rewrite eqEcard sub1set cards1 class_refl leq_eqVlt cGG //. exact: imset_f. Qed. End CardClass. End InternalGroupAction. Lemma gacentQ (gT : finGroupType) (H : {group gT}) (A : {set gT}) : 'C_(|'Q)(A) = 'C(A / H). Proof. apply/setP=> Hx; case: (cosetP Hx) => x Nx ->{Hx}. rewrite -sub_cent1 -astab1J astabC sub1set -(quotientInorm H A). have defD: qact_dom 'J H = 'N(H) by rewrite qact_domE ?subsetT ?astabsJ. rewrite !(inE, mem_quotient) //= defD setIC. apply/subsetP/subsetP=> [cAx _ /morphimP[a Na Aa ->] | cAx a Aa]. by move/cAx: Aa; rewrite !inE qactE ?defD ?morphJ. have [_ Na] := setIP Aa; move/implyP: (cAx (coset H a)); rewrite mem_morphim //. by rewrite !inE qactE ?defD ?morphJ. Qed. Section AutAct. Variable (gT : finGroupType) (G : {set gT}). Definition autact := act ('P \ subsetT (Aut G)). Canonical aut_action := [action of autact]. Lemma autactK a : actperm aut_action a = a. Proof. by apply/permP=> x; rewrite permE. Qed. Lemma autact_is_groupAction : is_groupAction G aut_action. Proof. by move=> a Aa /=; rewrite autactK. Qed. Canonical aut_groupAction := GroupAction autact_is_groupAction. Section perm_prime_orbit. Variable (T : finType) (c : {perm T}). Hypothesis Tp : prime #|T|. Hypothesis cc : #[c]%g = #|T|. Let cp : prime #[c]%g. Proof. by rewrite cc. Qed. Lemma perm_prime_atrans : [transitive <[c]>, on setT | 'P]. Proof. apply/imsetP; suff /existsP[x] : [exists x, ~~ (#|orbit 'P <[c]> x| < #[c])]. move=> oxT; suff /eqP orbit_x : orbit 'P <[c]> x == setT by exists x. by rewrite eqEcard subsetT cardsT -cc leqNgt. apply/forallP => olT; have o1 x : #|orbit 'P <[c]> x| == 1%N. by case/primeP: cp => _ /(_ _ (dvdn_orbit 'P _ x))/orP[]//; rewrite ltn_eqF. suff c1 : c = 1%g by rewrite c1 ?order1 in (cp). apply/permP => x; rewrite perm1; apply/set1P. by rewrite -(card_orbit1 (eqP (o1 _))) (mem_orbit 'P) ?cycle_id. Qed. Lemma perm_prime_orbit x : orbit 'P <[c]> x = [set: T]. Proof. by apply: atransP => //; apply: perm_prime_atrans. Qed. Lemma perm_prime_astab x : 'C_<[c]>[x | 'P]%g = 1%g. Proof. by apply/card1_trivg/eqP; rewrite -(@eqn_pmul2l #|orbit 'P <[c]> x|) ?card_orbit_stab ?perm_prime_orbit ?cardsT ?muln1 ?prime_gt0// -cc. Qed. End perm_prime_orbit. End AutAct. Arguments autact {gT} G%_g. Arguments aut_action {gT} G%_g. Arguments aut_groupAction {gT} G%_g. Notation "[ 'Aut' G ]" := (aut_action G) : action_scope. Notation "[ 'Aut' G ]" := (aut_groupAction G) : groupAction_scope.
Dual.lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv import Mathlib.LinearAlgebra.QuadraticForm.Prod /-! # Quadratic form structures related to `Module.Dual` ## Main definitions * `LinearMap.dualProd R M`, the bilinear form on `(f, x) : Module.Dual R M × M` defined as `f x`. * `QuadraticForm.dualProd R M`, the quadratic form on `(f, x) : Module.Dual R M × M` defined as `f x`. * `QuadraticForm.toDualProd : (Q.prod <| -Q) →qᵢ QuadraticForm.dualProd R M` a form-preserving map from `(Q.prod <| -Q)` to `QuadraticForm.dualProd R M`. -/ variable (R M N : Type*) namespace LinearMap section Semiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- The symmetric bilinear form on `Module.Dual R M × M` defined as `B (f, x) (g, y) = f y + g x`. -/ @[simps!] def dualProd : LinearMap.BilinForm R (Module.Dual R M × M) := (applyₗ.comp (snd R (Module.Dual R M) M)).compl₂ (fst R (Module.Dual R M) M) + ((applyₗ.comp (snd R (Module.Dual R M) M)).compl₂ (fst R (Module.Dual R M) M)).flip theorem isSymm_dualProd : (dualProd R M).IsSymm := ⟨fun _x _y => add_comm _ _⟩ end Semiring section Ring variable [CommRing R] [AddCommGroup M] [Module R M] theorem separatingLeft_dualProd : (dualProd R M).SeparatingLeft ↔ Function.Injective (Module.Dual.eval R M) := by classical rw [separatingLeft_iff_ker_eq_bot, ker_eq_bot] let e := LinearEquiv.prodComm R _ _ ≪≫ₗ Module.dualProdDualEquivDual R (Module.Dual R M) M let h_d := e.symm.toLinearMap.comp (dualProd R M) refine (Function.Injective.of_comp_iff e.symm.injective (dualProd R M)).symm.trans ?_ rw [← LinearEquiv.coe_toLinearMap, ← coe_comp] change Function.Injective h_d ↔ _ have : h_d = prodMap id (Module.Dual.eval R M) := by refine ext fun x => Prod.ext ?_ ?_ · ext dsimp [e, h_d, Module.Dual.eval, LinearEquiv.prodComm] simp · ext dsimp [e, h_d, Module.Dual.eval, LinearEquiv.prodComm] simp rw [this, coe_prodMap] refine Prod.map_injective.trans ?_ exact and_iff_right Function.injective_id end Ring end LinearMap namespace QuadraticForm open QuadraticMap section Semiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] /-- The quadratic form on `Module.Dual R M × M` defined as `Q (f, x) = f x`. -/ @[simps] def dualProd : QuadraticForm R (Module.Dual R M × M) where toFun p := p.1 p.2 toFun_smul a p := by rw [Prod.smul_fst, Prod.smul_snd, LinearMap.smul_apply, LinearMap.map_smul, smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_assoc] exists_companion' := ⟨LinearMap.dualProd R M, fun p q => by rw [LinearMap.dualProd_apply_apply, Prod.fst_add, Prod.snd_add, LinearMap.add_apply, map_add, map_add, add_right_comm _ (q.1 q.2), add_comm (q.1 p.2) (p.1 q.2), ← add_assoc, ← add_assoc]⟩ @[simp] theorem _root_.LinearMap.dualProd.toQuadraticForm : (LinearMap.dualProd R M).toQuadraticMap = 2 • dualProd R M := ext fun _a => (two_nsmul _).symm variable {R M N} /-- Any module isomorphism induces a quadratic isomorphism between the corresponding `dual_prod.` -/ @[simps!] def dualProdIsometry (f : M ≃ₗ[R] N) : (dualProd R M).IsometryEquiv (dualProd R N) where toLinearEquiv := f.dualMap.symm.prodCongr f map_app' x := DFunLike.congr_arg x.fst <| f.symm_apply_apply _ /-- `QuadraticForm.dualProd` commutes (isometrically) with `QuadraticForm.prod`. -/ @[simps!] def dualProdProdIsometry : (dualProd R (M × N)).IsometryEquiv ((dualProd R M).prod (dualProd R N)) where toLinearEquiv := (Module.dualProdDualEquivDual R M N).symm.prodCongr (LinearEquiv.refl R (M × N)) ≪≫ₗ LinearEquiv.prodProdProdComm R _ _ M N map_app' m := (m.fst.map_add _ _).symm.trans <| DFunLike.congr_arg m.fst <| Prod.ext (add_zero _) (zero_add _) end Semiring section Ring variable [CommRing R] [AddCommGroup M] [Module R M] variable {R M} /-- The isometry sending `(Q.prod <| -Q)` to `(QuadraticForm.dualProd R M)`. This is `σ` from Proposition 4.8, page 84 of [*Hermitian K-Theory and Geometric Applications*][hyman1973]; though we swap the order of the pairs. -/ @[simps!] def toDualProd (Q : QuadraticForm R M) [Invertible (2 : R)] : (Q.prod <| -Q) →qᵢ QuadraticForm.dualProd R M where toLinearMap := LinearMap.prod (Q.associated.comp (LinearMap.fst _ _ _) + Q.associated.comp (LinearMap.snd _ _ _)) (LinearMap.fst _ _ _ - LinearMap.snd _ _ _) map_app' x := by dsimp only [associated, associatedHom] dsimp only [LinearMap.smul_apply, LinearMap.coe_mk, AddHom.coe_mk, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearMap.prod_apply, Pi.prod, LinearMap.add_apply, LinearMap.coe_comp, Function.comp_apply, LinearMap.fst_apply, LinearMap.snd_apply, LinearMap.sub_apply, dualProd_apply, polarBilin_apply_apply, prod_apply, neg_apply] simp only [polar_sub_right, polar_self, nsmul_eq_mul, Nat.cast_ofNat, polar_comm _ x.1 x.2, smul_sub, Module.End.smul_def, sub_add_sub_cancel, ← sub_eq_add_neg (Q x.1) (Q x.2)] rw [← LinearMap.map_sub (⅟2 : Module.End R R), ← mul_sub, ← Module.End.smul_def] simp only [Module.End.smul_def, half_moduleEnd_apply_eq_half_smul, smul_eq_mul, invOf_mul_cancel_left'] /-! TODO: show that `QuadraticForm.toDualProd` is an `QuadraticForm.IsometryEquiv` -/ end Ring end QuadraticForm
StacksAttribute.lean
import Mathlib.Tactic.StacksAttribute import Mathlib.Util.ParseCommand /-- info: No tags found. -/ #guard_msgs in #stacks_tags namespace X @[stacks A04Q "A comment", kerodon B15R "Also a comment"] theorem tagged : True := .intro end X /-- info: some ([Stacks Tag A04Q](https://stacks.math.columbia.edu/tag/A04Q) (A comment) [Kerodon Tag B15R](https://kerodon.net/tag/B15R) (Also a comment)) -/ #guard_msgs in run_cmd Lean.logInfo m!"{← Lean.findDocString? (← Lean.getEnv) `X.tagged}" #guard_msgs in @[stacks 0BR2, kerodon 0X12] example : True := .intro @[stacks 0BR2, stacks 0X14 "I can also have a comment"] example : True := .intro @[stacks 0X14 "I can also have a comment"] example : True := .intro @[stacks 0BR2, stacks 0X14 "I can also have a comment"] example : True := .intro @[stacks 0X14 "I can also have a comment"] example : True := .intro /-- error: <input>:1:3: Stacks tags must be exactly 4 characters -/ #guard_msgs in #parse Mathlib.StacksTag.stacksTagFn => "A05" /-- error: <input>:1:4: Stacks tags must consist only of digits and uppercase letters. -/ #guard_msgs in #parse Mathlib.StacksTag.stacksTagFn => "A05b" /-- info: 0BD5 -/ #guard_msgs in #parse Mathlib.StacksTag.stacksTagFn => "0BD5" /-- info: [Stacks Tag A04Q](https://stacks.math.columbia.edu/tag/A04Q) corresponds to declaration 'X.tagged'. (A comment) -/ #guard_msgs in #stacks_tags /-- info: [Stacks Tag A04Q](https://stacks.math.columbia.edu/tag/A04Q) corresponds to declaration 'X.tagged'. (A comment) True -/ #guard_msgs in #stacks_tags! /-- info: [Stacks Tag B15R](https://kerodon.net/tag/B15R) corresponds to declaration 'X.tagged'. (Also a comment) True -/ #guard_msgs in #kerodon_tags! section errors open Lean Parser Mathlib.StacksTag def captureException (env : Environment) (s : ParserFn) (input : String) : Except String Syntax := let ictx := mkInputContext input "<input>" let s := s.run ictx { env, options := {} } (getTokenTable env) (mkParserState input) if !s.allErrors.isEmpty then .error (s.toErrorMsg ictx) else if ictx.input.atEnd s.pos then .ok s.stxStack.back else .error ((s.mkError "end of input").toErrorMsg ictx) /-- error: <input>:1:3: Stacks tags must be exactly 4 characters -/ #guard_msgs in run_cmd do let _ ← Lean.ofExcept <| captureException (← getEnv) stacksTagFn "A05" /-- error: <input>:1:4: Stacks tags must consist only of digits and uppercase letters. -/ #guard_msgs in run_cmd do let _ ← Lean.ofExcept <| captureException (← getEnv) stacksTagFn "aaaa" /-- error: <input>:1:0: expected stacks tag -/ #guard_msgs in run_cmd do let env ← getEnv let _ ← Lean.ofExcept <| captureException env stacksTagFn "\"A04Q\"" end errors
Defs.lean
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kevin Buzzard, Kim Morrison, Johan Commelin, Chris Hughes, Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Group.Defs import Mathlib.Algebra.Notation.Pi.Defs import Mathlib.Data.FunLike.Basic import Mathlib.Logic.Function.Iterate /-! # Monoid and group homomorphisms This file defines the bundled structures for monoid and group homomorphisms. Namely, we define `MonoidHom` (resp., `AddMonoidHom`) to be bundled homomorphisms between multiplicative (resp., additive) monoids or groups. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. This file also defines the lesser-used (and notation-less) homomorphism types which are used as building blocks for other homomorphisms: * `ZeroHom` * `OneHom` * `AddHom` * `MulHom` ## Notations * `→+`: Bundled `AddMonoid` homs. Also use for `AddGroup` homs. * `→*`: Bundled `Monoid` homs. Also use for `Group` homs. * `→ₙ+`: Bundled `AddSemigroup` homs. * `→ₙ*`: Bundled `Semigroup` homs. ## Implementation notes There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. There is no `GroupHom` -- the idea is that `MonoidHom` is used. The constructor for `MonoidHom` needs a proof of `map_one` as well as `map_mul`; a separate constructor `MonoidHom.mk'` will construct group homs (i.e. monoid homs between groups) given only a proof that multiplication is preserved, Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `MonoidHom`. When they can be inferred from the type it is faster to use this method than to use type class inference. Historically this file also included definitions of unbundled homomorphism classes; they were deprecated and moved to `Deprecated/Group`. ## Tags MonoidHom, AddMonoidHom -/ open Function variable {ι α β M N P : Type*} -- monoids variable {G : Type*} {H : Type*} -- groups variable {F : Type*} -- homs section Zero /-- `ZeroHom M N` is the type of functions `M → N` that preserve zero. When possible, instead of parametrizing results over `(f : ZeroHom M N)`, you should parametrize over `(F : Type*) [ZeroHomClass F M N] (f : F)`. When you extend this structure, make sure to also extend `ZeroHomClass`. -/ structure ZeroHom (M : Type*) (N : Type*) [Zero M] [Zero N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves 0 -/ protected map_zero' : toFun 0 = 0 /-- `ZeroHomClass F M N` states that `F` is a type of zero-preserving homomorphisms. You should extend this typeclass when you extend `ZeroHom`. -/ class ZeroHomClass (F : Type*) (M N : outParam Type*) [Zero M] [Zero N] [FunLike F M N] : Prop where /-- The proposition that the function preserves 0 -/ map_zero : ∀ f : F, f 0 = 0 -- Instances and lemmas are defined below through `@[to_additive]`. end Zero section Add /-- `M →ₙ+ N` is the type of functions `M → N` that preserve addition. The `ₙ` in the notation stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and `NonUnitalRingHom`, so a `AddHom` is a non-unital additive monoid hom. When possible, instead of parametrizing results over `(f : AddHom M N)`, you should parametrize over `(F : Type*) [AddHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `AddHomClass`. -/ structure AddHom (M : Type*) (N : Type*) [Add M] [Add N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves addition -/ protected map_add' : ∀ x y, toFun (x + y) = toFun x + toFun y /-- `M →ₙ+ N` denotes the type of addition-preserving maps from `M` to `N`. -/ infixr:25 " →ₙ+ " => AddHom /-- `AddHomClass F M N` states that `F` is a type of addition-preserving homomorphisms. You should declare an instance of this typeclass when you extend `AddHom`. -/ class AddHomClass (F : Type*) (M N : outParam Type*) [Add M] [Add N] [FunLike F M N] : Prop where /-- The proposition that the function preserves addition -/ map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y -- Instances and lemmas are defined below through `@[to_additive]`. end Add section add_zero /-- `M →+ N` is the type of functions `M → N` that preserve the `AddZeroClass` structure. `AddMonoidHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →+ N)`, you should parametrize over `(F : Type*) [AddMonoidHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `AddMonoidHomClass`. -/ structure AddMonoidHom (M : Type*) (N : Type*) [AddZeroClass M] [AddZeroClass N] extends ZeroHom M N, AddHom M N attribute [nolint docBlame] AddMonoidHom.toAddHom attribute [nolint docBlame] AddMonoidHom.toZeroHom /-- `M →+ N` denotes the type of additive monoid homomorphisms from `M` to `N`. -/ infixr:25 " →+ " => AddMonoidHom /-- `AddMonoidHomClass F M N` states that `F` is a type of `AddZeroClass`-preserving homomorphisms. You should also extend this typeclass when you extend `AddMonoidHom`. -/ class AddMonoidHomClass (F : Type*) (M N : outParam Type*) [AddZeroClass M] [AddZeroClass N] [FunLike F M N] : Prop extends AddHomClass F M N, ZeroHomClass F M N -- Instances and lemmas are defined below through `@[to_additive]`. end add_zero section One variable [One M] [One N] /-- `OneHom M N` is the type of functions `M → N` that preserve one. When possible, instead of parametrizing results over `(f : OneHom M N)`, you should parametrize over `(F : Type*) [OneHomClass F M N] (f : F)`. When you extend this structure, make sure to also extend `OneHomClass`. -/ @[to_additive] structure OneHom (M : Type*) (N : Type*) [One M] [One N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves 1 -/ protected map_one' : toFun 1 = 1 /-- `OneHomClass F M N` states that `F` is a type of one-preserving homomorphisms. You should extend this typeclass when you extend `OneHom`. -/ @[to_additive] class OneHomClass (F : Type*) (M N : outParam Type*) [One M] [One N] [FunLike F M N] : Prop where /-- The proposition that the function preserves 1 -/ map_one : ∀ f : F, f 1 = 1 @[to_additive] instance OneHom.funLike : FunLike (OneHom M N) M N where coe := OneHom.toFun coe_injective' f g h := by cases f; cases g; congr @[to_additive] instance OneHom.oneHomClass : OneHomClass (OneHom M N) M N where map_one := OneHom.map_one' library_note "hom simp lemma priority" /-- The hom class hierarchy allows for a single lemma, such as `map_one`, to apply to a large variety of morphism types, so long as they have an instance of `OneHomClass`. For example, this applies to to `MonoidHom`, `RingHom`, `AlgHom`, `StarAlgHom`, as well as their `Equiv` variants, etc. However, precisely because these lemmas are so widely applicable, they keys in the `simp` discrimination tree are necessarily highly non-specific. For example, the key for `map_one` is `@DFunLike.coe _ _ _ _ _ 1`. Consequently, whenever lean sees `⇑f 1`, for some `f : F`, it will attempt to synthesize a `OneHomClass F ?A ?B` instance. If no such instance exists, then Lean will need to traverse (almost) the entirety of the `FunLike` hierarchy in order to determine this because so many classes have a `OneHomClass` instance (in fact, this problem is likely worse for `ZeroHomClass`). This can lead to a significant performance hit when `map_one` fails to apply. To avoid this problem, we mark these widely applicable simp lemmas with key discimination tree keys with `mid` priority in order to ensure that they are not tried first. We do not use `low`, to allow bundled morphisms to unfold themselves with `low` priority such that the generic morphism lemmas are applied first. For instance, we might have ```lean def fooMonoidHom : M →* N where toFun := foo; map_one' := sorry; map_mul' := sorry @[simp low] lemma fooMonoidHom_apply (x : M) : fooMonoidHom x = foo x := rfl ``` As `map_mul` is tagged `simp mid`, this means that it still fires before `fooMonoidHom_apply`, which is the behavior we desire. -/ variable [FunLike F M N] /-- See note [hom simp lemma priority] -/ @[to_additive (attr := simp mid)] theorem map_one [OneHomClass F M N] (f : F) : f 1 = 1 := OneHomClass.map_one f @[to_additive] lemma map_comp_one [OneHomClass F M N] (f : F) : f ∘ (1 : ι → M) = 1 := by simp /-- In principle this could be an instance, but in practice it causes performance issues. -/ @[to_additive] theorem Subsingleton.of_oneHomClass [Subsingleton M] [OneHomClass F M N] : Subsingleton F where allEq f g := DFunLike.ext _ _ fun x ↦ by simp [Subsingleton.elim x 1] @[to_additive] instance [Subsingleton M] : Subsingleton (OneHom M N) := .of_oneHomClass @[to_additive] theorem map_eq_one_iff [OneHomClass F M N] (f : F) (hf : Function.Injective f) {x : M} : f x = 1 ↔ x = 1 := hf.eq_iff' (map_one f) @[to_additive] theorem map_ne_one_iff {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] (f : F) (hf : Function.Injective f) {x : R} : f x ≠ 1 ↔ x ≠ 1 := (map_eq_one_iff f hf).not @[to_additive] theorem ne_one_of_map {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] {f : F} {x : R} (hx : f x ≠ 1) : x ≠ 1 := ne_of_apply_ne f <| (by rwa [(map_one f)]) /-- Turn an element of a type `F` satisfying `OneHomClass F M N` into an actual `OneHom`. This is declared as the default coercion from `F` to `OneHom M N`. -/ @[to_additive (attr := coe) /-- Turn an element of a type `F` satisfying `ZeroHomClass F M N` into an actual `ZeroHom`. This is declared as the default coercion from `F` to `ZeroHom M N`. -/] def OneHomClass.toOneHom [OneHomClass F M N] (f : F) : OneHom M N where toFun := f map_one' := map_one f /-- Any type satisfying `OneHomClass` can be cast into `OneHom` via `OneHomClass.toOneHom`. -/ @[to_additive /-- Any type satisfying `ZeroHomClass` can be cast into `ZeroHom` via `ZeroHomClass.toZeroHom`. -/] instance [OneHomClass F M N] : CoeTC F (OneHom M N) := ⟨OneHomClass.toOneHom⟩ @[to_additive (attr := simp)] theorem OneHom.coe_coe [OneHomClass F M N] (f : F) : ((f : OneHom M N) : M → N) = f := rfl end One section Mul variable [Mul M] [Mul N] /-- `M →ₙ* N` is the type of functions `M → N` that preserve multiplication. The `ₙ` in the notation stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and `NonUnitalRingHom`, so a `MulHom` is a non-unital monoid hom. When possible, instead of parametrizing results over `(f : M →ₙ* N)`, you should parametrize over `(F : Type*) [MulHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `MulHomClass`. -/ @[to_additive] structure MulHom (M : Type*) (N : Type*) [Mul M] [Mul N] where /-- The underlying function -/ protected toFun : M → N /-- The proposition that the function preserves multiplication -/ protected map_mul' : ∀ x y, toFun (x * y) = toFun x * toFun y /-- `M →ₙ* N` denotes the type of multiplication-preserving maps from `M` to `N`. -/ infixr:25 " →ₙ* " => MulHom /-- `MulHomClass F M N` states that `F` is a type of multiplication-preserving homomorphisms. You should declare an instance of this typeclass when you extend `MulHom`. -/ @[to_additive] class MulHomClass (F : Type*) (M N : outParam Type*) [Mul M] [Mul N] [FunLike F M N] : Prop where /-- The proposition that the function preserves multiplication -/ map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y @[to_additive] instance MulHom.funLike : FunLike (M →ₙ* N) M N where coe := MulHom.toFun coe_injective' f g h := by cases f; cases g; congr /-- `MulHom` is a type of multiplication-preserving homomorphisms -/ @[to_additive /-- `AddHom` is a type of addition-preserving homomorphisms -/] instance MulHom.mulHomClass : MulHomClass (M →ₙ* N) M N where map_mul := MulHom.map_mul' variable [FunLike F M N] /-- See note [hom simp lemma priority] -/ @[to_additive (attr := simp mid)] theorem map_mul [MulHomClass F M N] (f : F) (x y : M) : f (x * y) = f x * f y := MulHomClass.map_mul f x y @[to_additive (attr := simp)] lemma map_comp_mul [MulHomClass F M N] (f : F) (g h : ι → M) : f ∘ (g * h) = f ∘ g * f ∘ h := by ext; simp /-- Turn an element of a type `F` satisfying `MulHomClass F M N` into an actual `MulHom`. This is declared as the default coercion from `F` to `M →ₙ* N`. -/ @[to_additive (attr := coe) /-- Turn an element of a type `F` satisfying `AddHomClass F M N` into an actual `AddHom`. This is declared as the default coercion from `F` to `M →ₙ+ N`. -/] def MulHomClass.toMulHom [MulHomClass F M N] (f : F) : M →ₙ* N where toFun := f map_mul' := map_mul f /-- Any type satisfying `MulHomClass` can be cast into `MulHom` via `MulHomClass.toMulHom`. -/ @[to_additive /-- Any type satisfying `AddHomClass` can be cast into `AddHom` via `AddHomClass.toAddHom`. -/] instance [MulHomClass F M N] : CoeTC F (M →ₙ* N) := ⟨MulHomClass.toMulHom⟩ @[to_additive (attr := simp)] theorem MulHom.coe_coe [MulHomClass F M N] (f : F) : ((f : MulHom M N) : M → N) = f := rfl end Mul section mul_one variable [MulOneClass M] [MulOneClass N] /-- `M →* N` is the type of functions `M → N` that preserve the `Monoid` structure. `MonoidHom` is also used for group homomorphisms. When possible, instead of parametrizing results over `(f : M →* N)`, you should parametrize over `(F : Type*) [MonoidHomClass F M N] (f : F)`. When you extend this structure, make sure to extend `MonoidHomClass`. -/ @[to_additive] structure MonoidHom (M : Type*) (N : Type*) [MulOneClass M] [MulOneClass N] extends OneHom M N, M →ₙ* N attribute [nolint docBlame] MonoidHom.toMulHom attribute [nolint docBlame] MonoidHom.toOneHom /-- `M →* N` denotes the type of monoid homomorphisms from `M` to `N`. -/ infixr:25 " →* " => MonoidHom /-- `MonoidHomClass F M N` states that `F` is a type of `Monoid`-preserving homomorphisms. You should also extend this typeclass when you extend `MonoidHom`. -/ @[to_additive] class MonoidHomClass (F : Type*) (M N : outParam Type*) [MulOneClass M] [MulOneClass N] [FunLike F M N] : Prop extends MulHomClass F M N, OneHomClass F M N @[to_additive] instance MonoidHom.instFunLike : FunLike (M →* N) M N where coe f := f.toFun coe_injective' f g h := by cases f cases g congr apply DFunLike.coe_injective' exact h @[to_additive] instance MonoidHom.instMonoidHomClass : MonoidHomClass (M →* N) M N where map_mul := MonoidHom.map_mul' map_one f := f.toOneHom.map_one' @[to_additive] instance [Subsingleton M] : Subsingleton (M →* N) := .of_oneHomClass variable [FunLike F M N] /-- Turn an element of a type `F` satisfying `MonoidHomClass F M N` into an actual `MonoidHom`. This is declared as the default coercion from `F` to `M →* N`. -/ @[to_additive (attr := coe) /-- Turn an element of a type `F` satisfying `AddMonoidHomClass F M N` into an actual `MonoidHom`. This is declared as the default coercion from `F` to `M →+ N`. -/] def MonoidHomClass.toMonoidHom [MonoidHomClass F M N] (f : F) : M →* N := { (f : M →ₙ* N), (f : OneHom M N) with } /-- Any type satisfying `MonoidHomClass` can be cast into `MonoidHom` via `MonoidHomClass.toMonoidHom`. -/ @[to_additive /-- Any type satisfying `AddMonoidHomClass` can be cast into `AddMonoidHom` via `AddMonoidHomClass.toAddMonoidHom`. -/] instance [MonoidHomClass F M N] : CoeTC F (M →* N) := ⟨MonoidHomClass.toMonoidHom⟩ @[to_additive (attr := simp)] theorem MonoidHom.coe_coe [MonoidHomClass F M N] (f : F) : ((f : M →* N) : M → N) = f := rfl @[to_additive] theorem map_mul_eq_one [MonoidHomClass F M N] (f : F) {a b : M} (h : a * b = 1) : f a * f b = 1 := by rw [← map_mul, h, map_one] variable [FunLike F G H] @[to_additive] theorem map_div' [DivInvMonoid G] [DivInvMonoid H] [MulHomClass F G H] (f : F) (hf : ∀ a, f a⁻¹ = (f a)⁻¹) (a b : G) : f (a / b) = f a / f b := by rw [div_eq_mul_inv, div_eq_mul_inv, map_mul, hf] @[to_additive] lemma map_comp_div' [DivInvMonoid G] [DivInvMonoid H] [MulHomClass F G H] (f : F) (hf : ∀ a, f a⁻¹ = (f a)⁻¹) (g h : ι → G) : f ∘ (g / h) = f ∘ g / f ∘ h := by ext; simp [map_div' f hf] /-- Group homomorphisms preserve inverse. See note [hom simp lemma priority] -/ @[to_additive (attr := simp mid) /-- Additive group homomorphisms preserve negation. -/] theorem map_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (a : G) : f a⁻¹ = (f a)⁻¹ := eq_inv_of_mul_eq_one_left <| map_mul_eq_one f <| inv_mul_cancel _ @[to_additive (attr := simp)] lemma map_comp_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) : f ∘ g⁻¹ = (f ∘ g)⁻¹ := by ext; simp /-- Group homomorphisms preserve division. -/ @[to_additive /-- Additive group homomorphisms preserve subtraction. -/] theorem map_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (a b : G) : f (a * b⁻¹) = f a * (f b)⁻¹ := by rw [map_mul, map_inv] @[to_additive] lemma map_comp_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) : f ∘ (g * h⁻¹) = f ∘ g * (f ∘ h)⁻¹ := by simp /-- Group homomorphisms preserve division. See note [hom simp lemma priority] -/ @[to_additive (attr := simp mid) /-- Additive group homomorphisms preserve subtraction. -/] theorem map_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) : ∀ a b, f (a / b) = f a / f b := map_div' _ <| map_inv f @[to_additive (attr := simp)] lemma map_comp_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) : f ∘ (g / h) = f ∘ g / f ∘ h := by ext; simp /-- See note [hom simp lemma priority] -/ @[to_additive (attr := simp mid) (reorder := 9 10)] theorem map_pow [Monoid G] [Monoid H] [MonoidHomClass F G H] (f : F) (a : G) : ∀ n : ℕ, f (a ^ n) = f a ^ n | 0 => by rw [pow_zero, pow_zero, map_one] | n + 1 => by rw [pow_succ, pow_succ, map_mul, map_pow f a n] @[to_additive (attr := simp)] lemma map_comp_pow [Monoid G] [Monoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) (n : ℕ) : f ∘ (g ^ n) = f ∘ g ^ n := by ext; simp @[to_additive] theorem map_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F) (hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (a : G) : ∀ n : ℤ, f (a ^ n) = f a ^ n | (n : ℕ) => by rw [zpow_natCast, map_pow, zpow_natCast] | Int.negSucc n => by rw [zpow_negSucc, hf, map_pow, ← zpow_negSucc] @[to_additive (attr := simp)] lemma map_comp_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F) (hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (g : ι → G) (n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by ext; simp [map_zpow' f hf] /-- Group homomorphisms preserve integer power. See note [hom simp lemma priority] -/ @[to_additive (attr := simp mid) (reorder := 9 10) /-- Additive group homomorphisms preserve integer scaling. -/] theorem map_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : G) (n : ℤ) : f (g ^ n) = f g ^ n := map_zpow' f (map_inv f) g n @[to_additive] lemma map_comp_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) (n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by simp end mul_one -- completely uninteresting lemmas about coercion to function, that all homs need section Coes /-! Bundled morphisms can be down-cast to weaker bundlings -/ attribute [coe] MonoidHom.toOneHom attribute [coe] AddMonoidHom.toZeroHom /-- `MonoidHom` down-cast to a `OneHom`, forgetting the multiplicative property. -/ @[to_additive /-- `AddMonoidHom` down-cast to a `ZeroHom`, forgetting the additive property -/] instance MonoidHom.coeToOneHom [MulOneClass M] [MulOneClass N] : Coe (M →* N) (OneHom M N) := ⟨MonoidHom.toOneHom⟩ attribute [coe] MonoidHom.toMulHom attribute [coe] AddMonoidHom.toAddHom /-- `MonoidHom` down-cast to a `MulHom`, forgetting the 1-preserving property. -/ @[to_additive /-- `AddMonoidHom` down-cast to an `AddHom`, forgetting the 0-preserving property. -/] instance MonoidHom.coeToMulHom [MulOneClass M] [MulOneClass N] : Coe (M →* N) (M →ₙ* N) := ⟨MonoidHom.toMulHom⟩ -- these must come after the coe_toFun definitions initialize_simps_projections ZeroHom (toFun → apply) initialize_simps_projections AddHom (toFun → apply) initialize_simps_projections AddMonoidHom (toFun → apply) initialize_simps_projections OneHom (toFun → apply) initialize_simps_projections MulHom (toFun → apply) initialize_simps_projections MonoidHom (toFun → apply) @[to_additive (attr := simp)] theorem OneHom.coe_mk [One M] [One N] (f : M → N) (h1) : (OneHom.mk f h1 : M → N) = f := rfl @[to_additive (attr := simp)] theorem OneHom.toFun_eq_coe [One M] [One N] (f : OneHom M N) : f.toFun = f := rfl @[to_additive (attr := simp)] theorem MulHom.coe_mk [Mul M] [Mul N] (f : M → N) (hmul) : (MulHom.mk f hmul : M → N) = f := rfl @[to_additive (attr := simp)] theorem MulHom.toFun_eq_coe [Mul M] [Mul N] (f : M →ₙ* N) : f.toFun = f := rfl @[to_additive (attr := simp)] theorem MonoidHom.coe_mk [MulOneClass M] [MulOneClass N] (f hmul) : (MonoidHom.mk f hmul : M → N) = f := rfl @[to_additive (attr := simp)] theorem MonoidHom.toOneHom_coe [MulOneClass M] [MulOneClass N] (f : M →* N) : (f.toOneHom : M → N) = f := rfl @[to_additive (attr := simp)] theorem MonoidHom.toMulHom_coe [MulOneClass M] [MulOneClass N] (f : M →* N) : f.toMulHom.toFun = f := rfl @[to_additive] theorem MonoidHom.toFun_eq_coe [MulOneClass M] [MulOneClass N] (f : M →* N) : f.toFun = f := rfl @[to_additive (attr := ext)] theorem OneHom.ext [One M] [One N] ⦃f g : OneHom M N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h @[to_additive (attr := ext)] theorem MulHom.ext [Mul M] [Mul N] ⦃f g : M →ₙ* N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h @[to_additive (attr := ext)] theorem MonoidHom.ext [MulOneClass M] [MulOneClass N] ⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h namespace MonoidHom variable [Group G] variable [MulOneClass M] /-- Makes a group homomorphism from a proof that the map preserves multiplication. -/ @[to_additive (attr := simps -fullyApplied) /-- Makes an additive group homomorphism from a proof that the map preserves addition. -/] def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G where toFun := f map_mul' := map_mul map_one' := by rw [← mul_right_cancel_iff, ← map_mul _ 1, one_mul, one_mul] end MonoidHom @[to_additive (attr := simp)] theorem OneHom.mk_coe [One M] [One N] (f : OneHom M N) (h1) : OneHom.mk f h1 = f := OneHom.ext fun _ => rfl @[to_additive (attr := simp)] theorem MulHom.mk_coe [Mul M] [Mul N] (f : M →ₙ* N) (hmul) : MulHom.mk f hmul = f := MulHom.ext fun _ => rfl @[to_additive (attr := simp)] theorem MonoidHom.mk_coe [MulOneClass M] [MulOneClass N] (f : M →* N) (hmul) : MonoidHom.mk f hmul = f := MonoidHom.ext fun _ => rfl end Coes /-- Copy of a `OneHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive /-- Copy of a `ZeroHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/] protected def OneHom.copy [One M] [One N] (f : OneHom M N) (f' : M → N) (h : f' = f) : OneHom M N where toFun := f' map_one' := h.symm ▸ f.map_one' @[to_additive (attr := simp)] theorem OneHom.coe_copy {_ : One M} {_ : One N} (f : OneHom M N) (f' : M → N) (h : f' = f) : (f.copy f' h) = f' := rfl @[to_additive] theorem OneHom.coe_copy_eq {_ : One M} {_ : One N} (f : OneHom M N) (f' : M → N) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h /-- Copy of a `MulHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive /-- Copy of an `AddHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/] protected def MulHom.copy [Mul M] [Mul N] (f : M →ₙ* N) (f' : M → N) (h : f' = f) : M →ₙ* N where toFun := f' map_mul' := h.symm ▸ f.map_mul' @[to_additive (attr := simp)] theorem MulHom.coe_copy {_ : Mul M} {_ : Mul N} (f : M →ₙ* N) (f' : M → N) (h : f' = f) : (f.copy f' h) = f' := rfl @[to_additive] theorem MulHom.coe_copy_eq {_ : Mul M} {_ : Mul N} (f : M →ₙ* N) (f' : M → N) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h /-- Copy of a `MonoidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive /-- Copy of an `AddMonoidHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/] protected def MonoidHom.copy [MulOneClass M] [MulOneClass N] (f : M →* N) (f' : M → N) (h : f' = f) : M →* N := { f.toOneHom.copy f' h, f.toMulHom.copy f' h with } @[to_additive (attr := simp)] theorem MonoidHom.coe_copy {_ : MulOneClass M} {_ : MulOneClass N} (f : M →* N) (f' : M → N) (h : f' = f) : (f.copy f' h) = f' := rfl @[to_additive] theorem MonoidHom.copy_eq {_ : MulOneClass M} {_ : MulOneClass N} (f : M →* N) (f' : M → N) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[to_additive] protected theorem OneHom.map_one [One M] [One N] (f : OneHom M N) : f 1 = 1 := f.map_one' /-- If `f` is a monoid homomorphism then `f 1 = 1`. -/ @[to_additive /-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/] protected theorem MonoidHom.map_one [MulOneClass M] [MulOneClass N] (f : M →* N) : f 1 = 1 := f.map_one' @[to_additive] protected theorem MulHom.map_mul [Mul M] [Mul N] (f : M →ₙ* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b /-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/ @[to_additive /-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/] protected theorem MonoidHom.map_mul [MulOneClass M] [MulOneClass N] (f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b namespace MonoidHom variable [MulOneClass M] [MulOneClass N] [FunLike F M N] [MonoidHomClass F M N] /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too. For elements invertible on both sides see `IsUnit.map`. -/ @[to_additive /-- Given an AddMonoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too. -/] theorem map_exists_right_inv (f : F) {x : M} (hx : ∃ y, x * y = 1) : ∃ y, f x * y = 1 := let ⟨y, hy⟩ := hx ⟨f y, map_mul_eq_one f hy⟩ /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `IsUnit.map`. -/ @[to_additive /-- Given an AddMonoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `IsAddUnit.map`. -/] theorem map_exists_left_inv (f : F) {x : M} (hx : ∃ y, y * x = 1) : ∃ y, y * f x = 1 := let ⟨y, hy⟩ := hx ⟨f y, map_mul_eq_one f hy⟩ end MonoidHom /-- The identity map from a type with 1 to itself. -/ @[to_additive (attr := simps) /-- The identity map from a type with zero to itself. -/] def OneHom.id (M : Type*) [One M] : OneHom M M where toFun x := x map_one' := rfl /-- The identity map from a type with multiplication to itself. -/ @[to_additive (attr := simps) /-- The identity map from a type with addition to itself. -/] def MulHom.id (M : Type*) [Mul M] : M →ₙ* M where toFun x := x map_mul' _ _ := rfl /-- The identity map from a monoid to itself. -/ @[to_additive (attr := simps) /-- The identity map from an additive monoid to itself. -/] def MonoidHom.id (M : Type*) [MulOneClass M] : M →* M where toFun x := x map_one' := rfl map_mul' _ _ := rfl @[to_additive (attr := simp)] lemma OneHom.coe_id {M : Type*} [One M] : (OneHom.id M : M → M) = _root_.id := rfl @[to_additive (attr := simp)] lemma MulHom.coe_id {M : Type*} [Mul M] : (MulHom.id M : M → M) = _root_.id := rfl @[to_additive (attr := simp)] lemma MonoidHom.coe_id {M : Type*} [MulOneClass M] : (MonoidHom.id M : M → M) = _root_.id := rfl /-- Composition of `OneHom`s as a `OneHom`. -/ @[to_additive /-- Composition of `ZeroHom`s as a `ZeroHom`. -/] def OneHom.comp [One M] [One N] [One P] (hnp : OneHom N P) (hmn : OneHom M N) : OneHom M P where toFun := hnp ∘ hmn map_one' := by simp /-- Composition of `MulHom`s as a `MulHom`. -/ @[to_additive /-- Composition of `AddHom`s as an `AddHom`. -/] def MulHom.comp [Mul M] [Mul N] [Mul P] (hnp : N →ₙ* P) (hmn : M →ₙ* N) : M →ₙ* P where toFun := hnp ∘ hmn map_mul' x y := by simp /-- Composition of monoid morphisms as a monoid morphism. -/ @[to_additive /-- Composition of additive monoid morphisms as an additive monoid morphism. -/] def MonoidHom.comp [MulOneClass M] [MulOneClass N] [MulOneClass P] (hnp : N →* P) (hmn : M →* N) : M →* P where toFun := hnp ∘ hmn map_one' := by simp map_mul' := by simp @[to_additive (attr := simp)] theorem OneHom.coe_comp [One M] [One N] [One P] (g : OneHom N P) (f : OneHom M N) : ↑(g.comp f) = g ∘ f := rfl @[to_additive (attr := simp)] theorem MulHom.coe_comp [Mul M] [Mul N] [Mul P] (g : N →ₙ* P) (f : M →ₙ* N) : ↑(g.comp f) = g ∘ f := rfl @[to_additive (attr := simp)] theorem MonoidHom.coe_comp [MulOneClass M] [MulOneClass N] [MulOneClass P] (g : N →* P) (f : M →* N) : ↑(g.comp f) = g ∘ f := rfl @[to_additive] theorem OneHom.comp_apply [One M] [One N] [One P] (g : OneHom N P) (f : OneHom M N) (x : M) : g.comp f x = g (f x) := rfl @[to_additive] theorem MulHom.comp_apply [Mul M] [Mul N] [Mul P] (g : N →ₙ* P) (f : M →ₙ* N) (x : M) : g.comp f x = g (f x) := rfl @[to_additive] theorem MonoidHom.comp_apply [MulOneClass M] [MulOneClass N] [MulOneClass P] (g : N →* P) (f : M →* N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of monoid homomorphisms is associative. -/ @[to_additive /-- Composition of additive monoid homomorphisms is associative. -/] theorem OneHom.comp_assoc {Q : Type*} [One M] [One N] [One P] [One Q] (f : OneHom M N) (g : OneHom N P) (h : OneHom P Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] theorem MulHom.comp_assoc {Q : Type*} [Mul M] [Mul N] [Mul P] [Mul Q] (f : M →ₙ* N) (g : N →ₙ* P) (h : P →ₙ* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] theorem MonoidHom.comp_assoc {Q : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass P] [MulOneClass Q] (f : M →* N) (g : N →* P) (h : P →* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] theorem OneHom.cancel_right [One M] [One N] [One P] {g₁ g₂ : OneHom N P} {f : OneHom M N} (hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => OneHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩ @[to_additive] theorem MulHom.cancel_right [Mul M] [Mul N] [Mul P] {g₁ g₂ : N →ₙ* P} {f : M →ₙ* N} (hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => MulHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩ @[to_additive] theorem MonoidHom.cancel_right [MulOneClass M] [MulOneClass N] [MulOneClass P] {g₁ g₂ : N →* P} {f : M →* N} (hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => MonoidHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩ @[to_additive] theorem OneHom.cancel_left [One M] [One N] [One P] {g : OneHom N P} {f₁ f₂ : OneHom M N} (hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => OneHom.ext fun x => hg <| by rw [← OneHom.comp_apply, h, OneHom.comp_apply], fun h => h ▸ rfl⟩ @[to_additive] theorem MulHom.cancel_left [Mul M] [Mul N] [Mul P] {g : N →ₙ* P} {f₁ f₂ : M →ₙ* N} (hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => MulHom.ext fun x => hg <| by rw [← MulHom.comp_apply, h, MulHom.comp_apply], fun h => h ▸ rfl⟩ @[to_additive] theorem MonoidHom.cancel_left [MulOneClass M] [MulOneClass N] [MulOneClass P] {g : N →* P} {f₁ f₂ : M →* N} (hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => MonoidHom.ext fun x => hg <| by rw [← MonoidHom.comp_apply, h, MonoidHom.comp_apply], fun h => h ▸ rfl⟩ section @[to_additive] theorem MonoidHom.toOneHom_injective [MulOneClass M] [MulOneClass N] : Function.Injective (MonoidHom.toOneHom : (M →* N) → OneHom M N) := Function.Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective @[to_additive] theorem MonoidHom.toMulHom_injective [MulOneClass M] [MulOneClass N] : Function.Injective (MonoidHom.toMulHom : (M →* N) → M →ₙ* N) := Function.Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective end @[to_additive (attr := simp)] theorem OneHom.comp_id [One M] [One N] (f : OneHom M N) : f.comp (OneHom.id M) = f := OneHom.ext fun _ => rfl @[to_additive (attr := simp)] theorem MulHom.comp_id [Mul M] [Mul N] (f : M →ₙ* N) : f.comp (MulHom.id M) = f := MulHom.ext fun _ => rfl @[to_additive (attr := simp)] theorem MonoidHom.comp_id [MulOneClass M] [MulOneClass N] (f : M →* N) : f.comp (MonoidHom.id M) = f := MonoidHom.ext fun _ => rfl @[to_additive (attr := simp)] theorem OneHom.id_comp [One M] [One N] (f : OneHom M N) : (OneHom.id N).comp f = f := OneHom.ext fun _ => rfl @[to_additive (attr := simp)] theorem MulHom.id_comp [Mul M] [Mul N] (f : M →ₙ* N) : (MulHom.id N).comp f = f := MulHom.ext fun _ => rfl @[to_additive (attr := simp)] theorem MonoidHom.id_comp [MulOneClass M] [MulOneClass N] (f : M →* N) : (MonoidHom.id N).comp f = f := MonoidHom.ext fun _ => rfl @[to_additive] protected theorem MonoidHom.map_pow [Monoid M] [Monoid N] (f : M →* N) (a : M) (n : ℕ) : f (a ^ n) = f a ^ n := map_pow f a n @[to_additive] protected theorem MonoidHom.map_zpow' [DivInvMonoid M] [DivInvMonoid N] (f : M →* N) (hf : ∀ x, f x⁻¹ = (f x)⁻¹) (a : M) (n : ℤ) : f (a ^ n) = f a ^ n := map_zpow' f hf a n /-- Makes a `OneHom` inverse from the bijective inverse of a `OneHom` -/ @[to_additive (attr := simps) /-- Make a `ZeroHom` inverse from the bijective inverse of a `ZeroHom` -/] def OneHom.inverse [One M] [One N] (f : OneHom M N) (g : N → M) (h₁ : Function.LeftInverse g f) : OneHom N M := { toFun := g, map_one' := by rw [← f.map_one, h₁] } /-- Makes a multiplicative inverse from a bijection which preserves multiplication. -/ @[to_additive (attr := simps) /-- Makes an additive inverse from a bijection which preserves addition. -/] def MulHom.inverse [Mul M] [Mul N] (f : M →ₙ* N) (g : N → M) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : N →ₙ* M where toFun := g map_mul' x y := calc g (x * y) = g (f (g x) * f (g y)) := by rw [h₂ x, h₂ y] _ = g (f (g x * g y)) := by rw [f.map_mul] _ = g x * g y := h₁ _ /-- If `M` and `N` have multiplications, `f : M →ₙ* N` is a surjective multiplicative map, and `M` is commutative, then `N` is commutative. -/ @[to_additive /-- If `M` and `N` have additions, `f : M →ₙ+ N` is a surjective additive map, and `M` is commutative, then `N` is commutative. -/] theorem Function.Surjective.mul_comm [Mul M] [Mul N] {f : M →ₙ* N} (is_surj : Function.Surjective f) (is_comm : Std.Commutative (· * · : M → M → M)) : Std.Commutative (· * · : N → N → N) where comm := fun a b ↦ by obtain ⟨a', ha'⟩ := is_surj a obtain ⟨b', hb'⟩ := is_surj b simp only [← ha', ← hb', ← map_mul] rw [is_comm.comm] /-- The inverse of a bijective `MonoidHom` is a `MonoidHom`. -/ @[to_additive (attr := simps) /-- The inverse of a bijective `AddMonoidHom` is an `AddMonoidHom`. -/] def MonoidHom.inverse {A B : Type*} [Monoid A] [Monoid B] (f : A →* B) (g : B → A) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : B →* A := { (f : OneHom A B).inverse g h₁, (f : A →ₙ* B).inverse g h₁ h₂ with toFun := g } section End namespace Monoid variable (M) [MulOneClass M] /-- The monoid of endomorphisms. -/ @[to_additive /-- The monoid of endomorphisms. -/, to_additive_dont_translate] protected def End := M →* M namespace End @[to_additive] instance instFunLike : FunLike (Monoid.End M) M M := MonoidHom.instFunLike @[to_additive] instance instMonoidHomClass : MonoidHomClass (Monoid.End M) M M := MonoidHom.instMonoidHomClass @[to_additive instOne] instance instOne : One (Monoid.End M) where one := .id _ @[to_additive instMul] instance instMul : Mul (Monoid.End M) where mul := .comp @[to_additive instMonoid] instance instMonoid : Monoid (Monoid.End M) where mul := MonoidHom.comp one := MonoidHom.id M mul_assoc _ _ _ := MonoidHom.comp_assoc _ _ _ mul_one := MonoidHom.comp_id one_mul := MonoidHom.id_comp npow n f := (npowRec n f).copy f^[n] <| by induction n <;> simp [npowRec, *] <;> rfl npow_succ _ _ := DFunLike.coe_injective <| Function.iterate_succ _ _ @[to_additive] instance : Inhabited (Monoid.End M) := ⟨1⟩ @[to_additive (attr := simp, norm_cast) coe_pow] lemma coe_pow (f : Monoid.End M) (n : ℕ) : (↑(f ^ n) : M → M) = f^[n] := rfl @[to_additive (attr := simp) coe_one] theorem coe_one : ((1 : Monoid.End M) : M → M) = id := rfl @[to_additive (attr := simp) coe_mul] theorem coe_mul (f g) : ((f * g : Monoid.End M) : M → M) = f ∘ g := rfl end End end Monoid end End /-- `1` is the homomorphism sending all elements to `1`. -/ @[to_additive /-- `0` is the homomorphism sending all elements to `0`. -/] instance [One M] [One N] : One (OneHom M N) := ⟨⟨fun _ => 1, rfl⟩⟩ /-- `1` is the multiplicative homomorphism sending all elements to `1`. -/ @[to_additive /-- `0` is the additive homomorphism sending all elements to `0` -/] instance [Mul M] [MulOneClass N] : One (M →ₙ* N) := ⟨⟨fun _ => 1, fun _ _ => (one_mul 1).symm⟩⟩ /-- `1` is the monoid homomorphism sending all elements to `1`. -/ @[to_additive /-- `0` is the additive monoid homomorphism sending all elements to `0`. -/] instance [MulOneClass M] [MulOneClass N] : One (M →* N) := ⟨⟨⟨fun _ => 1, rfl⟩, fun _ _ => (one_mul 1).symm⟩⟩ @[to_additive (attr := simp)] theorem OneHom.one_apply [One M] [One N] (x : M) : (1 : OneHom M N) x = 1 := rfl @[to_additive (attr := simp)] theorem MonoidHom.one_apply [MulOneClass M] [MulOneClass N] (x : M) : (1 : M →* N) x = 1 := rfl @[to_additive (attr := simp)] theorem OneHom.one_comp [One M] [One N] [One P] (f : OneHom M N) : (1 : OneHom N P).comp f = 1 := rfl @[to_additive (attr := simp)] theorem OneHom.comp_one [One M] [One N] [One P] (f : OneHom N P) : f.comp (1 : OneHom M N) = 1 := by ext simp only [OneHom.map_one, OneHom.coe_comp, Function.comp_apply, OneHom.one_apply] @[to_additive] instance [One M] [One N] : Inhabited (OneHom M N) := ⟨1⟩ @[to_additive] instance [Mul M] [MulOneClass N] : Inhabited (M →ₙ* N) := ⟨1⟩ @[to_additive] instance [MulOneClass M] [MulOneClass N] : Inhabited (M →* N) := ⟨1⟩ namespace MonoidHom @[to_additive (attr := simp)] theorem one_comp [MulOneClass M] [MulOneClass N] [MulOneClass P] (f : M →* N) : (1 : N →* P).comp f = 1 := rfl @[to_additive (attr := simp)] theorem comp_one [MulOneClass M] [MulOneClass N] [MulOneClass P] (f : N →* P) : f.comp (1 : M →* N) = 1 := by ext simp only [map_one, coe_comp, Function.comp_apply, one_apply] /-- Group homomorphisms preserve inverse. -/ @[to_additive /-- Additive group homomorphisms preserve negation. -/] protected theorem map_inv [Group α] [DivisionMonoid β] (f : α →* β) (a : α) : f a⁻¹ = (f a)⁻¹ := map_inv f _ /-- Group homomorphisms preserve integer power. -/ @[to_additive /-- Additive group homomorphisms preserve integer scaling. -/] protected theorem map_zpow [Group α] [DivisionMonoid β] (f : α →* β) (g : α) (n : ℤ) : f (g ^ n) = f g ^ n := map_zpow f g n /-- Group homomorphisms preserve division. -/ @[to_additive /-- Additive group homomorphisms preserve subtraction. -/] protected theorem map_div [Group α] [DivisionMonoid β] (f : α →* β) (g h : α) : f (g / h) = f g / f h := map_div f g h /-- Group homomorphisms preserve division. -/ @[to_additive /-- Additive group homomorphisms preserve subtraction. -/] protected theorem map_mul_inv [Group α] [DivisionMonoid β] (f : α →* β) (g h : α) : f (g * h⁻¹) = f g * (f h)⁻¹ := by simp end MonoidHom @[to_additive (attr := simp)] lemma iterate_map_mul {M F : Type*} [Mul M] [FunLike F M M] [MulHomClass F M M] (f : F) (n : ℕ) (x y : M) : f^[n] (x * y) = f^[n] x * f^[n] y := Function.Semiconj₂.iterate (map_mul f) n x y @[to_additive (attr := simp)] lemma iterate_map_one {M F : Type*} [One M] [FunLike F M M] [OneHomClass F M M] (f : F) (n : ℕ) : f^[n] 1 = 1 := iterate_fixed (map_one f) n @[to_additive (attr := simp)] lemma iterate_map_inv {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x : M) : f^[n] x⁻¹ = (f^[n] x)⁻¹ := Commute.iterate_left (map_inv f) n x @[to_additive (attr := simp)] lemma iterate_map_div {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x y : M) : f^[n] (x / y) = f^[n] x / f^[n] y := Semiconj₂.iterate (map_div f) n x y @[to_additive (attr := simp)] lemma iterate_map_pow {M F : Type*} [Monoid M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x : M) (k : ℕ) : f^[n] (x ^ k) = f^[n] x ^ k := Commute.iterate_left (map_pow f · k) n x @[to_additive (attr := simp)] lemma iterate_map_zpow {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M] (f : F) (n : ℕ) (x : M) (k : ℤ) : f^[n] (x ^ k) = f^[n] x ^ k := Commute.iterate_left (map_zpow f · k) n x
Defs.lean
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, William Sørensen, Robin Arnez -/ import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.MkIffOfInductiveProp import Mathlib.Tactic.PPWithUniv /-! # Small types A type is `w`-small if there exists an equivalence to some `S : Type w`. We provide a model `Shrink α : Type w`, and `equivShrink α : α ≃ Shrink α`. A subsingleton type is `w`-small for any `w`. If `α ≃ β`, then `Small.{w} α ↔ Small.{w} β`. See `Mathlib/Logic/Small/Basic.lean` for further instances and theorems. -/ universe u w v v' /-- A type is `Small.{w}` if there exists an equivalence to some `S : Type w`. -/ @[mk_iff, pp_with_univ] class Small (α : Type v) : Prop where /-- If a type is `Small.{w}`, then there exists an equivalence with some `S : Type w` -/ equiv_small : ∃ S : Type w, Nonempty (α ≃ S) /-- Constructor for `Small α` from an explicit witness type and equivalence. -/ theorem Small.mk' {α : Type v} {S : Type w} (e : α ≃ S) : Small.{w} α := ⟨⟨S, ⟨e⟩⟩⟩ /-- An arbitrarily chosen model in `Type w` for a `w`-small type. -/ @[pp_with_univ] def Shrink (α : Type v) [Small.{w} α] : Type w := Classical.choose (@Small.equiv_small α _) /-- A computable implementation of `equivShrink`. The `implemented_by` using this to implement `equivShrink` is safe because: * `Shrink α` has no memory layout in the compiler that needs to be conformed to. * There is no other computable way to construct or destructure an object of type `Shrink α`. * There is also no other computable way to modify the content of a shrink (as it always needs `Classical.choose_spec`). -/ @[inline] private unsafe def equivShrinkImpl (α : Type v) [Small.{u, v} α] : α ≃ Shrink.{u, v} α := ⟨unsafeCast, unsafeCast, lcProof, lcProof⟩ /-- The equivalence between a `w`-small type and a model. -/ @[implemented_by equivShrinkImpl] def equivShrink (α : Type v) [Small.{w} α] : α ≃ Shrink α := Nonempty.some (Classical.choose_spec (@Small.equiv_small α _)) @[ext] theorem Shrink.ext {α : Type v} [Small.{w} α] {x y : Shrink α} (w : (equivShrink _).symm x = (equivShrink _).symm y) : x = y := by simpa using w -- It would be nice to mark this as `aesop cases` if -- https://github.com/JLimperg/aesop/issues/59 -- is resolved. @[induction_eliminator] protected def Shrink.rec {α : Type*} [Small.{w} α] {F : Shrink α → Sort v} (h : ∀ X, F (equivShrink _ X)) : ∀ X, F X := fun X => ((equivShrink _).apply_symm_apply X) ▸ (h _) @[simp] lemma Shrink.rec_equivShrink {α : Type*} [Small.{w} α] {F : Shrink α → Sort v} {f : (a : α) → F (equivShrink α a)} (a : α) : Shrink.rec f (equivShrink _ a) = f a := by simp only [Shrink.rec, eqRec_eq_cast, cast_eq_iff_heq] rw [Equiv.symm_apply_apply] instance small_self (α : Type v) : Small.{v} α := Small.mk' <| Equiv.refl α theorem small_map {α : Type*} {β : Type*} [hβ : Small.{w} β] (e : α ≃ β) : Small.{w} α := let ⟨_, ⟨f⟩⟩ := hβ.equiv_small Small.mk' (e.trans f) theorem small_lift (α : Type u) [hα : Small.{v} α] : Small.{max v w} α := let ⟨⟨_, ⟨f⟩⟩⟩ := hα Small.mk' <| f.trans (Equiv.ulift.{w}).symm /-- Due to https://github.com/leanprover/lean4/issues/2297, this is useless as an instance. See however `Logic.UnivLE`, whose API is able to indirectly provide this instance. -/ lemma small_max (α : Type v) : Small.{max w v} α := small_lift.{v, w} α instance small_zero (α : Type) : Small.{w} α := small_max α instance (priority := 100) small_succ (α : Type v) : Small.{v+1} α := small_lift.{v, v+1} α instance small_ulift (α : Type u) [Small.{v} α] : Small.{v} (ULift.{w} α) := small_map Equiv.ulift instance small_plift (α : Type u) [Small.{v} α] : Small.{v} (PLift α) := small_map Equiv.plift theorem small_type : Small.{max (u + 1) v} (Type u) := small_max.{max (u + 1) v} _ instance {α : Type u} [Small.{v} α] [Nontrivial α] : Nontrivial (Shrink.{v} α) := (equivShrink α).symm.nontrivial section theorem small_congr {α : Type*} {β : Type*} (e : α ≃ β) : Small.{w} α ↔ Small.{w} β := ⟨fun h => @small_map _ _ h e.symm, fun h => @small_map _ _ h e⟩ instance small_sigma {α} (β : α → Type*) [Small.{w} α] [∀ a, Small.{w} (β a)] : Small.{w} (Σ a, β a) := ⟨⟨Σ a' : Shrink α, Shrink (β ((equivShrink α).symm a')), ⟨Equiv.sigmaCongr (equivShrink α) fun a => by simpa using equivShrink (β a)⟩⟩⟩ theorem not_small_type : ¬Small.{u} (Type max u v) | ⟨⟨S, ⟨e⟩⟩⟩ => @Function.cantor_injective (Σ α, e.symm α) (fun a => ⟨_, cast (e.3 _).symm a⟩) fun a b e => by dsimp at e injection e with h₁ h₂ simpa using h₂ end
Basic.lean
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Limits.Preserves.Limits /-! # (Co)limits in functor categories. We show that if `D` has limits, then the functor category `C ⥤ D` also has limits (`CategoryTheory.Limits.functorCategoryHasLimits`), and the evaluation functors preserve limits (`CategoryTheory.Limits.evaluation_preservesLimits`) (and similarly for colimits). We also show that `F : D ⥤ K ⥤ C` preserves (co)limits if it does so for each `k : K` (`CategoryTheory.Limits.preservesLimits_of_evaluation` and `CategoryTheory.Limits.preservesColimits_of_evaluation`). -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Functor -- morphism levels before object levels. See note [CategoryTheory universes]. universe w' w v₁ v₂ u₁ u₂ v v' u u' namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] @[reassoc (attr := simp)] theorem limit.lift_π_app (H : J ⥤ K ⥤ C) [HasLimit H] (c : Cone H) (j : J) (k : K) : (limit.lift H c).app k ≫ (limit.π H j).app k = (c.π.app j).app k := congr_app (limit.lift_π c j) k @[reassoc (attr := simp)] theorem colimit.ι_desc_app (H : J ⥤ K ⥤ C) [HasColimit H] (c : Cocone H) (j : J) (k : K) : (colimit.ι H j).app k ≫ (colimit.desc H c).app k = (c.ι.app j).app k := congr_app (colimit.ι_desc c j) k /-- The evaluation functors jointly reflect limits: that is, to show a cone is a limit of `F` it suffices to show that each evaluation cone is a limit. In other words, to prove a cone is limiting you can show it's pointwise limiting. -/ def evaluationJointlyReflectsLimits {F : J ⥤ K ⥤ C} (c : Cone F) (t : ∀ k : K, IsLimit (((evaluation K C).obj k).mapCone c)) : IsLimit c where lift s := { app := fun k => (t k).lift ⟨s.pt.obj k, whiskerRight s.π ((evaluation K C).obj k)⟩ naturality := fun X Y f => (t Y).hom_ext fun j => by rw [assoc, (t Y).fac _ j] simpa using ((t X).fac_assoc ⟨s.pt.obj X, whiskerRight s.π ((evaluation K C).obj X)⟩ j _).symm } fac s j := by ext k; exact (t k).fac _ j uniq s m w := by ext x exact (t x).hom_ext fun j => (congr_app (w j) x).trans ((t x).fac ⟨s.pt.obj _, whiskerRight s.π ((evaluation K C).obj _)⟩ j).symm /-- Given a functor `F` and a collection of limit cones for each diagram `X ↦ F X k`, we can stitch them together to give a cone for the diagram `F`. `combinedIsLimit` shows that the new cone is limiting, and `evalCombined` shows it is (essentially) made up of the original cones. -/ @[simps] def combineCones (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) : Cone F where pt := { obj := fun k => (c k).cone.pt map := fun {k₁} {k₂} f => (c k₂).isLimit.lift ⟨_, (c k₁).cone.π ≫ F.flip.map f⟩ map_id := fun k => (c k).isLimit.hom_ext fun j => by simp map_comp := fun {k₁} {k₂} {k₃} f₁ f₂ => (c k₃).isLimit.hom_ext fun j => by simp } π := { app := fun j => { app := fun k => (c k).cone.π.app j } naturality := fun j₁ j₂ g => by ext k; exact (c k).cone.π.naturality g } /-- The stitched together cones each project down to the original given cones (up to iso). -/ def evaluateCombinedCones (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) (k : K) : ((evaluation K C).obj k).mapCone (combineCones F c) ≅ (c k).cone := Cones.ext (Iso.refl _) /-- Stitching together limiting cones gives a limiting cone. -/ def combinedIsLimit (F : J ⥤ K ⥤ C) (c : ∀ k : K, LimitCone (F.flip.obj k)) : IsLimit (combineCones F c) := evaluationJointlyReflectsLimits _ fun k => (c k).isLimit.ofIsoLimit (evaluateCombinedCones F c k).symm /-- The evaluation functors jointly reflect colimits: that is, to show a cocone is a colimit of `F` it suffices to show that each evaluation cocone is a colimit. In other words, to prove a cocone is colimiting you can show it's pointwise colimiting. -/ def evaluationJointlyReflectsColimits {F : J ⥤ K ⥤ C} (c : Cocone F) (t : ∀ k : K, IsColimit (((evaluation K C).obj k).mapCocone c)) : IsColimit c where desc s := { app := fun k => (t k).desc ⟨s.pt.obj k, whiskerRight s.ι ((evaluation K C).obj k)⟩ naturality := fun X Y f => (t X).hom_ext fun j => by rw [(t X).fac_assoc _ j] erw [← (c.ι.app j).naturality_assoc f] erw [(t Y).fac ⟨s.pt.obj _, whiskerRight s.ι _⟩ j] simp } fac s j := by ext k; exact (t k).fac _ j uniq s m w := by ext x exact (t x).hom_ext fun j => (congr_app (w j) x).trans ((t x).fac ⟨s.pt.obj _, whiskerRight s.ι ((evaluation K C).obj _)⟩ j).symm /-- Given a functor `F` and a collection of colimit cocones for each diagram `X ↦ F X k`, we can stitch them together to give a cocone for the diagram `F`. `combinedIsColimit` shows that the new cocone is colimiting, and `evalCombined` shows it is (essentially) made up of the original cocones. -/ @[simps] def combineCocones (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) : Cocone F where pt := { obj := fun k => (c k).cocone.pt map := fun {k₁} {k₂} f => (c k₁).isColimit.desc ⟨_, F.flip.map f ≫ (c k₂).cocone.ι⟩ map_id := fun k => (c k).isColimit.hom_ext fun j => by simp map_comp := fun {k₁} {k₂} {k₃} f₁ f₂ => (c k₁).isColimit.hom_ext fun j => by simp } ι := { app := fun j => { app := fun k => (c k).cocone.ι.app j } naturality := fun j₁ j₂ g => by ext k; exact (c k).cocone.ι.naturality g } /-- The stitched together cocones each project down to the original given cocones (up to iso). -/ def evaluateCombinedCocones (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) (k : K) : ((evaluation K C).obj k).mapCocone (combineCocones F c) ≅ (c k).cocone := Cocones.ext (Iso.refl _) /-- Stitching together colimiting cocones gives a colimiting cocone. -/ def combinedIsColimit (F : J ⥤ K ⥤ C) (c : ∀ k : K, ColimitCocone (F.flip.obj k)) : IsColimit (combineCocones F c) := evaluationJointlyReflectsColimits _ fun k => (c k).isColimit.ofIsoColimit (evaluateCombinedCocones F c k).symm /-- An alternative colimit cocone in the functor category `K ⥤ C` in the case where `C` has `J`-shaped colimits, with cocone point `F.flip ⋙ colim`. -/ @[simps] noncomputable def pointwiseCocone [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) : Cocone F where pt := F.flip ⋙ colim ι := { app X := { app Y := (colimit.ι _ X : (F.flip.obj Y).obj X ⟶ _) } naturality X Y f := by ext x simp only [Functor.const_obj_obj, Functor.comp_obj, colim_obj, NatTrans.comp_app, Functor.const_obj_map, Category.comp_id] change (F.flip.obj x).map f ≫ _ = _ rw [colimit.w] } /-- `pointwiseCocone` is indeed a colimit cocone. -/ noncomputable def pointwiseIsColimit [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) : IsColimit (pointwiseCocone F) := by apply IsColimit.ofIsoColimit (combinedIsColimit _ (fun k ↦ ⟨colimit.cocone _, colimit.isColimit _⟩)) exact Cocones.ext (Iso.refl _) noncomputable section instance functorCategoryHasLimit (F : J ⥤ K ⥤ C) [∀ k, HasLimit (F.flip.obj k)] : HasLimit F := HasLimit.mk { cone := combineCones F fun _ => getLimitCone _ isLimit := combinedIsLimit _ _ } instance functorCategoryHasLimitsOfShape [HasLimitsOfShape J C] : HasLimitsOfShape J (K ⥤ C) where has_limit _ := inferInstance instance functorCategoryHasColimit (F : J ⥤ K ⥤ C) [∀ k, HasColimit (F.flip.obj k)] : HasColimit F := HasColimit.mk { cocone := combineCocones F fun _ => getColimitCocone _ isColimit := combinedIsColimit _ _ } instance functorCategoryHasColimitsOfShape [HasColimitsOfShape J C] : HasColimitsOfShape J (K ⥤ C) where has_colimit _ := inferInstance -- Porting note: previously Lean could see through the binders and infer_instance sufficed instance functorCategoryHasLimitsOfSize [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₁, u₁} (K ⥤ C) where has_limits_of_shape := fun _ _ => inferInstance -- Porting note: previously Lean could see through the binders and infer_instance sufficed instance functorCategoryHasColimitsOfSize [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfSize.{v₁, u₁} (K ⥤ C) where has_colimits_of_shape := fun _ _ => inferInstance instance hasLimitCompEvaluation (F : J ⥤ K ⥤ C) (k : K) [HasLimit (F.flip.obj k)] : HasLimit (F ⋙ (evaluation _ _).obj k) := hasLimit_of_iso (F := F.flip.obj k) (Iso.refl _) instance evaluation_preservesLimit (F : J ⥤ K ⥤ C) [∀ k, HasLimit (F.flip.obj k)] (k : K) : PreservesLimit F ((evaluation K C).obj k) := -- Porting note: added a let because X was not inferred let X : (k : K) → LimitCone (F.flip.obj k) := fun k => getLimitCone (F.flip.obj k) preservesLimit_of_preserves_limit_cone (combinedIsLimit _ X) <| IsLimit.ofIsoLimit (limit.isLimit _) (evaluateCombinedCones F X k).symm instance evaluation_preservesLimitsOfShape [HasLimitsOfShape J C] (k : K) : PreservesLimitsOfShape J ((evaluation K C).obj k) where preservesLimit := inferInstance /-- If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a limit, then the evaluation of that limit at `k` is the limit of the evaluations of `F.obj j` at `k`. -/ def limitObjIsoLimitCompEvaluation [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (k : K) : (limit F).obj k ≅ limit (F ⋙ (evaluation K C).obj k) := preservesLimitIso ((evaluation K C).obj k) F @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_hom_π [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (limitObjIsoLimitCompEvaluation F k).hom ≫ limit.π (F ⋙ (evaluation K C).obj k) j = (limit.π F j).app k := by dsimp [limitObjIsoLimitCompEvaluation] simp @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_inv_π_app [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (limitObjIsoLimitCompEvaluation F k).inv ≫ (limit.π F j).app k = limit.π (F ⋙ (evaluation K C).obj k) j := by dsimp [limitObjIsoLimitCompEvaluation] rw [Iso.inv_comp_eq] simp @[reassoc (attr := simp)] theorem limit_map_limitObjIsoLimitCompEvaluation_hom [HasLimitsOfShape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) : (limit F).map f ≫ (limitObjIsoLimitCompEvaluation _ _).hom = (limitObjIsoLimitCompEvaluation _ _).hom ≫ limMap (whiskerLeft _ ((evaluation _ _).map f)) := by ext simp @[reassoc (attr := simp)] theorem limitObjIsoLimitCompEvaluation_inv_limit_map [HasLimitsOfShape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) : (limitObjIsoLimitCompEvaluation _ _).inv ≫ (limit F).map f = limMap (whiskerLeft _ ((evaluation _ _).map f)) ≫ (limitObjIsoLimitCompEvaluation _ _).inv := by rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv, limit_map_limitObjIsoLimitCompEvaluation_hom] @[ext] theorem limit_obj_ext {H : J ⥤ K ⥤ C} [HasLimitsOfShape J C] {k : K} {W : C} {f g : W ⟶ (limit H).obj k} (w : ∀ j, f ≫ (Limits.limit.π H j).app k = g ≫ (Limits.limit.π H j).app k) : f = g := by apply (cancel_mono (limitObjIsoLimitCompEvaluation H k).hom).1 ext j simpa using w j /-- Taking a limit after whiskering by `G` is the same as using `G` and then taking a limit. -/ def limitCompWhiskeringLeftIsoCompLimit (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasLimitsOfShape J C] : limit (F ⋙ (whiskeringLeft _ _ _).obj G) ≅ G ⋙ limit F := NatIso.ofComponents (fun j => limitObjIsoLimitCompEvaluation (F ⋙ (whiskeringLeft _ _ _).obj G) j ≪≫ HasLimit.isoOfNatIso (isoWhiskerLeft F (whiskeringLeftCompEvaluation G j)) ≪≫ (limitObjIsoLimitCompEvaluation F (G.obj j)).symm) @[reassoc (attr := simp)] theorem limitCompWhiskeringLeftIsoCompLimit_hom_whiskerLeft_π (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasLimitsOfShape J C] (j : J) : (limitCompWhiskeringLeftIsoCompLimit F G).hom ≫ whiskerLeft G (limit.π F j) = limit.π (F ⋙ (whiskeringLeft _ _ _).obj G) j := by ext d simp [limitCompWhiskeringLeftIsoCompLimit] @[reassoc (attr := simp)] theorem limitCompWhiskeringLeftIsoCompLimit_inv_π (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasLimitsOfShape J C] (j : J) : (limitCompWhiskeringLeftIsoCompLimit F G).inv ≫ limit.π (F ⋙ (whiskeringLeft _ _ _).obj G) j = whiskerLeft G (limit.π F j) := by simp [Iso.inv_comp_eq] instance hasColimitCompEvaluation (F : J ⥤ K ⥤ C) (k : K) [HasColimit (F.flip.obj k)] : HasColimit (F ⋙ (evaluation _ _).obj k) := hasColimit_of_iso (F := F.flip.obj k) (Iso.refl _) instance evaluation_preservesColimit (F : J ⥤ K ⥤ C) [∀ k, HasColimit (F.flip.obj k)] (k : K) : PreservesColimit F ((evaluation K C).obj k) := -- Porting note: added a let because X was not inferred let X : (k : K) → ColimitCocone (F.flip.obj k) := fun k => getColimitCocone (F.flip.obj k) preservesColimit_of_preserves_colimit_cocone (combinedIsColimit _ X) <| IsColimit.ofIsoColimit (colimit.isColimit _) (evaluateCombinedCocones F X k).symm instance evaluation_preservesColimitsOfShape [HasColimitsOfShape J C] (k : K) : PreservesColimitsOfShape J ((evaluation K C).obj k) where preservesColimit := inferInstance /-- If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a colimit, then the evaluation of that colimit at `k` is the colimit of the evaluations of `F.obj j` at `k`. -/ def colimitObjIsoColimitCompEvaluation [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (k : K) : (colimit F).obj k ≅ colimit (F ⋙ (evaluation K C).obj k) := preservesColimitIso ((evaluation K C).obj k) F @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_ι_inv [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : colimit.ι (F ⋙ (evaluation K C).obj k) j ≫ (colimitObjIsoColimitCompEvaluation F k).inv = (colimit.ι F j).app k := by dsimp [colimitObjIsoColimitCompEvaluation] simp @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_ι_app_hom [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) (j : J) (k : K) : (colimit.ι F j).app k ≫ (colimitObjIsoColimitCompEvaluation F k).hom = colimit.ι (F ⋙ (evaluation K C).obj k) j := by dsimp [colimitObjIsoColimitCompEvaluation] rw [← Iso.eq_comp_inv] simp @[reassoc (attr := simp)] theorem colimitObjIsoColimitCompEvaluation_inv_colimit_map [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) : (colimitObjIsoColimitCompEvaluation _ _).inv ≫ (colimit F).map f = colimMap (whiskerLeft _ ((evaluation _ _).map f)) ≫ (colimitObjIsoColimitCompEvaluation _ _).inv := by ext simp @[reassoc (attr := simp)] theorem colimit_map_colimitObjIsoColimitCompEvaluation_hom [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) : (colimit F).map f ≫ (colimitObjIsoColimitCompEvaluation _ _).hom = (colimitObjIsoColimitCompEvaluation _ _).hom ≫ colimMap (whiskerLeft _ ((evaluation _ _).map f)) := by rw [← Iso.inv_comp_eq, ← Category.assoc, ← Iso.eq_comp_inv, colimitObjIsoColimitCompEvaluation_inv_colimit_map] @[ext] theorem colimit_obj_ext {H : J ⥤ K ⥤ C} [HasColimitsOfShape J C] {k : K} {W : C} {f g : (colimit H).obj k ⟶ W} (w : ∀ j, (colimit.ι H j).app k ≫ f = (colimit.ι H j).app k ≫ g) : f = g := by apply (cancel_epi (colimitObjIsoColimitCompEvaluation H k).inv).1 ext j simpa using w j /-- Taking a colimit after whiskering by `G` is the same as using `G` and then taking a colimit. -/ def colimitCompWhiskeringLeftIsoCompColimit (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasColimitsOfShape J C] : colimit (F ⋙ (whiskeringLeft _ _ _).obj G) ≅ G ⋙ colimit F := NatIso.ofComponents (fun j => colimitObjIsoColimitCompEvaluation (F ⋙ (whiskeringLeft _ _ _).obj G) j ≪≫ HasColimit.isoOfNatIso (isoWhiskerLeft F (whiskeringLeftCompEvaluation G j)) ≪≫ (colimitObjIsoColimitCompEvaluation F (G.obj j)).symm) @[reassoc (attr := simp)] theorem ι_colimitCompWhiskeringLeftIsoCompColimit_hom (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasColimitsOfShape J C] (j : J) : colimit.ι (F ⋙ (whiskeringLeft _ _ _).obj G) j ≫ (colimitCompWhiskeringLeftIsoCompColimit F G).hom = whiskerLeft G (colimit.ι F j) := by ext d simp [colimitCompWhiskeringLeftIsoCompColimit] @[reassoc (attr := simp)] theorem whiskerLeft_ι_colimitCompWhiskeringLeftIsoCompColimit_inv (F : J ⥤ K ⥤ C) (G : D ⥤ K) [HasColimitsOfShape J C] (j : J) : whiskerLeft G (colimit.ι F j) ≫ (colimitCompWhiskeringLeftIsoCompColimit F G).inv = colimit.ι (F ⋙ (whiskeringLeft _ _ _).obj G) j := by simp [Iso.comp_inv_eq] instance evaluationPreservesLimits [HasLimits C] (k : K) : PreservesLimits ((evaluation K C).obj k) where preservesLimitsOfShape {_} _𝒥 := inferInstance /-- `F : D ⥤ K ⥤ C` preserves the limit of some `G : J ⥤ D` if it does for each `k : K`. -/ lemma preservesLimit_of_evaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D) (H : ∀ k : K, PreservesLimit G (F ⋙ (evaluation K C).obj k : D ⥤ C)) : PreservesLimit G F := ⟨fun {c} hc => ⟨by apply evaluationJointlyReflectsLimits intro X haveI := H X change IsLimit ((F ⋙ (evaluation K C).obj X).mapCone c) exact isLimitOfPreserves _ hc⟩⟩ /-- `F : D ⥤ K ⥤ C` preserves limits of shape `J` if it does for each `k : K`. -/ lemma preservesLimitsOfShape_of_evaluation (F : D ⥤ K ⥤ C) (J : Type*) [Category J] (_ : ∀ k : K, PreservesLimitsOfShape J (F ⋙ (evaluation K C).obj k)) : PreservesLimitsOfShape J F := ⟨fun {G} => preservesLimit_of_evaluation F G fun _ => PreservesLimitsOfShape.preservesLimit⟩ /-- `F : D ⥤ K ⥤ C` preserves all limits if it does for each `k : K`. -/ lemma preservesLimits_of_evaluation (F : D ⥤ K ⥤ C) (_ : ∀ k : K, PreservesLimitsOfSize.{w', w} (F ⋙ (evaluation K C).obj k)) : PreservesLimitsOfSize.{w', w} F := ⟨fun {L} _ => preservesLimitsOfShape_of_evaluation F L fun _ => PreservesLimitsOfSize.preservesLimitsOfShape⟩ /-- The constant functor `C ⥤ (D ⥤ C)` preserves limits. -/ instance preservesLimits_const : PreservesLimitsOfSize.{w', w} (const D : C ⥤ _) := preservesLimits_of_evaluation _ fun _ => preservesLimits_of_natIso <| Iso.symm <| constCompEvaluationObj _ _ instance evaluation_preservesColimits [HasColimits C] (k : K) : PreservesColimits ((evaluation K C).obj k) where preservesColimitsOfShape := inferInstance /-- `F : D ⥤ K ⥤ C` preserves the colimit of some `G : J ⥤ D` if it does for each `k : K`. -/ lemma preservesColimit_of_evaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D) (H : ∀ k, PreservesColimit G (F ⋙ (evaluation K C).obj k)) : PreservesColimit G F := ⟨fun {c} hc => ⟨by apply evaluationJointlyReflectsColimits intro X haveI := H X change IsColimit ((F ⋙ (evaluation K C).obj X).mapCocone c) exact isColimitOfPreserves _ hc⟩⟩ /-- `F : D ⥤ K ⥤ C` preserves all colimits of shape `J` if it does for each `k : K`. -/ lemma preservesColimitsOfShape_of_evaluation (F : D ⥤ K ⥤ C) (J : Type*) [Category J] (_ : ∀ k : K, PreservesColimitsOfShape J (F ⋙ (evaluation K C).obj k)) : PreservesColimitsOfShape J F := ⟨fun {G} => preservesColimit_of_evaluation F G fun _ => PreservesColimitsOfShape.preservesColimit⟩ /-- `F : D ⥤ K ⥤ C` preserves all colimits if it does for each `k : K`. -/ lemma preservesColimits_of_evaluation (F : D ⥤ K ⥤ C) (_ : ∀ k : K, PreservesColimitsOfSize.{w', w} (F ⋙ (evaluation K C).obj k)) : PreservesColimitsOfSize.{w', w} F := ⟨fun {L} _ => preservesColimitsOfShape_of_evaluation F L fun _ => PreservesColimitsOfSize.preservesColimitsOfShape⟩ /-- The constant functor `C ⥤ (D ⥤ C)` preserves colimits. -/ instance preservesColimits_const : PreservesColimitsOfSize.{w', w} (const D : C ⥤ _) := preservesColimits_of_evaluation _ fun _ => preservesColimits_of_natIso <| Iso.symm <| constCompEvaluationObj _ _ open CategoryTheory.prod /-- The limit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by the individual limits on objects. -/ @[simps!] def limitIsoFlipCompLim [HasLimitsOfShape J C] (F : J ⥤ K ⥤ C) : limit F ≅ F.flip ⋙ lim := NatIso.ofComponents (limitObjIsoLimitCompEvaluation F) /-- A variant of `limitIsoFlipCompLim` where the arguments of `F` are flipped. -/ @[simps!] def limitFlipIsoCompLim [HasLimitsOfShape J C] (F : K ⥤ J ⥤ C) : limit F.flip ≅ F ⋙ lim := let f := fun k => limitObjIsoLimitCompEvaluation F.flip k ≪≫ HasLimit.isoOfNatIso (flipCompEvaluation _ _) NatIso.ofComponents f /-- For a functor `G : J ⥤ K ⥤ C`, its limit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ lim`. Note that this does not require `K` to be small. -/ @[simps!] def limitIsoSwapCompLim [HasLimitsOfShape J C] (G : J ⥤ K ⥤ C) : limit G ≅ curry.obj (Prod.swap K J ⋙ uncurry.obj G) ⋙ lim := limitIsoFlipCompLim G ≪≫ isoWhiskerRight (flipIsoCurrySwapUncurry _) _ /-- The colimit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by the individual colimits on objects. -/ @[simps!] def colimitIsoFlipCompColim [HasColimitsOfShape J C] (F : J ⥤ K ⥤ C) : colimit F ≅ F.flip ⋙ colim := NatIso.ofComponents (colimitObjIsoColimitCompEvaluation F) /-- A variant of `colimit_iso_flip_comp_colim` where the arguments of `F` are flipped. -/ @[simps!] def colimitFlipIsoCompColim [HasColimitsOfShape J C] (F : K ⥤ J ⥤ C) : colimit F.flip ≅ F ⋙ colim := let f := fun _ => colimitObjIsoColimitCompEvaluation _ _ ≪≫ HasColimit.isoOfNatIso (flipCompEvaluation _ _) NatIso.ofComponents f /-- For a functor `G : J ⥤ K ⥤ C`, its colimit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ colim`. Note that this does not require `K` to be small. -/ @[simps!] def colimitIsoSwapCompColim [HasColimitsOfShape J C] (G : J ⥤ K ⥤ C) : colimit G ≅ curry.obj (Prod.swap K J ⋙ uncurry.obj G) ⋙ colim := colimitIsoFlipCompColim G ≪≫ isoWhiskerRight (flipIsoCurrySwapUncurry _) _ end end Limits end CategoryTheory
Star.lean
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Mario Carneiro, Yury Kudryashov, Heather Macbeth -/ import Mathlib.Analysis.CStarAlgebra.Basic import Mathlib.Topology.ContinuousMap.Bounded.Normed import Mathlib.Topology.ContinuousMap.Star /-! # Star structures on bounded continuous functions -/ noncomputable section open Topology Bornology NNReal uniformity UniformConvergence RCLike BoundedContinuousFunction open Set Filter Metric Function universe u v w variable {F : Type*} {α : Type u} {β : Type v} {γ : Type w} namespace BoundedContinuousFunction /-! ### Star structures In this section, if `β` is a normed ⋆-group, then so is the space of bounded continuous functions from `α` to `β`, by using the star operation pointwise. If `𝕜` is normed field and a ⋆-ring over which `β` is a normed algebra and a star module, then the space of bounded continuous functions from `α` to `β` is a star module. If `β` is a ⋆-ring in addition to being a normed ⋆-group, then `α →ᵇ β` inherits a ⋆-ring structure. In summary, if `β` is a C⋆-algebra over `𝕜`, then so is `α →ᵇ β`; note that completeness is guaranteed when `β` is complete (see `BoundedContinuousFunction.complete`). -/ section NormedAddCommGroup variable {𝕜 : Type*} [NormedField 𝕜] [StarRing 𝕜] [TopologicalSpace α] [SeminormedAddCommGroup β] [StarAddMonoid β] [NormedStarGroup β] variable [NormedSpace 𝕜 β] [StarModule 𝕜 β] instance instStarAddMonoid : StarAddMonoid (α →ᵇ β) where star f := f.comp star starNormedAddGroupHom.lipschitz star_involutive f := ext fun x => star_star (f x) star_add f g := ext fun x => star_add (f x) (g x) /-- The right-hand side of this equality can be parsed `star ∘ ⇑f` because of the instance `Pi.instStarForAll`. Upon inspecting the goal, one sees `⊢ ↑(star f) = star ↑f`. -/ @[simp] theorem coe_star (f : α →ᵇ β) : ⇑(star f) = star (⇑f) := rfl @[simp] theorem star_apply (f : α →ᵇ β) (x : α) : star f x = star (f x) := rfl instance instNormedStarGroup : NormedStarGroup (α →ᵇ β) where norm_star_le f := by simp only [norm_eq, star_apply, norm_star, le_of_eq] instance instStarModule : StarModule 𝕜 (α →ᵇ β) where star_smul k f := ext fun x => star_smul k (f x) end NormedAddCommGroup section CStarRing variable [TopologicalSpace α] variable [NonUnitalNormedRing β] [StarRing β] instance instStarRing [NormedStarGroup β] : StarRing (α →ᵇ β) where __ := instStarAddMonoid star_mul f g := ext fun x ↦ star_mul (f x) (g x) variable [CStarRing β] instance instCStarRing : CStarRing (α →ᵇ β) where norm_mul_self_le f := by rw [← sq, ← Real.le_sqrt (norm_nonneg _) (norm_nonneg _), norm_le (Real.sqrt_nonneg _)] intro x rw [Real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ← CStarRing.norm_star_mul_self] exact norm_coe_le_norm (star f * f) x end CStarRing section NormedAlgebra variable (𝕜 : Type*) [NormedField 𝕜] [TopologicalSpace α] [NormedRing β] [NormedAlgebra 𝕜 β] [StarAddMonoid β] [NormedStarGroup β] /-- The ⋆-algebra-homomorphism forgetting that a bounded continuous function is bounded. -/ @[simps!] def toContinuousMapStarₐ : (α →ᵇ β) →⋆ₐ[𝕜] C(α, β) := { toContinuousMapₐ 𝕜 with map_star' _ := rfl } @[simp] theorem coe_toContinuousMapStarₐ (f : α →ᵇ β) : (f.toContinuousMapStarₐ 𝕜 : α → β) = f := rfl end NormedAlgebra end BoundedContinuousFunction
NoZeroDivisors.lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.RingTheory.PowerSeries.Order import Mathlib.RingTheory.Ideal.Maps /-! # Power series over rings with no zero divisors This file proves, using the properties of orders of power series, that `R⟦X⟧` is an integral domain when `R` is. We then state various results about `R⟦X⟧` with `R` an integral domain. ## Instance If `R` has `NoZeroDivisors`, then so does `R⟦X⟧`. -/ variable {R : Type*} namespace PowerSeries section NoZeroDivisors variable [Semiring R] instance [NoZeroDivisors R] : NoZeroDivisors R⟦X⟧ where eq_zero_or_eq_zero_of_mul_eq_zero {φ ψ} h := by simp_rw [← order_eq_top, order_mul] at h ⊢ exact WithTop.add_eq_top.mp h end NoZeroDivisors section IsDomain instance [Ring R] [IsDomain R] : IsDomain R⟦X⟧ := NoZeroDivisors.to_isDomain _ variable [CommRing R] [IsDomain R] /-- The ideal spanned by the variable in the power series ring over an integral domain is a prime ideal. -/ theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by rw [this] exact RingHom.ker_isPrime _ apply Ideal.ext intro φ rw [RingHom.mem_ker, Ideal.mem_span_singleton, X_dvd_iff] /-- The variable of the power series ring over an integral domain is prime. -/ theorem X_prime : Prime (X : R⟦X⟧) := by rw [← Ideal.span_singleton_prime] · exact span_X_isPrime · intro h simpa [map_zero (coeff R 1)] using congr_arg (coeff R 1) h /-- The variable of the power series ring over an integral domain is irreducible. -/ theorem X_irreducible : Irreducible (X : R⟦X⟧) := X_prime.irreducible theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by intro p q h rw [PowerSeries.ext_iff] at * intro n specialize h n rwa [coeff_rescale, coeff_rescale, mul_right_inj' <| pow_ne_zero _ ha] at h end IsDomain end PowerSeries
CircleIntegral.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.IsolatedZeros import Mathlib.Analysis.SpecialFunctions.Complex.CircleMap import Mathlib.Analysis.SpecialFunctions.NonIntegrable /-! # Integral over a circle in `ℂ` In this file we define `∮ z in C(c, R), f z` to be the integral $\oint_{|z-c|=|R|} f(z)\,dz$ and prove some properties of this integral. We give definition and prove most lemmas for a function `f : ℂ → E`, where `E` is a complex Banach space. For this reason, some lemmas use, e.g., `(z - c)⁻¹ • f z` instead of `f z / (z - c)`. ## Main definitions * `CircleIntegrable f c R`: a function `f : ℂ → E` is integrable on the circle with center `c` and radius `R` if `f ∘ circleMap c R` is integrable on `[0, 2π]`; * `circleIntegral f c R`: the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$; * `cauchyPowerSeries f c R`: the power series that is equal to $\sum_{n=0}^{\infty} \oint_{|z-c|=R} \left(\frac{w-c}{z - c}\right)^n \frac{1}{z-c}f(z)\,dz$ at `w - c`. The coefficients of this power series depend only on `f ∘ circleMap c R`, and the power series converges to `f w` if `f` is differentiable on the closed ball `Metric.closedBall c R` and `w` belongs to the corresponding open ball. ## Main statements * `hasFPowerSeriesOn_cauchy_integral`: for any circle integrable function `f`, the power series `cauchyPowerSeries f c R`, `R > 0`, converges to the Cauchy integral `(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`; * `circleIntegral.integral_sub_zpow_of_undef`, `circleIntegral.integral_sub_zpow_of_ne`, and `circleIntegral.integral_sub_inv_of_mem_ball`: formulas for `∮ z in C(c, R), (z - w) ^ n`, `n : ℤ`. These lemmas cover the following cases: - `circleIntegral.integral_sub_zpow_of_undef`, `n < 0` and `|w - c| = |R|`: in this case the function is not integrable, so the integral is equal to its default value (zero); - `circleIntegral.integral_sub_zpow_of_ne`, `n ≠ -1`: in the cases not covered by the previous lemma, we have `(z - w) ^ n = ((z - w) ^ (n + 1) / (n + 1))'`, thus the integral equals zero; - `circleIntegral.integral_sub_inv_of_mem_ball`, `n = -1`, `|w - c| < R`: in this case the integral is equal to `2πi`. The case `n = -1`, `|w -c| > R` is not covered by these lemmas. While it is possible to construct an explicit primitive, it is easier to apply Cauchy theorem, so we postpone the proof till we have this theorem (see https://github.com/leanprover-community/mathlib4/pull/10000). ## Notation - `∮ z in C(c, R), f z`: notation for the integral $\oint_{|z-c|=|R|} f(z)\,dz$, defined as $\int_{0}^{2π}(c + Re^{θ i})' f(c+Re^{θ i})\,dθ$. ## Tags integral, circle, Cauchy integral -/ variable {E : Type*} [NormedAddCommGroup E] noncomputable section open scoped Real NNReal Interval Pointwise Topology open Complex MeasureTheory TopologicalSpace Metric Function Set Filter Asymptotics /-! ### Facts about `circleMap` -/ /-- The range of `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem range_circleMap (c : ℂ) (R : ℝ) : range (circleMap c R) = sphere c |R| := calc range (circleMap c R) = c +ᵥ R • range fun θ : ℝ => exp (θ * I) := by simp +unfoldPartialApp only [← image_vadd, ← image_smul, ← range_comp, vadd_eq_add, circleMap, comp_def, real_smul] _ = sphere c |R| := by rw [range_exp_mul_I, smul_sphere R 0 zero_le_one] simp /-- The image of `(0, 2π]` under `circleMap c R` is the circle with center `c` and radius `|R|`. -/ @[simp] theorem image_circleMap_Ioc (c : ℂ) (R : ℝ) : circleMap c R '' Ioc 0 (2 * π) = sphere c |R| := by rw [← range_circleMap, ← (periodic_circleMap c R).image_Ioc Real.two_pi_pos 0, zero_add] theorem hasDerivAt_circleMap (c : ℂ) (R : ℝ) (θ : ℝ) : HasDerivAt (circleMap c R) (circleMap 0 R θ * I) θ := by simpa only [mul_assoc, one_mul, ofRealCLM_apply, circleMap, ofReal_one, zero_add] using (((ofRealCLM.hasDerivAt (x := θ)).mul_const I).cexp.const_mul (R : ℂ)).const_add c theorem differentiable_circleMap (c : ℂ) (R : ℝ) : Differentiable ℝ (circleMap c R) := fun θ => (hasDerivAt_circleMap c R θ).differentiableAt /-- The circleMap is real analytic. -/ theorem analyticOnNhd_circleMap (c : ℂ) (R : ℝ) : AnalyticOnNhd ℝ (circleMap c R) Set.univ := by intro z hz apply analyticAt_const.add apply analyticAt_const.mul rw [← Function.comp_def] apply analyticAt_cexp.restrictScalars.comp ((ofRealCLM.analyticAt z).mul (by fun_prop)) /-- The circleMap is continuously differentiable. -/ theorem contDiff_circleMap (c : ℂ) (R : ℝ) {n : WithTop ℕ∞} : ContDiff ℝ n (circleMap c R) := (analyticOnNhd_circleMap c R).contDiff @[continuity, fun_prop] theorem continuous_circleMap (c : ℂ) (R : ℝ) : Continuous (circleMap c R) := (differentiable_circleMap c R).continuous @[fun_prop, measurability] theorem measurable_circleMap (c : ℂ) (R : ℝ) : Measurable (circleMap c R) := (continuous_circleMap c R).measurable @[simp] theorem deriv_circleMap (c : ℂ) (R : ℝ) (θ : ℝ) : deriv (circleMap c R) θ = circleMap 0 R θ * I := (hasDerivAt_circleMap _ _ _).deriv theorem deriv_circleMap_eq_zero_iff {c : ℂ} {R : ℝ} {θ : ℝ} : deriv (circleMap c R) θ = 0 ↔ R = 0 := by simp [I_ne_zero] theorem deriv_circleMap_ne_zero {c : ℂ} {R : ℝ} {θ : ℝ} (hR : R ≠ 0) : deriv (circleMap c R) θ ≠ 0 := mt deriv_circleMap_eq_zero_iff.1 hR theorem lipschitzWith_circleMap (c : ℂ) (R : ℝ) : LipschitzWith (Real.nnabs R) (circleMap c R) := lipschitzWith_of_nnnorm_deriv_le (differentiable_circleMap _ _) fun θ => NNReal.coe_le_coe.1 <| by simp theorem continuous_circleMap_inv {R : ℝ} {z w : ℂ} (hw : w ∈ ball z R) : Continuous fun θ => (circleMap z R θ - w)⁻¹ := by have : ∀ θ, circleMap z R θ - w ≠ 0 := by simp_rw [sub_ne_zero] exact fun θ => circleMap_ne_mem_ball hw θ -- Porting note: was `continuity` exact Continuous.inv₀ (by fun_prop) this theorem circleMap_preimage_codiscrete {c : ℂ} {R : ℝ} (hR : R ≠ 0) : map (circleMap c R) (codiscrete ℝ) ≤ codiscreteWithin (Metric.sphere c |R|) := by intro s hs apply (analyticOnNhd_circleMap c R).preimage_mem_codiscreteWithin · intro x hx by_contra hCon obtain ⟨a, ha⟩ := eventuallyConst_iff_exists_eventuallyEq.1 hCon have := ha.deriv.eq_of_nhds simp [hR] at this · rwa [Set.image_univ, range_circleMap] theorem circleMap_neg_radius {r x : ℝ} {c : ℂ} : circleMap c (-r) x = circleMap c r (x + π) := by simp [circleMap, add_mul, Complex.exp_add] /-! ### Integrability of a function on a circle -/ /-- We say that a function `f : ℂ → E` is integrable on the circle with center `c` and radius `R` if the function `f ∘ circleMap c R` is integrable on `[0, 2π]`. Note that the actual function used in the definition of `circleIntegral` is `(deriv (circleMap c R) θ) • f (circleMap c R θ)`. Integrability of this function is equivalent to integrability of `f ∘ circleMap c R` whenever `R ≠ 0`. -/ def CircleIntegrable (f : ℂ → E) (c : ℂ) (R : ℝ) : Prop := IntervalIntegrable (fun θ : ℝ => f (circleMap c R θ)) volume 0 (2 * π) @[simp] theorem circleIntegrable_const (a : E) (c : ℂ) (R : ℝ) : CircleIntegrable (fun _ => a) c R := intervalIntegrable_const namespace CircleIntegrable variable {f g : ℂ → E} {c : ℂ} {R : ℝ} {A : Type*} [NormedRing A] {a : A} /-- Analogue of `IntervalIntegrable.abs`: If a real-valued function `f` is circle integrable, then so is `|f|`. -/ theorem abs {f : ℂ → ℝ} (hf : CircleIntegrable f c R) : CircleIntegrable |f| c R := IntervalIntegrable.abs hf nonrec theorem add (hf : CircleIntegrable f c R) (hg : CircleIntegrable g c R) : CircleIntegrable (f + g) c R := hf.add hg /-- Sums of circle integrable functions are circle integrable. -/ protected theorem sum {ι : Type*} (s : Finset ι) {f : ι → ℂ → E} (h : ∀ i ∈ s, CircleIntegrable (f i) c R) : CircleIntegrable (∑ i ∈ s, f i) c R := by rw [CircleIntegrable, (by aesop : (fun θ ↦ (∑ i ∈ s, f i) (circleMap c R θ)) = ∑ i ∈ s, fun θ ↦ f i (circleMap c R θ))] at * exact IntervalIntegrable.sum s h /-- Finsums of circle integrable functions are circle integrable. -/ protected theorem finsum {ι : Type*} {f : ι → ℂ → E} (h : ∀ i, CircleIntegrable (f i) c R) : CircleIntegrable (∑ᶠ i, f i) c R := by by_cases h₁ : (Function.support f).Finite · rw [finsum_eq_sum f h₁] exact CircleIntegrable.sum h₁.toFinset (fun i _ ↦ h i) · rw [finsum_of_infinite_support h₁] apply circleIntegrable_const nonrec theorem neg (hf : CircleIntegrable f c R) : CircleIntegrable (-f) c R := hf.neg /-- If `f` is circle integrable, then so are its scalar multiples. -/ theorem const_smul {f : ℂ → A} (h : CircleIntegrable f c R) : CircleIntegrable (a • f) c R := IntervalIntegrable.const_mul h _ /-- If `f` is circle integrable, then so are its scalar multiples. -/ theorem const_fun_smul {f : ℂ → A} (h : CircleIntegrable f c R) : CircleIntegrable (fun z ↦ a • f z) c R := const_smul h /-- The function we actually integrate over `[0, 2π]` in the definition of `circleIntegral` is integrable. -/ theorem out [NormedSpace ℂ E] (hf : CircleIntegrable f c R) : IntervalIntegrable (fun θ : ℝ => deriv (circleMap c R) θ • f (circleMap c R θ)) volume 0 (2 * π) := by simp only [CircleIntegrable, deriv_circleMap, intervalIntegrable_iff] at * refine (hf.norm.const_mul |R|).mono' ?_ ?_ · exact ((continuous_circleMap _ _).aestronglyMeasurable.mul_const I).smul hf.aestronglyMeasurable · simp [norm_smul] end CircleIntegrable @[simp] theorem circleIntegrable_zero_radius {f : ℂ → E} {c : ℂ} : CircleIntegrable f c 0 := by simp [CircleIntegrable] /-- Circle integrability is invariant when functions change along discrete sets. -/ theorem CircleIntegrable.congr_codiscreteWithin {c : ℂ} {R : ℝ} {f₁ f₂ : ℂ → E} (hf : f₁ =ᶠ[codiscreteWithin (Metric.sphere c |R|)] f₂) (hf₁ : CircleIntegrable f₁ c R) : CircleIntegrable f₂ c R := by by_cases hR : R = 0 · simp [hR] apply (intervalIntegrable_congr_codiscreteWithin _).1 hf₁ rw [eventuallyEq_iff_exists_mem] exact ⟨(circleMap c R)⁻¹' {z | f₁ z = f₂ z}, codiscreteWithin.mono (by simp only [Set.subset_univ]) (circleMap_preimage_codiscrete hR hf), by tauto⟩ /-- Circle integrability is invariant when functions change along discrete sets. -/ theorem circleIntegrable_congr_codiscreteWithin {c : ℂ} {R : ℝ} {f₁ f₂ : ℂ → E} (hf : f₁ =ᶠ[codiscreteWithin (Metric.sphere c |R|)] f₂) : CircleIntegrable f₁ c R ↔ CircleIntegrable f₂ c R := ⟨(CircleIntegrable.congr_codiscreteWithin hf ·), (CircleIntegrable.congr_codiscreteWithin hf.symm ·)⟩ theorem circleIntegrable_iff [NormedSpace ℂ E] {f : ℂ → E} {c : ℂ} (R : ℝ) : CircleIntegrable f c R ↔ IntervalIntegrable (fun θ : ℝ => deriv (circleMap c R) θ • f (circleMap c R θ)) volume 0 (2 * π) := by by_cases h₀ : R = 0 · simp +unfoldPartialApp [h₀, const] refine ⟨fun h => h.out, fun h => ?_⟩ simp only [CircleIntegrable, intervalIntegrable_iff, deriv_circleMap] at h ⊢ refine (h.norm.const_mul |R|⁻¹).mono' ?_ ?_ · have H : ∀ {θ}, circleMap 0 R θ * I ≠ 0 := fun {θ} => by simp [h₀, I_ne_zero] simpa only [inv_smul_smul₀ H] using ((continuous_circleMap 0 R).aestronglyMeasurable.mul_const I).aemeasurable.inv.aestronglyMeasurable.smul h.aestronglyMeasurable · simp [norm_smul, h₀] theorem ContinuousOn.circleIntegrable' {f : ℂ → E} {c : ℂ} {R : ℝ} (hf : ContinuousOn f (sphere c |R|)) : CircleIntegrable f c R := (hf.comp_continuous (continuous_circleMap _ _) (circleMap_mem_sphere' _ _)).intervalIntegrable _ _ theorem ContinuousOn.circleIntegrable {f : ℂ → E} {c : ℂ} {R : ℝ} (hR : 0 ≤ R) (hf : ContinuousOn f (sphere c R)) : CircleIntegrable f c R := ContinuousOn.circleIntegrable' <| (abs_of_nonneg hR).symm ▸ hf /-- The function `fun z ↦ (z - w) ^ n`, `n : ℤ`, is circle integrable on the circle with center `c` and radius `|R|` if and only if `R = 0` or `0 ≤ n`, or `w` does not belong to this circle. -/ @[simp] theorem circleIntegrable_sub_zpow_iff {c w : ℂ} {R : ℝ} {n : ℤ} : CircleIntegrable (fun z => (z - w) ^ n) c R ↔ R = 0 ∨ 0 ≤ n ∨ w ∉ sphere c |R| := by constructor · intro h; contrapose! h; rcases h with ⟨hR, hn, hw⟩ simp only [circleIntegrable_iff R, deriv_circleMap] rw [← image_circleMap_Ioc] at hw; rcases hw with ⟨θ, hθ, rfl⟩ replace hθ : θ ∈ [[0, 2 * π]] := Icc_subset_uIcc (Ioc_subset_Icc_self hθ) refine not_intervalIntegrable_of_sub_inv_isBigO_punctured ?_ Real.two_pi_pos.ne hθ set f : ℝ → ℂ := fun θ' => circleMap c R θ' - circleMap c R θ have : ∀ᶠ θ' in 𝓝[≠] θ, f θ' ∈ ball (0 : ℂ) 1 \ {0} := by suffices ∀ᶠ z in 𝓝[≠] circleMap c R θ, z - circleMap c R θ ∈ ball (0 : ℂ) 1 \ {0} from ((differentiable_circleMap c R θ).hasDerivAt.tendsto_nhdsNE (deriv_circleMap_ne_zero hR)).eventually this filter_upwards [self_mem_nhdsWithin, mem_nhdsWithin_of_mem_nhds (ball_mem_nhds _ zero_lt_one)] simp_all [dist_eq, sub_eq_zero] refine (((hasDerivAt_circleMap c R θ).isBigO_sub.mono inf_le_left).inv_rev (this.mono fun θ' h₁ h₂ => absurd h₂ h₁.2)).trans ?_ refine IsBigO.of_bound |R|⁻¹ (this.mono fun θ' hθ' => ?_) set x := ‖f θ'‖ suffices x⁻¹ ≤ x ^ n by simp only [Algebra.id.smul_eq_mul, norm_mul, norm_inv, norm_I, mul_one] simpa only [norm_circleMap_zero, norm_zpow, Ne, abs_eq_zero.not.2 hR, not_false_iff, inv_mul_cancel_left₀] using this have : x ∈ Ioo (0 : ℝ) 1 := by simpa [x, and_comm] using hθ' rw [← zpow_neg_one] refine (zpow_right_strictAnti₀ this.1 this.2).le_iff_ge.2 (Int.lt_add_one_iff.1 ?_); exact hn · rintro (rfl | H) exacts [circleIntegrable_zero_radius, ((continuousOn_id.sub continuousOn_const).zpow₀ _ fun z hz => H.symm.imp_left fun (hw : w ∉ sphere c |R|) => sub_ne_zero.2 <| ne_of_mem_of_not_mem hz hw).circleIntegrable'] @[simp] theorem circleIntegrable_sub_inv_iff {c w : ℂ} {R : ℝ} : CircleIntegrable (fun z => (z - w)⁻¹) c R ↔ R = 0 ∨ w ∉ sphere c |R| := by simp only [← zpow_neg_one, circleIntegrable_sub_zpow_iff]; norm_num variable [NormedSpace ℂ E] /-- Definition for $\oint_{|z-c|=R} f(z)\,dz$ -/ def circleIntegral (f : ℂ → E) (c : ℂ) (R : ℝ) : E := ∫ θ : ℝ in (0)..2 * π, deriv (circleMap c R) θ • f (circleMap c R θ) /-- `∮ z in C(c, R), f z` is the circle integral $\oint_{|z-c|=R} f(z)\,dz$. -/ notation3 "∮ "(...)" in ""C("c", "R")"", "r:(scoped f => circleIntegral f c R) => r theorem circleIntegral_def_Icc (f : ℂ → E) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), f z) = ∫ θ in Icc 0 (2 * π), deriv (circleMap c R) θ • f (circleMap c R θ) := by rw [circleIntegral, intervalIntegral.integral_of_le Real.two_pi_pos.le, Measure.restrict_congr_set Ioc_ae_eq_Icc] namespace circleIntegral @[simp] theorem integral_radius_zero (f : ℂ → E) (c : ℂ) : (∮ z in C(c, 0), f z) = 0 := by simp +unfoldPartialApp [circleIntegral, const] theorem integral_congr {f g : ℂ → E} {c : ℂ} {R : ℝ} (hR : 0 ≤ R) (h : EqOn f g (sphere c R)) : (∮ z in C(c, R), f z) = ∮ z in C(c, R), g z := intervalIntegral.integral_congr fun θ _ => by simp only [h (circleMap_mem_sphere _ hR _)] /-- Circle integrals are invariant when functions change along discrete sets. -/ theorem circleIntegral_congr_codiscreteWithin {c : ℂ} {R : ℝ} {f₁ f₂ : ℂ → ℂ} (hf : f₁ =ᶠ[codiscreteWithin (Metric.sphere c |R|)] f₂) (hR : R ≠ 0) : (∮ z in C(c, R), f₁ z) = (∮ z in C(c, R), f₂ z) := by apply intervalIntegral.integral_congr_ae_restrict apply ae_restrict_le_codiscreteWithin measurableSet_uIoc simp only [deriv_circleMap, smul_eq_mul, mul_eq_mul_left_iff, mul_eq_zero, circleMap_eq_center_iff, hR, Complex.I_ne_zero, or_self, or_false] exact codiscreteWithin.mono (by tauto) (circleMap_preimage_codiscrete hR hf) theorem integral_sub_inv_smul_sub_smul (f : ℂ → E) (c w : ℂ) (R : ℝ) : (∮ z in C(c, R), (z - w)⁻¹ • (z - w) • f z) = ∮ z in C(c, R), f z := by rcases eq_or_ne R 0 with (rfl | hR); · simp only [integral_radius_zero] have : (circleMap c R ⁻¹' {w}).Countable := (countable_singleton _).preimage_circleMap c hR refine intervalIntegral.integral_congr_ae ((this.ae_notMem _).mono fun θ hθ _' => ?_) change circleMap c R θ ≠ w at hθ simp only [inv_smul_smul₀ (sub_ne_zero.2 <| hθ)] theorem integral_undef {f : ℂ → E} {c : ℂ} {R : ℝ} (hf : ¬CircleIntegrable f c R) : (∮ z in C(c, R), f z) = 0 := intervalIntegral.integral_undef (mt (circleIntegrable_iff R).mpr hf) theorem integral_add {f g : ℂ → E} {c : ℂ} {R : ℝ} (hf : CircleIntegrable f c R) (hg : CircleIntegrable g c R) : (∮ z in C(c, R), f z + g z) = (∮ z in C(c, R), f z) + (∮ z in C(c, R), g z) := by simp only [circleIntegral, smul_add, intervalIntegral.integral_add hf.out hg.out] theorem integral_sub {f g : ℂ → E} {c : ℂ} {R : ℝ} (hf : CircleIntegrable f c R) (hg : CircleIntegrable g c R) : (∮ z in C(c, R), f z - g z) = (∮ z in C(c, R), f z) - ∮ z in C(c, R), g z := by simp only [circleIntegral, smul_sub, intervalIntegral.integral_sub hf.out hg.out] theorem norm_integral_le_of_norm_le_const' {f : ℂ → E} {c : ℂ} {R C : ℝ} (hf : ∀ z ∈ sphere c |R|, ‖f z‖ ≤ C) : ‖∮ z in C(c, R), f z‖ ≤ 2 * π * |R| * C := calc ‖∮ z in C(c, R), f z‖ ≤ |R| * C * |2 * π - 0| := intervalIntegral.norm_integral_le_of_norm_le_const fun θ _ => calc ‖deriv (circleMap c R) θ • f (circleMap c R θ)‖ = |R| * ‖f (circleMap c R θ)‖ := by simp [norm_smul] _ ≤ |R| * C := mul_le_mul_of_nonneg_left (hf _ <| circleMap_mem_sphere' _ _ _) (abs_nonneg _) _ = 2 * π * |R| * C := by rw [sub_zero, _root_.abs_of_pos Real.two_pi_pos]; ac_rfl theorem norm_integral_le_of_norm_le_const {f : ℂ → E} {c : ℂ} {R C : ℝ} (hR : 0 ≤ R) (hf : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) : ‖∮ z in C(c, R), f z‖ ≤ 2 * π * R * C := have : |R| = R := abs_of_nonneg hR calc ‖∮ z in C(c, R), f z‖ ≤ 2 * π * |R| * C := norm_integral_le_of_norm_le_const' <| by rwa [this] _ = 2 * π * R * C := by rw [this] theorem norm_two_pi_i_inv_smul_integral_le_of_norm_le_const {f : ℂ → E} {c : ℂ} {R C : ℝ} (hR : 0 ≤ R) (hf : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) : ‖(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), f z‖ ≤ R * C := by have : ‖(2 * π * I : ℂ)⁻¹‖ = (2 * π)⁻¹ := by simp [Real.pi_pos.le] rw [norm_smul, this, ← div_eq_inv_mul, div_le_iff₀ Real.two_pi_pos, mul_comm (R * C), ← mul_assoc] exact norm_integral_le_of_norm_le_const hR hf /-- If `f` is continuous on the circle `|z - c| = R`, `R > 0`, the `‖f z‖` is less than or equal to `C : ℝ` on this circle, and this norm is strictly less than `C` at some point `z` of the circle, then `‖∮ z in C(c, R), f z‖ < 2 * π * R * C`. -/ theorem norm_integral_lt_of_norm_le_const_of_lt {f : ℂ → E} {c : ℂ} {R C : ℝ} (hR : 0 < R) (hc : ContinuousOn f (sphere c R)) (hf : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) (hlt : ∃ z ∈ sphere c R, ‖f z‖ < C) : ‖∮ z in C(c, R), f z‖ < 2 * π * R * C := by rw [← _root_.abs_of_pos hR, ← image_circleMap_Ioc] at hlt rcases hlt with ⟨_, ⟨θ₀, hmem, rfl⟩, hlt⟩ calc ‖∮ z in C(c, R), f z‖ ≤ ∫ θ in (0)..2 * π, ‖deriv (circleMap c R) θ • f (circleMap c R θ)‖ := intervalIntegral.norm_integral_le_integral_norm Real.two_pi_pos.le _ < ∫ _ in (0)..2 * π, R * C := by simp only [deriv_circleMap, norm_smul, norm_mul, norm_circleMap_zero, abs_of_pos hR, norm_I, mul_one] refine intervalIntegral.integral_lt_integral_of_continuousOn_of_le_of_exists_lt Real.two_pi_pos ?_ continuousOn_const (fun θ _ => ?_) ⟨θ₀, Ioc_subset_Icc_self hmem, ?_⟩ · exact continuousOn_const.mul (hc.comp (continuous_circleMap _ _).continuousOn fun θ _ => circleMap_mem_sphere _ hR.le _).norm · exact mul_le_mul_of_nonneg_left (hf _ <| circleMap_mem_sphere _ hR.le _) hR.le · exact (mul_lt_mul_left hR).2 hlt _ = 2 * π * R * C := by simp [mul_assoc]; ring @[simp] theorem integral_smul {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [SMulCommClass 𝕜 ℂ E] (a : 𝕜) (f : ℂ → E) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), a • f z) = a • ∮ z in C(c, R), f z := by simp only [circleIntegral, ← smul_comm a (_ : ℂ) (_ : E), intervalIntegral.integral_smul] @[simp] theorem integral_smul_const [CompleteSpace E] (f : ℂ → ℂ) (a : E) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), f z • a) = (∮ z in C(c, R), f z) • a := by simp only [circleIntegral, intervalIntegral.integral_smul_const, ← smul_assoc] @[simp] theorem integral_const_mul (a : ℂ) (f : ℂ → ℂ) (c : ℂ) (R : ℝ) : (∮ z in C(c, R), a * f z) = a * ∮ z in C(c, R), f z := integral_smul a f c R @[simp] theorem integral_sub_center_inv (c : ℂ) {R : ℝ} (hR : R ≠ 0) : (∮ z in C(c, R), (z - c)⁻¹) = 2 * π * I := by simp [circleIntegral, ← div_eq_mul_inv, mul_div_cancel_left₀ _ (circleMap_ne_center hR)] /-- If `f' : ℂ → E` is a derivative of a complex differentiable function on the circle `Metric.sphere c |R|`, then `∮ z in C(c, R), f' z = 0`. -/ theorem integral_eq_zero_of_hasDerivWithinAt' [CompleteSpace E] {f f' : ℂ → E} {c : ℂ} {R : ℝ} (h : ∀ z ∈ sphere c |R|, HasDerivWithinAt f (f' z) (sphere c |R|) z) : (∮ z in C(c, R), f' z) = 0 := by by_cases hi : CircleIntegrable f' c R · rw [← sub_eq_zero.2 ((periodic_circleMap c R).comp f).eq] refine intervalIntegral.integral_eq_sub_of_hasDerivAt (fun θ _ => ?_) hi.out exact (h _ (circleMap_mem_sphere' _ _ _)).scomp_hasDerivAt θ (differentiable_circleMap _ _ _).hasDerivAt (circleMap_mem_sphere' _ _) · exact integral_undef hi /-- If `f' : ℂ → E` is a derivative of a complex differentiable function on the circle `Metric.sphere c R`, then `∮ z in C(c, R), f' z = 0`. -/ theorem integral_eq_zero_of_hasDerivWithinAt [CompleteSpace E] {f f' : ℂ → E} {c : ℂ} {R : ℝ} (hR : 0 ≤ R) (h : ∀ z ∈ sphere c R, HasDerivWithinAt f (f' z) (sphere c R) z) : (∮ z in C(c, R), f' z) = 0 := integral_eq_zero_of_hasDerivWithinAt' <| (abs_of_nonneg hR).symm ▸ h /-- If `n < 0` and `|w - c| = |R|`, then `(z - w) ^ n` is not circle integrable on the circle with center `c` and radius `|R|`, so the integral `∮ z in C(c, R), (z - w) ^ n` is equal to zero. -/ theorem integral_sub_zpow_of_undef {n : ℤ} {c w : ℂ} {R : ℝ} (hn : n < 0) (hw : w ∈ sphere c |R|) : (∮ z in C(c, R), (z - w) ^ n) = 0 := by rcases eq_or_ne R 0 with (rfl | h0) · apply integral_radius_zero · apply integral_undef simpa [circleIntegrable_sub_zpow_iff, *, not_or] /-- If `n ≠ -1` is an integer number, then the integral of `(z - w) ^ n` over the circle equals zero. -/ theorem integral_sub_zpow_of_ne {n : ℤ} (hn : n ≠ -1) (c w : ℂ) (R : ℝ) : (∮ z in C(c, R), (z - w) ^ n) = 0 := by rcases em (w ∈ sphere c |R| ∧ n < -1) with (⟨hw, hn⟩ | H) · exact integral_sub_zpow_of_undef (hn.trans (by decide)) hw push_neg at H have hd : ∀ z, z ≠ w ∨ -1 ≤ n → HasDerivAt (fun z => (z - w) ^ (n + 1) / (n + 1)) ((z - w) ^ n) z := by intro z hne convert ((hasDerivAt_zpow (n + 1) _ (hne.imp _ _)).comp z ((hasDerivAt_id z).sub_const w)).div_const _ using 1 · have hn' : (n + 1 : ℂ) ≠ 0 := by rwa [Ne, ← eq_neg_iff_add_eq_zero, ← Int.cast_one, ← Int.cast_neg, Int.cast_inj] simp [mul_div_cancel_left₀ _ hn'] exacts [sub_ne_zero.2, neg_le_iff_add_nonneg.1] refine integral_eq_zero_of_hasDerivWithinAt' fun z hz => (hd z ?_).hasDerivWithinAt exact (ne_or_eq z w).imp_right fun (h : z = w) => H <| h ▸ hz end circleIntegral /-- The power series that is equal to $\frac{1}{2πi}\sum_{n=0}^{\infty} \oint_{|z-c|=R} \left(\frac{w-c}{z - c}\right)^n \frac{1}{z-c}f(z)\,dz$ at `w - c`. The coefficients of this power series depend only on `f ∘ circleMap c R`, and the power series converges to `f w` if `f` is differentiable on the closed ball `Metric.closedBall c R` and `w` belongs to the corresponding open ball. For any circle integrable function `f`, this power series converges to the Cauchy integral for `f`. -/ def cauchyPowerSeries (f : ℂ → E) (c : ℂ) (R : ℝ) : FormalMultilinearSeries ℂ ℂ E := fun n => ContinuousMultilinearMap.mkPiRing ℂ _ <| (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c)⁻¹ ^ n • (z - c)⁻¹ • f z theorem cauchyPowerSeries_apply (f : ℂ → E) (c : ℂ) (R : ℝ) (n : ℕ) (w : ℂ) : (cauchyPowerSeries f c R n fun _ => w) = (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (w / (z - c)) ^ n • (z - c)⁻¹ • f z := by simp only [cauchyPowerSeries, ContinuousMultilinearMap.mkPiRing_apply, Fin.prod_const, div_eq_mul_inv, mul_pow, mul_smul, circleIntegral.integral_smul] rw [← smul_comm (w ^ n)] theorem norm_cauchyPowerSeries_le (f : ℂ → E) (c : ℂ) (R : ℝ) (n : ℕ) : ‖cauchyPowerSeries f c R n‖ ≤ ((2 * π)⁻¹ * ∫ θ : ℝ in (0)..2 * π, ‖f (circleMap c R θ)‖) * |R|⁻¹ ^ n := calc ‖cauchyPowerSeries f c R n‖ _ = (2 * π)⁻¹ * ‖∮ z in C(c, R), (z - c)⁻¹ ^ n • (z - c)⁻¹ • f z‖ := by simp [cauchyPowerSeries, norm_smul, Real.pi_pos.le] _ ≤ (2 * π)⁻¹ * ∫ θ in (0)..2 * π, ‖deriv (circleMap c R) θ • (circleMap c R θ - c)⁻¹ ^ n • (circleMap c R θ - c)⁻¹ • f (circleMap c R θ)‖ := (mul_le_mul_of_nonneg_left (intervalIntegral.norm_integral_le_integral_norm Real.two_pi_pos.le) (by simp [Real.pi_pos.le])) _ = (2 * π)⁻¹ * (|R|⁻¹ ^ n * (|R| * (|R|⁻¹ * ∫ x : ℝ in (0)..2 * π, ‖f (circleMap c R x)‖))) := by simp [norm_smul, mul_left_comm |R|] _ ≤ ((2 * π)⁻¹ * ∫ θ : ℝ in (0)..2 * π, ‖f (circleMap c R θ)‖) * |R|⁻¹ ^ n := by rcases eq_or_ne R 0 with (rfl | hR) · cases n <;> simp [-mul_inv_rev] · rw [mul_inv_cancel_left₀, mul_assoc, mul_comm (|R|⁻¹ ^ n)] rwa [Ne, _root_.abs_eq_zero] theorem le_radius_cauchyPowerSeries (f : ℂ → E) (c : ℂ) (R : ℝ≥0) : ↑R ≤ (cauchyPowerSeries f c R).radius := by refine (cauchyPowerSeries f c R).le_radius_of_bound ((2 * π)⁻¹ * ∫ θ : ℝ in (0)..2 * π, ‖f (circleMap c R θ)‖) fun n => ?_ refine (mul_le_mul_of_nonneg_right (norm_cauchyPowerSeries_le _ _ _ _) (pow_nonneg R.coe_nonneg _)).trans ?_ rw [abs_of_nonneg R.coe_nonneg] rcases eq_or_ne (R ^ n : ℝ) 0 with hR | hR · rw_mod_cast [hR, mul_zero] exact mul_nonneg (inv_nonneg.2 Real.two_pi_pos.le) (intervalIntegral.integral_nonneg Real.two_pi_pos.le fun _ _ => norm_nonneg _) · rw [inv_pow] have : (R : ℝ) ^ n ≠ 0 := by norm_cast at hR ⊢ rw [inv_mul_cancel_right₀ this] /-- For any circle integrable function `f`, the power series `cauchyPowerSeries f c R` multiplied by `2πI` converges to the integral `∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`. -/ theorem hasSum_two_pi_I_cauchyPowerSeries_integral {f : ℂ → E} {c : ℂ} {R : ℝ} {w : ℂ} (hf : CircleIntegrable f c R) (hw : ‖w‖ < R) : HasSum (fun n : ℕ => ∮ z in C(c, R), (w / (z - c)) ^ n • (z - c)⁻¹ • f z) (∮ z in C(c, R), (z - (c + w))⁻¹ • f z) := by have hR : 0 < R := (norm_nonneg w).trans_lt hw have hwR : ‖w‖ / R ∈ Ico (0 : ℝ) 1 := ⟨div_nonneg (norm_nonneg w) hR.le, (div_lt_one hR).2 hw⟩ refine intervalIntegral.hasSum_integral_of_dominated_convergence (fun n θ => ‖f (circleMap c R θ)‖ * (‖w‖ / R) ^ n) (fun n => ?_) (fun n => ?_) ?_ ?_ ?_ · simp only [deriv_circleMap] apply_rules [AEStronglyMeasurable.smul, hf.def'.1] <;> apply Measurable.aestronglyMeasurable · fun_prop · fun_prop · fun_prop · simp [norm_smul, abs_of_pos hR, mul_left_comm R, inv_mul_cancel_left₀ hR.ne', mul_comm ‖_‖] · exact Eventually.of_forall fun _ _ => (summable_geometric_of_lt_one hwR.1 hwR.2).mul_left _ · simpa only [tsum_mul_left, tsum_geometric_of_lt_one hwR.1 hwR.2] using hf.norm.mul_continuousOn continuousOn_const · refine Eventually.of_forall fun θ _ => HasSum.const_smul _ ?_ simp only [smul_smul] refine HasSum.smul_const ?_ _ have : ‖w / (circleMap c R θ - c)‖ < 1 := by simpa [abs_of_pos hR] using hwR.2 convert (hasSum_geometric_of_norm_lt_one this).mul_right _ using 1 simp [← sub_sub, ← mul_inv, sub_mul, div_mul_cancel₀ _ (circleMap_ne_center hR.ne')] /-- For any circle integrable function `f`, the power series `cauchyPowerSeries f c R`, `R > 0`, converges to the Cauchy integral `(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`. -/ theorem hasSum_cauchyPowerSeries_integral {f : ℂ → E} {c : ℂ} {R : ℝ} {w : ℂ} (hf : CircleIntegrable f c R) (hw : ‖w‖ < R) : HasSum (fun n => cauchyPowerSeries f c R n fun _ => w) ((2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - (c + w))⁻¹ • f z) := by simp only [cauchyPowerSeries_apply] exact (hasSum_two_pi_I_cauchyPowerSeries_integral hf hw).const_smul _ /-- For any circle integrable function `f`, the power series `cauchyPowerSeries f c R`, `R > 0`, converges to the Cauchy integral `(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`. -/ theorem sum_cauchyPowerSeries_eq_integral {f : ℂ → E} {c : ℂ} {R : ℝ} {w : ℂ} (hf : CircleIntegrable f c R) (hw : ‖w‖ < R) : (cauchyPowerSeries f c R).sum w = (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - (c + w))⁻¹ • f z := (hasSum_cauchyPowerSeries_integral hf hw).tsum_eq /-- For any circle integrable function `f`, the power series `cauchyPowerSeries f c R`, `R > 0`, converges to the Cauchy integral `(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z` on the open disc `Metric.ball c R`. -/ theorem hasFPowerSeriesOn_cauchy_integral {f : ℂ → E} {c : ℂ} {R : ℝ≥0} (hf : CircleIntegrable f c R) (hR : 0 < R) : HasFPowerSeriesOnBall (fun w => (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z) (cauchyPowerSeries f c R) c R := { r_le := le_radius_cauchyPowerSeries _ _ _ r_pos := ENNReal.coe_pos.2 hR hasSum := fun hy ↦ hasSum_cauchyPowerSeries_integral hf <| by simpa using hy } namespace circleIntegral /-- Integral $\oint_{|z-c|=R} \frac{dz}{z-w} = 2πi$ whenever $|w-c| < R$. -/ theorem integral_sub_inv_of_mem_ball {c w : ℂ} {R : ℝ} (hw : w ∈ ball c R) : (∮ z in C(c, R), (z - w)⁻¹) = 2 * π * I := by have hR : 0 < R := dist_nonneg.trans_lt hw suffices H : HasSum (fun n : ℕ => ∮ z in C(c, R), ((w - c) / (z - c)) ^ n * (z - c)⁻¹) (2 * π * I) by have A : CircleIntegrable (fun _ => (1 : ℂ)) c R := continuousOn_const.circleIntegrable' refine (H.unique ?_).symm simpa only [smul_eq_mul, mul_one, add_sub_cancel] using hasSum_two_pi_I_cauchyPowerSeries_integral A hw have H : ∀ n : ℕ, n ≠ 0 → (∮ z in C(c, R), (z - c) ^ (-n - 1 : ℤ)) = 0 := by refine fun n hn => integral_sub_zpow_of_ne ?_ _ _ _; simpa have : (∮ z in C(c, R), ((w - c) / (z - c)) ^ 0 * (z - c)⁻¹) = 2 * π * I := by simp [hR.ne'] refine this ▸ hasSum_single _ fun n hn => ?_ simp only [div_eq_mul_inv, mul_pow, integral_const_mul, mul_assoc] rw [(integral_congr hR.le fun z hz => _).trans (H n hn), mul_zero] intro z _ rw [← pow_succ, ← zpow_natCast, inv_zpow, ← zpow_neg, Int.natCast_succ, neg_add, sub_eq_add_neg _ (1 : ℤ)] end circleIntegral
EssentiallySmall.lean
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.EssentiallySmall /-! # Limits over essentially small indexing categories If `C` has limits of size `w` and `J` is `w`-essentially small, then `C` has limits of shape `J`. See also the file `FinallySmall.lean` for more general results. -/ universe w₁ w₂ v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory namespace CategoryTheory.Limits variable (J : Type u₂) [Category.{v₂} J] (C : Type u₁) [Category.{v₁} C] theorem hasLimitsOfShape_of_essentiallySmall [EssentiallySmall.{w₁} J] [HasLimitsOfSize.{w₁, w₁} C] : HasLimitsOfShape J C := hasLimitsOfShape_of_equivalence <| Equivalence.symm <| equivSmallModel.{w₁} J theorem hasColimitsOfShape_of_essentiallySmall [EssentiallySmall.{w₁} J] [HasColimitsOfSize.{w₁, w₁} C] : HasColimitsOfShape J C := hasColimitsOfShape_of_equivalence <| Equivalence.symm <| equivSmallModel.{w₁} J theorem hasProductsOfShape_of_small (β : Type w₂) [Small.{w₁} β] [HasProducts.{w₁} C] : HasProductsOfShape β C := hasLimitsOfShape_of_equivalence <| Discrete.equivalence <| Equiv.symm <| equivShrink β theorem hasCoproductsOfShape_of_small (β : Type w₂) [Small.{w₁} β] [HasCoproducts.{w₁} C] : HasCoproductsOfShape β C := hasColimitsOfShape_of_equivalence <| Discrete.equivalence <| Equiv.symm <| equivShrink β end CategoryTheory.Limits
Preorder.lean
/- Copyright (c) 2025 Sina Hazratpour. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sina Hazratpour, Joël Riou -/ import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts /-! # (Co)limits in a preorder category We provide basic results about the nullary and binary (co)products in the associated category of a preordered type. -/ universe u open CategoryTheory Limits namespace Preorder variable (C : Type u) section OrderBot variable [Preorder C] [OrderBot C] /-- The least element in a preordered type is initial in the category associated to this preorder. -/ def isInitialBot : IsInitial (⊥ : C) := IsInitial.ofUnique _ instance : HasInitial C := hasInitial_of_unique ⊥ end OrderBot section OrderTop variable [Preorder C] [OrderTop C] /-- The greatest element of a preordered type is terminal in the category associated to this preorder. -/ def isTerminalTop : IsTerminal (⊤ : C) := IsTerminal.ofUnique _ instance : HasTerminal C := hasTerminal_of_unique ⊤ end OrderTop section SemilatticeInf variable {C} [SemilatticeInf C] /-- The infimum of two elements in a preordered type is a binary product in the category associated to this preorder. -/ def isLimitBinaryFan (X Y : C) : IsLimit (BinaryFan.mk (P := X ⊓ Y) (homOfLE inf_le_left) (homOfLE inf_le_right)) := BinaryFan.isLimitMk (fun s ↦ homOfLE (le_inf (leOfHom s.fst) (leOfHom s.snd))) (by intros; rfl) (by intros; rfl) (by intros; rfl) end SemilatticeInf section SemilatticeSup variable {C} [SemilatticeSup C] /-- The supremum of two elements in a preordered type is a binary coproduct in the category associated to this preorder. -/ def isColimitBinaryCofan (X Y : C) : IsColimit (BinaryCofan.mk (P := X ⊔ Y) (homOfLE le_sup_left) (homOfLE le_sup_right)) := BinaryCofan.isColimitMk (fun s ↦ homOfLE (sup_le (leOfHom s.inl) (leOfHom s.inr))) (by intros; rfl) (by intros; rfl) (by intros; rfl) end SemilatticeSup end Preorder
RingQuot.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.RingQuot import Mathlib.Algebra.Star.Basic /-! # The *-ring structure on suitable quotients of a *-ring. -/ namespace RingQuot universe u variable {R : Type u} [Semiring R] (r : R → R → Prop) section StarRing variable [StarRing R] theorem Rel.star (hr : ∀ a b, r a b → r (star a) (star b)) ⦃a b : R⦄ (h : Rel r a b) : Rel r (star a) (star b) := by induction h with | of h => exact Rel.of (hr _ _ h) | add_left _ h => rw [star_add, star_add] exact Rel.add_left h | mul_left _ h => rw [star_mul, star_mul] exact Rel.mul_right h | mul_right _ h => rw [star_mul, star_mul] exact Rel.mul_left h private irreducible_def star' (hr : ∀ a b, r a b → r (star a) (star b)) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (star : R → R) (Rel.star r hr) a⟩ theorem star'_quot (hr : ∀ a b, r a b → r (star a) (star b)) {a} : (star' r hr ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (star a)⟩ := star'_def _ _ _ /-- Transfer a star_ring instance through a quotient, if the quotient is invariant to `star` -/ def starRing {R : Type u} [Semiring R] [StarRing R] (r : R → R → Prop) (hr : ∀ a b, r a b → r (star a) (star b)) : StarRing (RingQuot r) where star := star' r hr star_involutive := by rintro ⟨⟨⟩⟩ simp [star'_quot] star_mul := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [star'_quot, mul_quot, star_mul] star_add := by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ simp [star'_quot, add_quot, star_add] end StarRing end RingQuot
Dual.lean
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.LocallyConvex.Polar import Mathlib.Analysis.NormedSpace.HahnBanach.Extension import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Data.Set.Finite.Lemmas import Mathlib.Analysis.LocallyConvex.AbsConvex import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Topology.Algebra.Module.StrongDual /-! # The strong dual of a normed space In this file we consider the strong dual `StrongDual` of a normed space, and the continuous linear map `NormedSpace.inclusionInDoubleDual` from a normed space into its double StrongDual. For base field `𝕜 = ℝ` or `𝕜 = ℂ`, this map is actually an isometric embedding; we provide a version `NormedSpace.inclusionInDoubleDualLi` of the map which is of type a bundled linear isometric embedding, `E →ₗᵢ[𝕜] (StrongDual 𝕜 (StrongDual 𝕜 E))`. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `SeminormedAddCommGroup` and we specialize to `NormedAddCommGroup` when needed. ## Main definitions * `inclusionInDoubleDual` and `inclusionInDoubleDualLi` are the inclusion of a normed space in its double `StrongDual`, considered as a bounded linear map and as a linear isometry, respectively. * `polar 𝕜 s` is the subset of `StrongDual 𝕜 E` consisting of those functionals `x'` for which `‖x' z‖ ≤ 1` for every `z ∈ s`. ## References * [Conway, John B., A course in functional analysis][conway1990] ## Tags strong dual, polar -/ noncomputable section open Topology Bornology universe u v namespace NormedSpace section General variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] variable (E : Type*) [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] variable (F : Type*) [NormedAddCommGroup F] [NormedSpace 𝕜 F] /-- The inclusion of a normed space in its double (topological) strong dual, considered as a bounded linear map. -/ def inclusionInDoubleDual : E →L[𝕜] StrongDual 𝕜 (StrongDual 𝕜 E) := ContinuousLinearMap.apply 𝕜 𝕜 @[simp] theorem dual_def (x : E) (f : StrongDual 𝕜 E) : inclusionInDoubleDual 𝕜 E x f = f x := rfl theorem inclusionInDoubleDual_norm_eq : ‖inclusionInDoubleDual 𝕜 E‖ = ‖ContinuousLinearMap.id 𝕜 (StrongDual 𝕜 E)‖ := ContinuousLinearMap.opNorm_flip _ theorem inclusionInDoubleDual_norm_le : ‖inclusionInDoubleDual 𝕜 E‖ ≤ 1 := by rw [inclusionInDoubleDual_norm_eq] exact ContinuousLinearMap.norm_id_le theorem double_dual_bound (x : E) : ‖(inclusionInDoubleDual 𝕜 E) x‖ ≤ ‖x‖ := by simpa using ContinuousLinearMap.le_of_opNorm_le _ (inclusionInDoubleDual_norm_le 𝕜 E) x end General section BidualIsometry variable (𝕜 : Type v) [RCLike 𝕜] {E : Type u} [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- If one controls the norm of every `f x`, then one controls the norm of `x`. Compare `ContinuousLinearMap.opNorm_le_bound`. -/ theorem norm_le_dual_bound (x : E) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ f : StrongDual 𝕜 E, ‖f x‖ ≤ M * ‖f‖) : ‖x‖ ≤ M := by classical by_cases h : x = 0 · simp only [h, hMp, norm_zero] · obtain ⟨f, hf₁, hfx⟩ : ∃ f : E →L[𝕜] 𝕜, ‖f‖ = 1 ∧ f x = ‖x‖ := exists_dual_vector 𝕜 x h calc ‖x‖ = ‖(‖x‖ : 𝕜)‖ := RCLike.norm_coe_norm.symm _ = ‖f x‖ := by rw [hfx] _ ≤ M * ‖f‖ := hM f _ = M := by rw [hf₁, mul_one] theorem eq_zero_of_forall_dual_eq_zero {x : E} (h : ∀ f : StrongDual 𝕜 E, f x = (0 : 𝕜)) : x = 0 := norm_le_zero_iff.mp (norm_le_dual_bound 𝕜 x le_rfl fun f => by simp [h f]) theorem eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 ↔ ∀ g : StrongDual 𝕜 E, g x = 0 := ⟨fun hx => by simp [hx], fun h => eq_zero_of_forall_dual_eq_zero 𝕜 h⟩ /-- See also `geometric_hahn_banach_point_point`. -/ theorem eq_iff_forall_dual_eq {x y : E} : x = y ↔ ∀ g : StrongDual 𝕜 E, g x = g y := by rw [← sub_eq_zero, eq_zero_iff_forall_dual_eq_zero 𝕜 (x - y)] simp [sub_eq_zero] /-- The inclusion of a normed space in its double strong dual is an isometry onto its image. -/ def inclusionInDoubleDualLi : E →ₗᵢ[𝕜] StrongDual 𝕜 (StrongDual 𝕜 E) := { inclusionInDoubleDual 𝕜 E with norm_map' := by intro x apply le_antisymm · exact double_dual_bound 𝕜 E x rw [ContinuousLinearMap.norm_def] refine le_csInf ContinuousLinearMap.bounds_nonempty ?_ rintro c ⟨hc1, hc2⟩ exact norm_le_dual_bound 𝕜 x hc1 hc2 } end BidualIsometry section PolarSets open Metric Set StrongDual variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] theorem isClosed_polar (s : Set E) : IsClosed (StrongDual.polar 𝕜 s) := by dsimp only [StrongDual.polar] simp only [LinearMap.polar_eq_iInter, LinearMap.flip_apply] refine isClosed_biInter fun z _ => ?_ exact isClosed_Iic.preimage (ContinuousLinearMap.apply 𝕜 𝕜 z).continuous.norm @[simp] theorem polar_closure (s : Set E) : StrongDual.polar 𝕜 (closure s) = StrongDual.polar 𝕜 s := ((strongDualPairing 𝕜 E).flip.polar_antitone subset_closure).antisymm <| (strongDualPairing 𝕜 E).flip.polar_gc.l_le <| closure_minimal ((strongDualPairing 𝕜 E).flip.polar_gc.le_u_l s) <| by simpa [LinearMap.flip_flip] using (isClosed_polar _ _).preimage (inclusionInDoubleDual 𝕜 E).continuous variable {𝕜} /-- If `x'` is a `StrongDual 𝕜 E` element such that the norms `‖x' z‖` are bounded for `z ∈ s`, then a small scalar multiple of `x'` is in `polar 𝕜 s`. -/ theorem smul_mem_polar {s : Set E} {x' : StrongDual 𝕜 E} {c : 𝕜} (hc : ∀ z, z ∈ s → ‖x' z‖ ≤ ‖c‖) : c⁻¹ • x' ∈ StrongDual.polar 𝕜 s := by by_cases c_zero : c = 0 · simp only [c_zero, inv_zero, zero_smul] exact (strongDualPairing 𝕜 E).flip.zero_mem_polar _ have eq : ∀ z, ‖c⁻¹ • x' z‖ = ‖c⁻¹‖ * ‖x' z‖ := fun z => norm_smul c⁻¹ _ have le : ∀ z, z ∈ s → ‖c⁻¹ • x' z‖ ≤ ‖c⁻¹‖ * ‖c‖ := by intro z hzs rw [eq z] apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _) have cancel : ‖c⁻¹‖ * ‖c‖ = 1 := by simp only [c_zero, norm_eq_zero, Ne, not_false_iff, inv_mul_cancel₀, norm_inv] rwa [cancel] at le theorem polar_ball_subset_closedBall_div {c : 𝕜} (hc : 1 < ‖c‖) {r : ℝ} (hr : 0 < r) : StrongDual.polar 𝕜 (ball (0 : E) r) ⊆ closedBall (0 : StrongDual 𝕜 E) (‖c‖ / r) := by intro x' hx' rw [StrongDual.mem_polar_iff] at hx' simp only [mem_closedBall_zero_iff, mem_ball_zero_iff] at * have hcr : 0 < ‖c‖ / r := div_pos (zero_lt_one.trans hc) hr refine ContinuousLinearMap.opNorm_le_of_shell hr hcr.le hc fun x h₁ h₂ => ?_ calc ‖x' x‖ ≤ 1 := hx' _ h₂ _ ≤ ‖c‖ / r * ‖x‖ := (inv_le_iff_one_le_mul₀' hcr).1 (by rwa [inv_div]) variable (𝕜) theorem closedBall_inv_subset_polar_closedBall {r : ℝ} : closedBall (0 : StrongDual 𝕜 E) r⁻¹ ⊆ StrongDual.polar 𝕜 (closedBall (0 : E) r) := fun x' hx' x hx => calc ‖x' x‖ ≤ ‖x'‖ * ‖x‖ := x'.le_opNorm x _ ≤ r⁻¹ * r := (mul_le_mul (mem_closedBall_zero_iff.1 hx') (mem_closedBall_zero_iff.1 hx) (norm_nonneg _) (dist_nonneg.trans hx')) _ = r / r := inv_mul_eq_div _ _ _ ≤ 1 := div_self_le_one r /-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with inverse radius. -/ theorem polar_closedBall {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] {r : ℝ} (hr : 0 < r) : StrongDual.polar 𝕜 (closedBall (0 : E) r) = closedBall (0 : StrongDual 𝕜 E) r⁻¹ := by refine Subset.antisymm ?_ (closedBall_inv_subset_polar_closedBall 𝕜) intro x' h simp only [mem_closedBall_zero_iff] refine ContinuousLinearMap.opNorm_le_of_ball hr (inv_nonneg.mpr hr.le) fun z _ => ?_ simpa only [one_div] using LinearMap.bound_of_ball_bound' hr 1 x'.toLinearMap h z theorem polar_ball {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] {r : ℝ} (hr : 0 < r) : StrongDual.polar 𝕜 (ball (0 : E) r) = closedBall (0 : StrongDual 𝕜 E) r⁻¹ := by apply le_antisymm · intro x hx rw [mem_closedBall_zero_iff] apply le_of_forall_gt_imp_ge_of_dense intro a ha rw [← mem_closedBall_zero_iff, ← (mul_div_cancel_left₀ a (Ne.symm (ne_of_lt hr)))] rw [← RCLike.norm_of_nonneg (K := 𝕜) (le_trans zero_le_one (le_of_lt ((inv_lt_iff_one_lt_mul₀' hr).mp ha)))] apply polar_ball_subset_closedBall_div _ hr hx rw [RCLike.norm_of_nonneg (K := 𝕜) (le_trans zero_le_one (le_of_lt ((inv_lt_iff_one_lt_mul₀' hr).mp ha)))] exact (inv_lt_iff_one_lt_mul₀' hr).mp ha · rw [← polar_closedBall hr] exact LinearMap.polar_antitone _ ball_subset_closedBall /-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms of all elements of the polar `polar 𝕜 s` are bounded by a constant. -/ theorem isBounded_polar_of_mem_nhds_zero {s : Set E} (s_nhds : s ∈ 𝓝 (0 : E)) : IsBounded (StrongDual.polar 𝕜 s) := by obtain ⟨a, ha⟩ : ∃ a : 𝕜, 1 < ‖a‖ := NormedField.exists_one_lt_norm 𝕜 obtain ⟨r, r_pos, r_ball⟩ : ∃ r : ℝ, 0 < r ∧ ball 0 r ⊆ s := Metric.mem_nhds_iff.1 s_nhds exact isBounded_closedBall.subset (((strongDualPairing 𝕜 E).flip.polar_antitone r_ball).trans <| polar_ball_subset_closedBall_div ha r_pos) theorem sInter_polar_eq_closedBall {𝕜 E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] {r : ℝ} (hr : 0 < r) : ⋂₀ (StrongDual.polar 𝕜 '' { F | F.Finite ∧ F ⊆ closedBall (0 : E) r⁻¹ }) = closedBall 0 r := by conv_rhs => rw [← inv_inv r] rw [← polar_closedBall (inv_pos_of_pos hr), StrongDual.polar, (strongDualPairing 𝕜 E).flip.sInter_polar_finite_subset_eq_polar (closedBall (0 : E) r⁻¹)] end PolarSets end NormedSpace namespace LinearMap section NormedField variable {𝕜 E F : Type*} variable [NormedField 𝕜] [NormedSpace ℝ 𝕜] [AddCommMonoid E] [AddCommMonoid F] variable [Module 𝕜 E] [Module 𝕜 F] variable {B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜} (s : Set E) variable [Module ℝ F] [IsScalarTower ℝ 𝕜 F] [IsScalarTower ℝ 𝕜 𝕜] theorem polar_AbsConvex : AbsConvex 𝕜 (B.polar s) := by rw [polar_eq_biInter_preimage] exact AbsConvex.iInter₂ fun i hi => ⟨balanced_closedBall_zero.mulActionHom_preimage (f := (B i : (F →ₑ[(RingHom.id 𝕜)] 𝕜))), (convex_closedBall _ _).linear_preimage (B i)⟩ end NormedField end LinearMap
Shift.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory import Mathlib.Algebra.Ring.NegOnePow import Mathlib.CategoryTheory.Shift.Quotient import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.Tactic.Linarith /-! # The shift on cochain complexes and on the homotopy category In this file, we show that for any preadditive category `C`, the categories `CochainComplex C ℤ` and `HomotopyCategory C (ComplexShape.up ℤ)` are equipped with a shift by `ℤ`. We also show that if `F : C ⥤ D` is an additive functor, then the functors `F.mapHomologicalComplex (ComplexShape.up ℤ)` and `F.mapHomotopyCategory (ComplexShape.up ℤ)` commute with the shift by `ℤ`. -/ assert_not_exists TwoSidedIdeal universe v v' u u' open CategoryTheory variable (C : Type u) [Category.{v} C] [Preadditive C] {D : Type u'} [Category.{v'} D] [Preadditive D] namespace CochainComplex open HomologicalComplex /-- The shift functor by `n : ℤ` on `CochainComplex C ℤ` which sends a cochain complex `K` to the complex which is `K.X (i + n)` in degree `i`, and which multiplies the differentials by `(-1)^n`. -/ @[simps] def shiftFunctor (n : ℤ) : CochainComplex C ℤ ⥤ CochainComplex C ℤ where obj K := { X := fun i => K.X (i + n) d := fun _ _ => n.negOnePow • K.d _ _ d_comp_d' := by intros simp only [Linear.comp_units_smul, Linear.units_smul_comp, d_comp_d, smul_zero] shape := fun i j hij => by rw [K.shape, smul_zero] intro hij' apply hij dsimp at hij' ⊢ omega } map φ := { f := fun _ => φ.f _ comm' := by intros dsimp simp only [Linear.comp_units_smul, Hom.comm, Linear.units_smul_comp] } map_id := by intros; rfl map_comp := by intros; rfl instance (n : ℤ) : (shiftFunctor C n).Additive where variable {C} /-- The canonical isomorphism `((shiftFunctor C n).obj K).X i ≅ K.X m` when `m = i + n`. -/ @[simp] def shiftFunctorObjXIso (K : CochainComplex C ℤ) (n i m : ℤ) (hm : m = i + n) : ((shiftFunctor C n).obj K).X i ≅ K.X m := K.XIsoOfEq hm.symm section variable (C) attribute [local simp] XIsoOfEq_hom_naturality /-- The shift functor by `n` on `CochainComplex C ℤ` identifies to the identity functor when `n = 0`. -/ @[simps!] def shiftFunctorZero' (n : ℤ) (h : n = 0) : shiftFunctor C n ≅ 𝟭 _ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by omega)) (fun _ _ _ => by simp [h])) (fun _ ↦ by ext; simp) /-- The compatibility of the shift functors on `CochainComplex C ℤ` with respect to the addition of integers. -/ @[simps!] def shiftFunctorAdd' (n₁ n₂ n₁₂ : ℤ) (h : n₁ + n₂ = n₁₂) : shiftFunctor C n₁₂ ≅ shiftFunctor C n₁ ⋙ shiftFunctor C n₂ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by omega)) (fun _ _ _ => by subst h dsimp simp only [add_comm n₁ n₂, Int.negOnePow_add, Linear.units_smul_comp, Linear.comp_units_smul, d_comp_XIsoOfEq_hom, smul_smul, XIsoOfEq_hom_comp_d])) (by intros; ext; simp) attribute [local simp] XIsoOfEq instance : HasShift (CochainComplex C ℤ) ℤ := hasShiftMk _ _ { F := shiftFunctor C zero := shiftFunctorZero' C _ rfl add := fun n₁ n₂ => shiftFunctorAdd' C n₁ n₂ _ rfl } instance (n : ℤ) : (CategoryTheory.shiftFunctor (HomologicalComplex C (ComplexShape.up ℤ)) n).Additive := (inferInstance : (CochainComplex.shiftFunctor C n).Additive) end @[simp] lemma shiftFunctor_obj_X' (K : CochainComplex C ℤ) (n p : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).X p = K.X (p + n) := rfl @[simp] lemma shiftFunctor_map_f' {K L : CochainComplex C ℤ} (φ : K ⟶ L) (n p : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).map φ).f p = φ.f (p + n) := rfl @[simp] lemma shiftFunctor_obj_d' (K : CochainComplex C ℤ) (n i j : ℤ) : ((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).d i j = n.negOnePow • K.d _ _ := rfl lemma shiftFunctorAdd_inv_app_f (K : CochainComplex C ℤ) (a b n : ℤ) : ((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := rfl lemma shiftFunctorAdd_hom_app_f (K : CochainComplex C ℤ) (a b n : ℤ) : ((shiftFunctorAdd (CochainComplex C ℤ) a b).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := by tauto lemma shiftFunctorAdd'_inv_app_f' (K : CochainComplex C ℤ) (a b ab : ℤ) (h : a + b = ab) (n : ℤ) : ((CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b ab h).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_inv_app_f] lemma shiftFunctorAdd'_hom_app_f' (K : CochainComplex C ℤ) (a b ab : ℤ) (h : a + b = ab) (n : ℤ) : ((CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b ab h).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_hom_app_f] lemma shiftFunctorZero_inv_app_f (K : CochainComplex C ℤ) (n : ℤ) : ((CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_zero])).hom := rfl lemma shiftFunctorZero_hom_app_f (K : CochainComplex C ℤ) (n : ℤ) : ((CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_zero])).hom := by tauto lemma XIsoOfEq_shift (K : CochainComplex C ℤ) (n : ℤ) {p q : ℤ} (hpq : p = q) : (K⟦n⟧).XIsoOfEq hpq = K.XIsoOfEq (show p + n = q + n by rw [hpq]) := rfl variable (C) lemma shiftFunctorAdd'_eq (a b c : ℤ) (h : a + b = c) : CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b c h = shiftFunctorAdd' C a b c h := by ext simp only [shiftFunctorAdd'_hom_app_f', XIsoOfEq, eqToIso.hom, shiftFunctorAdd'_hom_app_f] lemma shiftFunctorAdd_eq (a b : ℤ) : CategoryTheory.shiftFunctorAdd (CochainComplex C ℤ) a b = shiftFunctorAdd' C a b _ rfl := by rw [← CategoryTheory.shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd'_eq] lemma shiftFunctorZero_eq : CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ = shiftFunctorZero' C 0 rfl := by ext rw [shiftFunctorZero_hom_app_f, shiftFunctorZero'_hom_app_f] variable {C} lemma shiftFunctorComm_hom_app_f (K : CochainComplex C ℤ) (a b p : ℤ) : ((shiftFunctorComm (CochainComplex C ℤ) a b).hom.app K).f p = (K.XIsoOfEq (show p + b + a = p + a + b by rw [add_assoc, add_comm b, add_assoc])).hom := by rw [shiftFunctorComm_eq _ _ _ _ rfl] dsimp rw [shiftFunctorAdd'_inv_app_f', shiftFunctorAdd'_hom_app_f'] simp only [XIsoOfEq, eqToIso.hom, eqToHom_trans] variable (C) attribute [local simp] XIsoOfEq_hom_naturality /-- Shifting cochain complexes by `n` and evaluating in a degree `i` identifies to the evaluation in degree `i'` when `n + i = i'`. -/ @[simps!] def shiftEval (n i i' : ℤ) (hi : n + i = i') : (CategoryTheory.shiftFunctor (CochainComplex C ℤ) n) ⋙ HomologicalComplex.eval C (ComplexShape.up ℤ) i ≅ HomologicalComplex.eval C (ComplexShape.up ℤ) i' := NatIso.ofComponents (fun K => K.XIsoOfEq (by dsimp; rw [← hi, add_comm i])) (by intros; simp) end CochainComplex namespace CategoryTheory open Category namespace Functor variable {C} variable (F : C ⥤ D) [F.Additive] attribute [local simp] Functor.map_zsmul /-- The commutation with the shift isomorphism for the functor on cochain complexes induced by an additive functor between preadditive categories. -/ @[simps!] def mapCochainComplexShiftIso (n : ℤ) : shiftFunctor _ n ⋙ F.mapHomologicalComplex (ComplexShape.up ℤ) ≅ F.mapHomologicalComplex (ComplexShape.up ℤ) ⋙ shiftFunctor _ n := NatIso.ofComponents (fun K => HomologicalComplex.Hom.isoOfComponents (fun _ => Iso.refl _) (by simp)) (fun _ => by ext; dsimp; rw [id_comp, comp_id]) instance commShiftMapCochainComplex : (F.mapHomologicalComplex (ComplexShape.up ℤ)).CommShift ℤ where iso := F.mapCochainComplexShiftIso zero := by ext rw [CommShift.isoZero_hom_app] dsimp simp only [CochainComplex.shiftFunctorZero_inv_app_f, CochainComplex.shiftFunctorZero_hom_app_f, HomologicalComplex.XIsoOfEq, eqToIso, eqToHom_map, eqToHom_trans, eqToHom_refl] add := fun a b => by ext rw [CommShift.isoAdd_hom_app] dsimp rw [id_comp, id_comp] simp only [CochainComplex.shiftFunctorAdd_hom_app_f, CochainComplex.shiftFunctorAdd_inv_app_f, HomologicalComplex.XIsoOfEq, eqToIso, eqToHom_map, eqToHom_trans, eqToHom_refl] lemma mapHomologicalComplex_commShiftIso_eq (n : ℤ) : (F.mapHomologicalComplex (ComplexShape.up ℤ)).commShiftIso n = F.mapCochainComplexShiftIso n := rfl @[simp] lemma mapHomologicalComplex_commShiftIso_hom_app_f (K : CochainComplex C ℤ) (n i : ℤ) : (((F.mapHomologicalComplex (ComplexShape.up ℤ)).commShiftIso n).hom.app K).f i = 𝟙 _ := rfl @[simp] lemma mapHomologicalComplex_commShiftIso_inv_app_f (K : CochainComplex C ℤ) (n i : ℤ) : (((F.mapHomologicalComplex (ComplexShape.up ℤ)).commShiftIso n).inv.app K).f i = 𝟙 _ := rfl end Functor end CategoryTheory namespace Homotopy variable {C} /-- If `h : Homotopy φ₁ φ₂` and `n : ℤ`, this is the induced homotopy between `φ₁⟦n⟧'` and `φ₂⟦n⟧'`. -/ def shift {K L : CochainComplex C ℤ} {φ₁ φ₂ : K ⟶ L} (h : Homotopy φ₁ φ₂) (n : ℤ) : Homotopy (φ₁⟦n⟧') (φ₂⟦n⟧') where hom _ _ := n.negOnePow • h.hom _ _ zero i j hij := by dsimp rw [h.zero, smul_zero] intro hij' dsimp at hij hij' omega comm := fun i => by rw [dNext_eq _ (show (ComplexShape.up ℤ).Rel i (i + 1) by simp), prevD_eq _ (show (ComplexShape.up ℤ).Rel (i - 1) i by simp)] dsimp simpa only [Linear.units_smul_comp, Linear.comp_units_smul, smul_smul, Int.units_mul_self, one_smul, dNext_eq _ (show (ComplexShape.up ℤ).Rel (i + n) (i + 1 + n) by dsimp; omega), prevD_eq _ (show (ComplexShape.up ℤ).Rel (i - 1 + n) (i + n) by dsimp; omega)] using h.comm (i + n) end Homotopy namespace HomotopyCategory instance : (homotopic C (ComplexShape.up ℤ)).IsCompatibleWithShift ℤ := ⟨fun n _ _ _ _ ⟨h⟩ => ⟨h.shift n⟩⟩ noncomputable instance hasShift : HasShift (HomotopyCategory C (ComplexShape.up ℤ)) ℤ := by dsimp only [HomotopyCategory] infer_instance noncomputable instance commShiftQuotient : (HomotopyCategory.quotient C (ComplexShape.up ℤ)).CommShift ℤ := Quotient.functor_commShift (homotopic C (ComplexShape.up ℤ)) ℤ instance (n : ℤ) : (shiftFunctor (HomotopyCategory C (ComplexShape.up ℤ)) n).Additive := by have : ((quotient C (ComplexShape.up ℤ) ⋙ shiftFunctor _ n)).Additive := Functor.additive_of_iso ((quotient C (ComplexShape.up ℤ)).commShiftIso n) apply Functor.additive_of_full_essSurj_comp (quotient _ _ ) section variable {C} variable (F : C ⥤ D) [F.Additive] noncomputable instance : (F.mapHomotopyCategory (ComplexShape.up ℤ)).CommShift ℤ := Quotient.liftCommShift _ _ _ _ instance : NatTrans.CommShift (F.mapHomotopyCategoryFactors (ComplexShape.up ℤ)).hom ℤ := Quotient.liftCommShift_compatibility _ _ _ _ end end HomotopyCategory
alt.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice. From mathcomp Require Import div fintype tuple tuple bigop prime finset ssralg. From mathcomp Require Import zmodp fingroup morphism perm automorphism quotient. From mathcomp Require Import action cyclic pgroup gseries sylow. From mathcomp Require Import primitive_action nilpotent maximal. (******************************************************************************) (* Definitions of the symmetric and alternate groups, and some properties. *) (* 'Sym_T == The symmetric group over type T (which must have a finType *) (* structure). *) (* := [set: {perm T}] *) (* 'Alt_T == The alternating group over type T. *) (******************************************************************************) Unset Printing Implicit Defensive. Set Implicit Arguments. Unset Strict Implicit. Import GroupScope GRing. HB.instance Definition _ := isMulGroup.Build bool addbA addFb addbb. Section SymAltDef. Variable T : finType. Implicit Types (s : {perm T}) (x y z : T). (** Definitions of the alternate groups and some Properties **) Definition Sym : {set {perm T}} := setT. Canonical Sym_group := Eval hnf in [group of Sym]. Local Notation "'Sym_T" := Sym. Canonical sign_morph := @Morphism _ _ 'Sym_T _ (in2W (@odd_permM _)). Definition Alt := 'ker (@odd_perm T). Canonical Alt_group := Eval hnf in [group of Alt]. Local Notation "'Alt_T" := Alt. Lemma Alt_even p : (p \in 'Alt_T) = ~~ p. Proof. by rewrite !inE /=; case: odd_perm. Qed. Lemma Alt_subset : 'Alt_T \subset 'Sym_T. Proof. exact: subsetT. Qed. Lemma Alt_normal : 'Alt_T <| 'Sym_T. Proof. exact: ker_normal. Qed. Lemma Alt_norm : 'Sym_T \subset 'N('Alt_T). Proof. by case/andP: Alt_normal. Qed. Let n := #|T|. Lemma Alt_index : 1 < n -> #|'Sym_T : 'Alt_T| = 2. Proof. move=> lt1n; rewrite -card_quotient ?Alt_norm //=. have : ('Sym_T / 'Alt_T) \isog (@odd_perm T @* 'Sym_T) by apply: first_isog. case/isogP=> g /injmP/card_in_imset <-. rewrite /morphim setIid=> ->; rewrite -card_bool; apply: eq_card => b. apply/imsetP; case: b => /=; last first. by exists (1 : {perm T}); [rewrite setIid inE | rewrite odd_perm1]. case: (pickP T) lt1n => [x1 _ | d0]; last by rewrite /n eq_card0. rewrite /n (cardD1 x1) ltnS lt0n => /existsP[x2 /=]. by rewrite eq_sym andbT -odd_tperm; exists (tperm x1 x2); rewrite ?inE. Qed. Lemma card_Sym : #|'Sym_T| = n`!. Proof. rewrite -[n]cardsE -card_perm; apply: eq_card => p. by apply/idP/subsetP=> [? ?|]; rewrite !inE. Qed. Lemma card_Alt : 1 < n -> (2 * #|'Alt_T|)%N = n`!. Proof. by move/Alt_index <-; rewrite mulnC (Lagrange Alt_subset) card_Sym. Qed. Lemma Sym_trans : [transitive^n 'Sym_T, on setT | 'P]. Proof. apply/imsetP; pose t1 := [tuple of enum T]. have dt1: t1 \in n.-dtuple(setT) by rewrite inE enum_uniq; apply/subsetP. exists t1 => //; apply/setP=> t; apply/idP/imsetP=> [|[a _ ->{t}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> x; rewrite !inE. case/dtuple_onP=> injt _; have injf := inj_comp injt enum_rank_inj. exists (perm injf); first by rewrite inE. apply: eq_from_tnth => i; rewrite tnth_map /= [aperm _ _]permE; congr tnth. by rewrite (tnth_nth (enum_default i)) enum_valK. Qed. Lemma Alt_trans : [transitive^n.-2 'Alt_T, on setT | 'P]. Proof. case n_m2: n Sym_trans => [|[|m]] /= tr_m2; try exact: ntransitive0. have tr_m := ntransitive_weak (leqW (leqnSn m)) tr_m2. case/imsetP: tr_m2; case/tupleP=> x; case/tupleP=> y t. rewrite !dtuple_on_add 2![x \in _]inE inE negb_or /= -!andbA. case/and4P=> nxy ntx nty dt _; apply/imsetP; exists t => //; apply/setP=> u. apply/idP/imsetP=> [|[a _ ->{u}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> z; rewrite !inE. case/(atransP2 tr_m dt)=> /= a _ ->{u}. case odd_a: (odd_perm a); last by exists a => //; rewrite !inE /= odd_a. exists (tperm x y * a); first by rewrite !inE /= odd_permM odd_tperm nxy odd_a. apply/val_inj/eq_in_map => z tz; rewrite actM /= /aperm; congr (a _). by case: tpermP ntx nty => // <-; rewrite tz. Qed. Lemma aperm_faithful (A : {group {perm T}}) : [faithful A, on setT | 'P]. Proof. by apply/faithfulP=> /= p _ np1; apply/eqP/perm_act1P=> y; rewrite np1 ?inE. Qed. End SymAltDef. Arguments Sym T%_type. Arguments Sym_group T%_type. Arguments Alt T%_type. Arguments Alt_group T%_type. Notation "''Sym_' T" := (Sym T) (at level 8, T at level 2, format "''Sym_' T") : group_scope. Notation "''Sym_' T" := (Sym_group T) : Group_scope. Notation "''Alt_' T" := (Alt T) (at level 8, T at level 2, format "''Alt_' T") : group_scope. Notation "''Alt_' T" := (Alt_group T) : Group_scope. Lemma trivial_Alt_2 (T : finType) : #|T| <= 2 -> 'Alt_T = 1. Proof. rewrite leq_eqVlt => /predU1P[] oT. by apply: card_le1_trivg; rewrite -leq_double -mul2n card_Alt oT. suffices Sym1: 'Sym_T = 1 by apply/trivgP; rewrite -Sym1 subsetT. by apply: card1_trivg; rewrite card_Sym; case: #|T| oT; do 2?case. Qed. Lemma simple_Alt_3 (T : finType) : #|T| = 3 -> simple 'Alt_T. Proof. move=> T3; have{T3} oA: #|'Alt_T| = 3. by apply: double_inj; rewrite -mul2n card_Alt T3. apply/simpleP; split=> [|K]; [by rewrite trivg_card1 oA | case/andP=> sKH _]. have:= cardSg sKH; rewrite oA dvdn_divisors // !inE orbC /= -oA. case/pred2P=> eqK; [right | left]; apply/eqP. by rewrite eqEcard sKH eqK leqnn. by rewrite eq_sym eqEcard sub1G eqK cards1. Qed. Lemma not_simple_Alt_4 (T : finType) : #|T| = 4 -> ~~ simple 'Alt_T. Proof. move=> oT; set A := 'Alt_T. have oA: #|A| = 12 by apply: double_inj; rewrite -mul2n card_Alt oT. suffices [p]: exists p, [/\ prime p, 1 < #|A|`_p < #|A| & #|'Syl_p(A)| == 1%N]. case=> p_pr pA_int; rewrite /A; case/normal_sylowP=> P; case/pHallP. rewrite /= -/A => sPA pP nPA; apply/simpleP=> [] [_]; rewrite -pP in pA_int. by case/(_ P)=> // defP; rewrite defP oA ?cards1 in pA_int. have: #|'Syl_3(A)| \in filter [pred d | d %% 3 == 1%N] (divisors 12). by rewrite mem_filter -dvdn_divisors //= -oA card_Syl_dvd ?card_Syl_mod. rewrite /= oA mem_seq2 orbC. case/predU1P=> [oQ3|]; [exists 2 | exists 3]; split; rewrite ?p_part //. pose A3 := [set x : {perm T} | #[x] == 3]; suffices oA3: #|A :&: A3| = 8. have sQ2 P: P \in 'Syl_2(A) -> P :=: A :\: A3. rewrite inE pHallE oA p_part -natTrecE /= => /andP[sPA /eqP oP]. apply/eqP; rewrite eqEcard -(leq_add2l 8) -{1}oA3 cardsID oA oP. rewrite andbT subsetD sPA; apply/exists_inP=> -[x] /= Px. by rewrite inE => /eqP ox; have:= order_dvdG Px; rewrite oP ox. have [/= P sylP] := Sylow_exists 2 [group of A]. rewrite -(([set P] =P 'Syl_2(A)) _) ?cards1 // eqEsubset sub1set inE sylP. by apply/subsetP=> Q sylQ; rewrite inE -val_eqE /= !sQ2 // inE. rewrite -[8]/(4 * 2)%N -{}oQ3 -sum1_card -sum_nat_const. rewrite (partition_big (fun x => <[x]>%G) [in 'Syl_3(A)]) => [|x]; last first. by case/setIP=> Ax; rewrite /= !inE pHallE p_part cycle_subG Ax oA. apply: eq_bigr => Q; rewrite inE pHallE oA p_part -?natTrecE //=. case/andP=> sQA /eqP oQ; have:= oQ. rewrite (cardsD1 1) group1 -sum1_card => [[/= <-]]; apply: eq_bigl => x. rewrite setIC -val_eqE /= 2!inE in_setD1 -andbA -{4}[x]expg1 -order_dvdn dvdn1. apply/and3P/andP=> [[/eqP-> _ /eqP <-] | [ntx Qx]]; first by rewrite cycle_id. have:= order_dvdG Qx; rewrite oQ dvdn_divisors // mem_seq2 (negPf ntx) /=. by rewrite eqEcard cycle_subG Qx (subsetP sQA) // oQ /order => /eqP->. Qed. Lemma simple_Alt5_base (T : finType) : #|T| = 5 -> simple 'Alt_T. Proof. move=> oT. have F1: #|'Alt_T| = 60 by apply: double_inj; rewrite -mul2n card_Alt oT. have FF (H : {group {perm T}}): H <| 'Alt_T -> H :<>: 1 -> 20 %| #|H|. - move=> Hh1 Hh3. have [x _]: exists x, x \in T by apply/existsP/eqP; rewrite oT. have F2 := Alt_trans T; rewrite oT /= in F2. have F3: [transitive 'Alt_T, on setT | 'P] by apply: ntransitive1 F2. have F4: [primitive 'Alt_T, on setT | 'P] by apply: ntransitive_primitive F2. case: (prim_trans_norm F4 Hh1) => F5. by case: Hh3; apply/trivgP; apply: subset_trans F5 (aperm_faithful _). have F6: 5 %| #|H| by rewrite -oT -cardsT (atrans_dvd F5). have F7: 4 %| #|H|. have F7: #|[set~ x]| = 4 by rewrite cardsC1 oT. case: (pickP [in [set~ x]]) => [y Hy | ?]; last by rewrite eq_card0 in F7. pose K := 'C_H[x | 'P]%G. have F8 : K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]%G. have F9: [transitive^2 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. exact: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. exact: ntransitive_primitive F9. have F12: K \subset Gx by apply: setSI; apply: normal_sub. have F13: K <| Gx by rewrite /(K <| _) F12 normsIG // normal_norm. case: (prim_trans_norm F11 F13) => Ksub; last first. by apply: dvdn_trans (cardSg F8); rewrite -F7; apply: atrans_dvd Ksub. have F14: [faithful Gx, on [set~ x] | 'P]. apply/subsetP=> g; do 2![case/setIP] => Altg cgx cgx'. apply: (subsetP (aperm_faithful 'Alt_T)). rewrite inE Altg /=; apply/astabP=> z _. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> nxz; rewrite (astabP cgx') ?inE //. have Hreg g (z : T): g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite (trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by case/normalP: Hh1 => _ nH1; rewrite -(nH1 _ Hg1) memJ_conjg. clear K F8 F12 F13 Ksub F14. case: (Cauchy _ F6) => // h Hh /eqP Horder. have diff_hnx_x n: 0 < n -> n < 5 -> x != (h ^+ n) x. move=> Hn1 Hn2; rewrite eq_sym; apply/negP => HH. have: #[h ^+ n] = 5. rewrite orderXgcd // (eqP Horder). by move: Hn1 Hn2 {HH}; do 5 (case: n => [|n] //). have Hhd2: h ^+ n \in H by rewrite groupX. by rewrite (Hreg _ _ Hhd2 (eqP HH)) order1. pose S1 := [tuple x; h x; (h ^+ 3) x]. have DnS1: S1 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. pose S2 := [tuple x; h x; (h ^+ 2) x]. have DnS2: S2 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. case: (atransP2 F2 DnS1 DnS2) => g Hg [/=]. rewrite /aperm => Hgx Hghx Hgh3x. have h_g_com: h * g = g * h. suff HH: (g * h * g^-1) * h^-1 = 1 by rewrite -[h * g]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hgx Hghx -!permM mulKVg mulgV perm1. rewrite groupM // ?groupV // (conjgCV g) mulgK -mem_conjg. by case/normalP: Hh1 => _ ->. have: (g * (h ^+ 2) * g ^-1) x = (h ^+ 3) x. rewrite !permM -Hgx. have ->: h (h x) = (h ^+ 2) x by rewrite /= permM. by rewrite {1}Hgh3x -!permM /= mulgV mulg1 -expgSr. rewrite commuteX // mulgK {1}[expgn]lock expgS permM -lock. by move/perm_inj=> eqxhx; case/eqP: (diff_hnx_x 1%N isT isT); rewrite expg1. by rewrite (@Gauss_dvd 4 5) // F7. apply/simpleP; split => [|H Hnorm]; first by rewrite trivg_card1 F1. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case Hcard60: (#|H| == 60); move/eqP: Hcard60 => Hcard60. by apply/eqP; rewrite eqEcard Hcard60 F1 andbT; case/andP: Hnorm. have {Hcard1 Hcard60} Hcard20: #|H| = 20. have Hdiv: 20 %| #|H| by apply: FF => // HH; case Hcard1; rewrite HH cards1. case H20: (#|H| == 20); first exact/eqP. case: Hcard60; case/andP: Hnorm; move/cardSg; rewrite F1 => Hdiv1 _. by case/dvdnP: Hdiv H20 Hdiv1 => n ->; move: n; do 4!case=> //. have prime_5: prime 5 by []. have nSyl5: #|'Syl_5(H)| = 1%N. move: (card_Syl_dvd 5 H) (card_Syl_mod H prime_5). rewrite Hcard20; case: (card _) => // n Hdiv. move: (dvdn_leq (isT: (0 < 20)%N) Hdiv). by move: (n) Hdiv; do 20 (case=> //). case: (Sylow_exists 5 H) => S; case/pHallP=> sSH oS. have{} oS: #|S| = 5 by rewrite oS p_part Hcard20. suff: 20 %| #|S| by rewrite oS. apply: FF => [|S1]; last by rewrite S1 cards1 in oS. apply: char_normal_trans Hnorm; apply: lone_subgroup_char => // Q sQH isoQS. rewrite subEproper; apply/norP=> [[nQS _]]; move: nSyl5. rewrite (cardsD1 S) (cardsD1 Q) 4!{1}inE nQS !pHallE sQH sSH Hcard20 p_part. by rewrite (card_isog isoQS) oS. Qed. Section Restrict. Variables (T : finType) (x : T). Notation T' := {y | y != x}. Lemma rfd_funP (p : {perm T}) (u : T') : let p1 := if p x == x then p else 1 in p1 (val u) != x. Proof. case: (p x =P x) => /= [pxx | _]; last by rewrite perm1 (valP u). by rewrite -[x in _ != x]pxx (inj_eq perm_inj); apply: (valP u). Qed. Definition rfd_fun p := [fun u => Sub ((_ : {perm T}) _) (rfd_funP p u) : T']. Lemma rfdP p : injective (rfd_fun p). Proof. apply: can_inj (rfd_fun p^-1) _ => u; apply: val_inj => /=. rewrite -(can_eq (permK p)) permKV eq_sym. by case: eqP => _; rewrite !(perm1, permK). Qed. Definition rfd p := perm (@rfdP p). Hypothesis card_T : 2 < #|T|. Lemma rfd_morph : {in 'C_('Sym_T)[x | 'P] &, {morph rfd : y z / y * z}}. Proof. move=> p q; rewrite !setIA !setIid; move/astab1P=> p_x; move/astab1P=> q_x. apply/permP=> u; apply: val_inj. by rewrite permE /= !permM !permE /= [p x]p_x [q x]q_x eqxx permM /=. Qed. Canonical rfd_morphism := Morphism rfd_morph. Definition rgd_fun (p : {perm T'}) := [fun x1 => if insub x1 is Some u then sval (p u) else x]. Lemma rgdP p : injective (rgd_fun p). Proof. apply: can_inj (rgd_fun p^-1) _ => y /=. case: (insubP _ y) => [u _ val_u|]; first by rewrite valK permK. by rewrite negbK; move/eqP->; rewrite insubF //= eqxx. Qed. Definition rgd p := perm (@rgdP p). Lemma rfd_odd (p : {perm T}) : p x = x -> rfd p = p :> bool. Proof. have rfd1: rfd 1 = 1. by apply/permP => u; apply: val_inj; rewrite permE /= if_same !perm1. have [n] := ubnP #|[set x | p x != x]|; elim: n p => // n IHn p le_p_n px_x. have [p_id | [x1 Hx1]] := set_0Vmem [set x | p x != x]. suffices ->: p = 1 by rewrite rfd1 !odd_perm1. by apply/permP => z; apply: contraFeq (in_set0 z); rewrite perm1 -p_id inE. have nx1x: x1 != x by apply: contraTneq Hx1 => ->; rewrite inE px_x eqxx. have npxx1: p x != x1 by apply: contraNneq nx1x => <-; rewrite px_x. have npx1x: p x1 != x by rewrite -px_x (inj_eq perm_inj). pose p1 := p * tperm x1 (p x1). have fix_p1 y: p y = y -> p1 y = y. by move=> pyy; rewrite permM; have [<-|/perm_inj<-|] := tpermP; rewrite ?pyy. have p1x_x: p1 x = x by apply: fix_p1. have{le_p_n} lt_p1_n: #|[set x | p1 x != x]| < n. move: le_p_n; rewrite ltnS (cardsD1 x1) Hx1; apply/leq_trans/subset_leq_card. rewrite subsetD1 inE permM tpermR eqxx andbT. by apply/subsetP=> y /[!inE]; apply: contraNneq=> /fix_p1->. transitivity (p1 (+) true); last first. by rewrite odd_permM odd_tperm -Hx1 inE eq_sym addbK. have ->: p = p1 * tperm x1 (p x1) by rewrite -tpermV mulgK. rewrite morphM; last 2 first; first by rewrite 2!inE; apply/astab1P. by rewrite 2!inE; apply/astab1P; rewrite -[RHS]p1x_x permM px_x. rewrite odd_permM IHn //=; congr (_ (+) _). pose x2 : T' := Sub x1 nx1x; pose px2 : T' := Sub (p x1) npx1x. suffices ->: rfd (tperm x1 (p x1)) = tperm x2 px2. by rewrite odd_tperm eq_sym; rewrite inE in Hx1. apply/permP => z; apply/val_eqP; rewrite permE /= tpermD // eqxx. by rewrite !permE /= -!val_eqE /= !(fun_if sval) /=. Qed. Lemma rfd_iso : 'C_('Alt_T)[x | 'P] \isog 'Alt_T'. Proof. have rgd_x p: rgd p x = x by rewrite permE /= insubF //= eqxx. have rfd_rgd p: rfd (rgd p) = p. apply/permP => [[z Hz]]; apply/val_eqP; rewrite !permE. by rewrite /= [rgd _ _]permE /= insubF eqxx // permE /= insubT. have sSd: 'C_('Alt_T)[x | 'P] \subset 'dom rfd. by apply/subsetP=> p /[!inE]/= /andP[]. apply/isogP; exists [morphism of restrm sSd rfd] => /=; last first. rewrite morphim_restrm setIid; apply/setP=> z; apply/morphimP/idP=> [[p _]|]. case/setIP; rewrite Alt_even => Hp; move/astab1P=> Hp1 ->. by rewrite Alt_even rfd_odd. have dz': rgd z x == x by rewrite rgd_x. move=> kz; exists (rgd z); last by rewrite /= rfd_rgd. by rewrite 2!inE (sameP astab1P eqP). rewrite 4!inE /= (sameP astab1P eqP) dz' -rfd_odd; last exact/eqP. by rewrite rfd_rgd mker // ?set11. apply/injmP=> x1 y1 /=. case/setIP=> Hax1; move/astab1P; rewrite /= /aperm => Hx1. case/setIP=> Hay1; move/astab1P; rewrite /= /aperm => Hy1 Hr. apply/permP => z. case (z =P x) => [->|]; [by rewrite Hx1 | move/eqP => nzx]. move: (congr1 (fun q : {perm T'} => q (Sub z nzx)) Hr). by rewrite !permE => [[]]; rewrite Hx1 Hy1 !eqxx. Qed. End Restrict. Lemma simple_Alt5 (T : finType) : #|T| >= 5 -> simple 'Alt_T. Proof. suff F1 n: #|T| = n + 5 -> simple 'Alt_T by move/subnK/esym/F1. elim: n T => [| n Hrec T Hde]; first exact: simple_Alt5_base. have oT: 5 < #|T| by rewrite Hde addnC. apply/simpleP; split=> [|H Hnorm]; last have [Hh1 nH] := andP Hnorm. rewrite trivg_card1 -[#|_|]half_double -mul2n card_Alt Hde addnC //. by rewrite addSn factS mulnC -(prednK (fact_gt0 _)). case E1: (pred0b T); first by rewrite /pred0b in E1; rewrite (eqP E1) in oT. case/pred0Pn: E1 => x _; have Hx := in_setT x. have F2: [transitive^4 'Alt_T, on setT | 'P]. by apply: ntransitive_weak (Alt_trans T); rewrite -(subnKC oT). have F3 := ntransitive1 (isT: 0 < 4) F2. have F4 := ntransitive_primitive (isT: 1 < 4) F2. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case: (prim_trans_norm F4 Hnorm) => F5. by rewrite (trivGP (subset_trans F5 (aperm_faithful _))) cards1 in Hcard1. case E1: (pred0b (predD1 T x)). rewrite /pred0b in E1; move: oT. by rewrite (cardD1 x) (eqP E1); case: (T x). case/pred0Pn: E1 => y Hdy; case/andP: (Hdy) => diff_x_y Hy. pose K := 'C_H[x | 'P]%G. have F8: K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]. have F9: [transitive^3 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. by apply: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. by apply: ntransitive_primitive F9. have F12: K \subset Gx by rewrite setSI // normal_sub. have F13: K <| Gx by apply/andP; rewrite normsIG. have:= prim_trans_norm F11; case/(_ K) => //= => Ksub; last first. have F14: Gx * H = 'Alt_T by apply/(subgroup_transitiveP _ _ F3). have: simple Gx. by rewrite (isog_simple (rfd_iso x)) Hrec //= card_sig cardC1 Hde. case/simpleP=> _ simGx; case/simGx: F13 => /= HH2. case Ez: (pred0b (predD1 (predD1 T x) y)). move: oT; rewrite /pred0b in Ez. by rewrite (cardD1 x) (cardD1 y) (eqP Ez) inE /= inE /= diff_x_y. case/pred0Pn: Ez => z; case/andP => diff_y_z Hdz. have [diff_x_z Hz] := andP Hdz. have: z \in [set~ x] by rewrite !inE. rewrite -(atransP Ksub y) ?inE //; case/imsetP => g. rewrite /= HH2 inE; move/eqP=> -> HH4. by case/negP: diff_y_z; rewrite HH4 act1. by rewrite /= -F14 -[Gx]HH2 (mulSGid F8). have F14: [faithful Gx, on [set~ x] | 'P]. apply: subset_trans (aperm_faithful 'Sym_T); rewrite subsetI subsetT. apply/subsetP=> g; do 2![case/setIP]=> _ cgx cgx'; apply/astabP=> z _ /=. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> zx; rewrite [_ g](astabP cgx') ?inE. have Hreg g z: g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite [K](trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by rewrite memJ_norm ?(subsetP nH). clear K F8 F12 F13 Ksub F14. have Hcard: 5 < #|H|. apply: (leq_trans oT); apply: dvdn_leq; first exact: cardG_gt0. by rewrite -cardsT (atrans_dvd F5). case Eh: (pred0b [predD1 H & 1]). by move: Hcard; rewrite /pred0b in Eh; rewrite (cardD1 1) group1 (eqP Eh). case/pred0Pn: Eh => h; case/andP => diff_1_h /= Hh. case Eg: (pred0b (predD1 (predD1 [predD1 H & 1] h) h^-1)). move: Hcard; rewrite ltnNge; case/negP. rewrite (cardD1 1) group1 (cardD1 h) (cardD1 h^-1) (eqnP Eg). by do 2!case: (_ \in _). case/pred0Pn: Eg => g; case/andP => diff_h1_g; case/andP => diff_h_g. case/andP => diff_1_g /= Hg. case diff_hx_x: (h x == x). by case/negP: diff_1_h; apply/eqP; apply: (Hreg _ _ Hh (eqP diff_hx_x)). case diff_gx_x: (g x == x). case/negP: diff_1_g; apply/eqP; apply: (Hreg _ _ Hg (eqP diff_gx_x)). case diff_gx_hx: (g x == h x). case/negP: diff_h_g; apply/eqP; symmetry; apply: (mulIg g^-1); rewrite gsimp. apply: (Hreg _ x); first by rewrite groupM // groupV. by rewrite permM -(eqP diff_gx_hx) -permM mulgV perm1. case diff_hgx_x: ((h * g) x == x). case/negP: diff_h1_g; apply/eqP; apply: (mulgI h); rewrite !gsimp. by apply: (Hreg _ x); [apply: groupM | apply/eqP]. case diff_hgx_hx: ((h * g) x == h x). case/negP: diff_1_g; apply/eqP. by apply: (Hreg _ (h x)) => //; apply/eqP; rewrite -permM. case diff_hgx_gx: ((h * g) x == g x). by case/idP: diff_hx_x; rewrite -(can_eq (permK g)) -permM. case Ez: (pred0b (predD1 (predD1 (predD1 (predD1 T x) (h x)) (g x)) ((h * g) x))). - move: oT; rewrite /pred0b in Ez. rewrite (cardD1 x) (cardD1 (h x)) (cardD1 (g x)) (cardD1 ((h * g) x)). by rewrite (eqP Ez) addnC; do 3!case: (_ x \in _). case/pred0Pn: Ez => z. case/and5P=> diff_hgx_z diff_gx_z diff_hx_z diff_x_z /= Hz. pose S1 := [tuple x; h x; g x; z]. have DnS1: S1 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT. rewrite -!(eq_sym z) diff_gx_z diff_x_z diff_hx_z. by rewrite !(eq_sym x) diff_hx_x diff_gx_x eq_sym diff_gx_hx. pose S2 := [tuple x; h x; g x; (h * g) x]. have DnS2: S2 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT !(eq_sym x). rewrite diff_hx_x diff_gx_x diff_hgx_x. by rewrite !(eq_sym (h x)) diff_gx_hx diff_hgx_hx eq_sym diff_hgx_gx. case: (atransP2 F2 DnS1 DnS2) => k Hk [/=]. rewrite /aperm => Hkx Hkhx Hkgx Hkhgx. have h_k_com: h * k = k * h. suff HH: (k * h * k^-1) * h^-1 = 1 by rewrite -[h * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkhx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have g_k_com: g * k = k * g. suff HH: (k * g * k^-1) * g^-1 = 1 by rewrite -[g * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkgx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have HH: (k * (h * g) * k ^-1) x = z. by rewrite 2!permM -Hkx Hkhgx -permM mulgV perm1. case/negP: diff_hgx_z. rewrite -HH !mulgA -h_k_com -!mulgA [k * _]mulgA. by rewrite -g_k_com -!mulgA mulgV mulg1. Qed. Lemma gen_tperm_circular_shift (X : finType) x y c : prime #|X| -> x != y -> #[c]%g = #|X| -> <<[set tperm x y; c]>>%g = ('Sym_X)%g. Proof. move=> Xprime neq_xy ord_c; apply/eqP; rewrite eqEsubset subsetT/=. have c_gt1 : (1 < #[c]%g)%N by rewrite ord_c prime_gt1. have cppSS : #[c]%g.-2.+2 = #|X| by rewrite ?prednK ?ltn_predRL. pose f (i : 'Z_#[c]%g) : X := Zpm i x. have [g fK gK] : bijective f. apply: inj_card_bij; rewrite ?cppSS ?card_ord// /f /Zpm => i j cijx. pose stabx := ('C_<[c]>[x | 'P])%g. have cjix : (c ^+ (j - i)%R)%g x = x. by apply: (@perm_inj _ (c ^+ i)%g); rewrite -permM -expgD_Zp// addrNK. have : (c ^+ (j - i)%R)%g \in stabx. by rewrite !inE ?groupX ?mem_gen ?sub1set ?inE// ['P%act _ _]cjix eqxx. rewrite [stabx]perm_prime_astab// => /set1gP. move=> /(congr1 (mulg (c ^+ i))); rewrite -expgD_Zp// addrC addrNK mulg1. by move=> /eqP; rewrite eq_expg_ord// ?cppSS ?ord_c// => /eqP->. pose gsf s := g \o s \o f. have gsf_inj (s : {perm X}) : injective (gsf s). apply: inj_comp; last exact: can_inj fK. by apply: inj_comp; [exact: can_inj gK|exact: perm_inj]. pose fsg s := f \o s \o g. have fsg_inj (s : {perm _}) : injective (fsg s). apply: inj_comp; last exact: can_inj gK. by apply: inj_comp; [exact: can_inj fK|exact: perm_inj]. have gsf_morphic : morphic 'Sym_X (fun s => perm (gsf_inj s)). apply/morphicP => u v _ _; apply/permP => /= i. by rewrite !permE/= !permE /gsf /= gK permM. pose phi := morphm gsf_morphic; rewrite /= in phi. have phi_inj : ('injm phi)%g. apply/subsetP => /= u /mker/=; rewrite morphmE => gsfu1. apply/set1gP/permP=> z; have /permP/(_ (g z)) := gsfu1. by rewrite !perm1 permE /gsf/= gK => /(can_inj gK). have phiT : (phi @* 'Sym_X)%g = [set: {perm 'Z_#[c]%g}]. apply/eqP; rewrite eqEsubset subsetT/=; apply/subsetP => /= u _. apply/morphimP; exists (perm (fsg_inj u)); rewrite ?in_setT//. by apply/permP => /= i; rewrite morphmE permE /gsf/fsg/= permE/= !fK. have f0 : f 0%R = x by rewrite /f /Zpm permX. pose k := g y; have k_gt0 : (k > 0)%N. by rewrite lt0n (val_eqE k 0%R) -(can_eq fK) eq_sym gK f0. have phixy : phi (tperm x y) = tperm (0%R : 'Z_#[c]) k. apply/permP => i; rewrite permE/= /gsf/=; apply: (canLR fK). by rewrite !permE/= -f0 -[y]gK !(can_eq fK) -!fun_if. have phic : phi c = perm (addrI (1%R : 'Z_#[c])). apply/permP => i; rewrite /phi morphmE !permE /gsf/=; apply: (canLR fK). by rewrite /f /Zpm -permM addrC expgD_Zp. rewrite -(injmSK phi_inj)//= morphim_gen/= ?subsetT//= -/phi. rewrite phiT /morphim !setTI/= -/phi imsetU1 imset_set1/= phixy phic. suff /gen_tpermn_circular_shift<- : coprime #[c]%g.-2.+2 (k - 0)%R by []. by rewrite subr0 prime_coprime ?gtnNdvd// ?cppSS. Qed. Section Perm_solvable. Local Open Scope nat_scope. Variable T : finType. Lemma solvable_AltF : 4 < #|T| -> solvable 'Alt_T = false. Proof. move=> card_T; apply/negP => Alt_solvable. have/simple_Alt5 Alt_simple := card_T. have := simple_sol_prime Alt_solvable Alt_simple. have lt_T n : n <= 4 -> n < #|T| by move/leq_ltn_trans; apply. have -> : #|('Alt_T)%G| = #|T|`! %/ 2 by rewrite -card_Alt ?mulKn ?lt_T. move/even_prime => [/eqP|]; apply/negP. rewrite neq_ltn leq_divRL // mulnC -[2 * 3]/(3`!). by apply/orP; right; apply/ltnW/ltn_fact/lt_T. by rewrite -dvdn2 dvdn_divRL dvdn_fact //=; apply/ltnW/lt_T. Qed. Lemma solvable_SymF : 4 < #|T| -> solvable 'Sym_T = false. Proof. by rewrite (series_sol (Alt_normal T)) => /solvable_AltF->. Qed. End Perm_solvable.
PureCoherence.lean
/- Copyright (c) 2024 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.Tactic.CategoryTheory.Coherence.PureCoherence import Mathlib.Tactic.CategoryTheory.Bicategory.Datatypes /-! # Coherence tactic for bicategories We provide a `bicategory_coherence` tactic, which proves that any two morphisms (with the same source and target) in a bicategory which are built out of associators and unitors are equal. -/ open Lean Meta Elab Qq open CategoryTheory Mathlib.Tactic.BicategoryLike Bicategory namespace Mathlib.Tactic.Bicategory section universe w v u variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B} local infixr:81 " ◁ " => Bicategory.whiskerLeftIso local infixl:81 " ▷ " => Bicategory.whiskerRightIso /-- The composition of the normalizing isomorphisms `η_f : p ≫ f ≅ pf` and `η_g : pf ≫ g ≅ pfg`. -/ abbrev normalizeIsoComp {p : a ⟶ b} {f : b ⟶ c} {g : c ⟶ d} {pf : a ⟶ c} {pfg : a ⟶ d} (η_f : p ≫ f ≅ pf) (η_g : pf ≫ g ≅ pfg) := (α_ _ _ _).symm ≪≫ whiskerRightIso η_f g ≪≫ η_g theorem naturality_associator {p : a ⟶ b} {f : b ⟶ c} {g : c ⟶ d} {h : d ⟶ e} {pf : a ⟶ c} {pfg : a ⟶ d} {pfgh : a ⟶ e} (η_f : p ≫ f ≅ pf) (η_g : pf ≫ g ≅ pfg) (η_h : pfg ≫ h ≅ pfgh) : p ◁ (α_ f g h) ≪≫ (normalizeIsoComp η_f (normalizeIsoComp η_g η_h)) = (normalizeIsoComp (normalizeIsoComp η_f η_g) η_h) := Iso.ext (by simp) theorem naturality_leftUnitor {p : a ⟶ b} {f : b ⟶ c} {pf : a ⟶ c} (η_f : p ≫ f ≅ pf) : p ◁ (λ_ f) ≪≫ η_f = normalizeIsoComp (ρ_ p) η_f := Iso.ext (by simp) theorem naturality_rightUnitor {p : a ⟶ b} {f : b ⟶ c} {pf : a ⟶ c} (η_f : p ≫ f ≅ pf) : p ◁ (ρ_ f) ≪≫ η_f = normalizeIsoComp η_f (ρ_ pf) := Iso.ext (by simp) theorem naturality_id {p : a ⟶ b} {f : b ⟶ c} {pf : a ⟶ c} (η_f : p ≫ f ≅ pf) : p ◁ Iso.refl f ≪≫ η_f = η_f := Iso.ext (by simp) theorem naturality_comp {p : a ⟶ b} {f g h : b ⟶ c} {pf : a ⟶ c} {η : f ≅ g} {θ : g ≅ h} (η_f : p ≫ f ≅ pf) (η_g : p ≫ g ≅ pf) (η_h : p ≫ h ≅ pf) (ih_η : p ◁ η ≪≫ η_g = η_f) (ih_θ : p ◁ θ ≪≫ η_h = η_g) : p ◁ (η ≪≫ θ) ≪≫ η_h = η_f := by rw [← ih_η, ← ih_θ] apply Iso.ext (by simp) theorem naturality_whiskerLeft {p : a ⟶ b} {f : b ⟶ c} {g h : c ⟶ d} {pf : a ⟶ c} {pfg : a ⟶ d} {η : g ≅ h} (η_f : p ≫ f ≅ pf) (η_fg : pf ≫ g ≅ pfg) (η_fh : pf ≫ h ≅ pfg) (ih_η : pf ◁ η ≪≫ η_fh = η_fg) : p ◁ (f ◁ η) ≪≫ normalizeIsoComp η_f η_fh = normalizeIsoComp η_f η_fg := by rw [← ih_η] apply Iso.ext (by simp [← whisker_exchange_assoc]) theorem naturality_whiskerRight {p : a ⟶ b} {f g : b ⟶ c} {h : c ⟶ d} {pf : a ⟶ c} {pfh : a ⟶ d} {η : f ≅ g} (η_f : p ≫ f ≅ pf) (η_g : p ≫ g ≅ pf) (η_fh : pf ≫ h ≅ pfh) (ih_η : p ◁ η ≪≫ η_g = η_f) : p ◁ (η ▷ h) ≪≫ normalizeIsoComp η_g η_fh = normalizeIsoComp η_f η_fh := by rw [← ih_η] apply Iso.ext (by simp) theorem naturality_inv {p : a ⟶ b} {f g : b ⟶ c} {pf : a ⟶ c} {η : f ≅ g} (η_f : p ≫ f ≅ pf) (η_g : p ≫ g ≅ pf) (ih : p ◁ η ≪≫ η_g = η_f) : p ◁ η.symm ≪≫ η_f = η_g := by rw [← ih] apply Iso.ext (by simp) instance : MonadNormalizeNaturality BicategoryM where mkNaturalityAssociator p pf pfg pfgh f g h η_f η_g η_h := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have d : Q($ctx.B) := g.tgt.e have e : Q($ctx.B) := h.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have g : Q($c ⟶ $d) := g.e have h : Q($d ⟶ $e) := h.e have pf : Q($a ⟶ $c) := pf.e.e have pfg : Q($a ⟶ $d) := pfg.e.e have pfgh : Q($a ⟶ $e) := pfgh.e.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e have η_g : Q($pf ≫ $g ≅ $pfg) := η_g.e have η_h : Q($pfg ≫ $h ≅ $pfgh) := η_h.e return q(naturality_associator $η_f $η_g $η_h) mkNaturalityLeftUnitor p pf f η_f := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have pf : Q($a ⟶ $c) := pf.e.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e return q(naturality_leftUnitor $η_f) mkNaturalityRightUnitor p pf f η_f := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have pf : Q($a ⟶ $c) := pf.e.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e return q(naturality_rightUnitor $η_f) mkNaturalityId p pf f η_f := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have pf : Q($a ⟶ $c) := pf.e.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e return q(naturality_id $η_f) mkNaturalityComp p pf f g h η θ η_f η_g η_h ih_η ih_θ := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have g : Q($b ⟶ $c) := g.e have h : Q($b ⟶ $c) := h.e have pf : Q($a ⟶ $c) := pf.e.e have η : Q($f ≅ $g) := η.e have θ : Q($g ≅ $h) := θ.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e have η_g : Q($p ≫ $g ≅ $pf) := η_g.e have η_h : Q($p ≫ $h ≅ $pf) := η_h.e have ih_η : Q($p ◁ $η ≪≫ $η_g = $η_f) := ih_η have ih_θ : Q($p ◁ $θ ≪≫ $η_h = $η_g) := ih_θ return q(naturality_comp $η_f $η_g $η_h $ih_η $ih_θ) mkNaturalityWhiskerLeft p pf pfg f g h η η_f η_fg η_fh ih_η := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have d : Q($ctx.B) := g.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have g : Q($c ⟶ $d) := g.e have h : Q($c ⟶ $d) := h.e have pf : Q($a ⟶ $c) := pf.e.e have pfg : Q($a ⟶ $d) := pfg.e.e have η : Q($g ≅ $h) := η.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e have η_fg : Q($pf ≫ $g ≅ $pfg) := η_fg.e have η_fh : Q($pf ≫ $h ≅ $pfg) := η_fh.e have ih_η : Q($pf ◁ $η ≪≫ $η_fh = $η_fg) := ih_η return q(naturality_whiskerLeft $η_f $η_fg $η_fh $ih_η) mkNaturalityWhiskerRight p pf pfh f g h η η_f η_g η_fh ih_η := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have d : Q($ctx.B) := h.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have g : Q($b ⟶ $c) := g.e have h : Q($c ⟶ $d) := h.e have pf : Q($a ⟶ $c) := pf.e.e have pfh : Q($a ⟶ $d) := pfh.e.e have η : Q($f ≅ $g) := η.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e have η_g : Q($p ≫ $g ≅ $pf) := η_g.e have η_fh : Q($pf ≫ $h ≅ $pfh) := η_fh.e have ih_η : Q($p ◁ $η ≪≫ $η_g = $η_f) := ih_η return q(naturality_whiskerRight $η_f $η_g $η_fh $ih_η) mkNaturalityHorizontalComp _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ := do throwError "horizontal composition is not implemented" mkNaturalityInv p pf f g η η_f η_g ih := do let ctx ← read let _bicat := ctx.instBicategory have a : Q($ctx.B) := p.src.e have b : Q($ctx.B) := p.tgt.e have c : Q($ctx.B) := f.tgt.e have p : Q($a ⟶ $b) := p.e.e have f : Q($b ⟶ $c) := f.e have g : Q($b ⟶ $c) := g.e have pf : Q($a ⟶ $c) := pf.e.e have η : Q($f ≅ $g) := η.e have η_f : Q($p ≫ $f ≅ $pf) := η_f.e have η_g : Q($p ≫ $g ≅ $pf) := η_g.e have ih : Q($p ◁ $η ≪≫ $η_g = $η_f) := ih return q(naturality_inv $η_f $η_g $ih) theorem of_normalize_eq {f g f' : a ⟶ b} {η θ : f ≅ g} (η_f : 𝟙 a ≫ f ≅ f') (η_g : 𝟙 a ≫ g ≅ f') (h_η : 𝟙 a ◁ η ≪≫ η_g = η_f) (h_θ : 𝟙 a ◁ θ ≪≫ η_g = η_f) : η = θ := by apply Iso.ext calc η.hom = (λ_ f).inv ≫ η_f.hom ≫ η_g.inv ≫ (λ_ g).hom := by simp [← reassoc_of% (congrArg Iso.hom h_η)] _ = θ.hom := by simp [← reassoc_of% (congrArg Iso.hom h_θ)] theorem mk_eq_of_naturality {f g f' : a ⟶ b} {η θ : f ⟶ g} {η' θ' : f ≅ g} (η_f : 𝟙 a ≫ f ≅ f') (η_g : 𝟙 a ≫ g ≅ f') (Hη : η'.hom = η) (Hθ : θ'.hom = θ) (Hη' : whiskerLeftIso (𝟙 a) η' ≪≫ η_g = η_f) (Hθ' : whiskerLeftIso (𝟙 a) θ' ≪≫ η_g = η_f) : η = θ := calc η = η'.hom := Hη.symm _ = (λ_ f).inv ≫ η_f.hom ≫ η_g.inv ≫ (λ_ g).hom := by simp [← reassoc_of% (congrArg Iso.hom Hη')] _ = θ'.hom := by simp [← reassoc_of% (congrArg Iso.hom Hθ')] _ = θ := Hθ end instance : MkEqOfNaturality BicategoryM where mkEqOfNaturality η θ ηIso θIso η_f η_g Hη Hθ := do let ctx ← read let _bicat := ctx.instBicategory let η' := ηIso.e let θ' := θIso.e let f ← η'.srcM let g ← η'.tgtM let f' ← η_f.tgtM have a : Q($ctx.B) := f.src.e have b : Q($ctx.B) := f.tgt.e have f : Q($a ⟶ $b) := f.e have g : Q($a ⟶ $b) := g.e have f' : Q($a ⟶ $b) := f'.e have η : Q($f ⟶ $g) := η have θ : Q($f ⟶ $g) := θ have η'_e : Q($f ≅ $g) := η'.e have θ'_e : Q($f ≅ $g) := θ'.e have η_f : Q(𝟙 $a ≫ $f ≅ $f') := η_f.e have η_g : Q(𝟙 $a ≫ $g ≅ $f') := η_g.e have η_hom : Q(Iso.hom $η'_e = $η) := ηIso.eq have Θ_hom : Q(Iso.hom $θ'_e = $θ) := θIso.eq have Hη : Q(whiskerLeftIso (𝟙 $a) $η'_e ≪≫ $η_g = $η_f) := Hη have Hθ : Q(whiskerLeftIso (𝟙 $a) $θ'_e ≪≫ $η_g = $η_f) := Hθ return q(mk_eq_of_naturality $η_f $η_g $η_hom $Θ_hom $Hη $Hθ) open Elab.Tactic /-- Close the goal of the form `η.hom = θ.hom`, where `η` and `θ` are 2-isomorphisms made up only of associators, unitors, and identities. ```lean example {B : Type} [Bicategory B] {a : B} : (λ_ (𝟙 a)).hom = (ρ_ (𝟙 a)).hom := by bicategory_coherence ``` -/ def pureCoherence (mvarId : MVarId) : MetaM (List MVarId) := BicategoryLike.pureCoherence Bicategory.Context `bicategory mvarId @[inherit_doc pureCoherence] elab "bicategory_coherence" : tactic => withMainContext do replaceMainGoal <| ← Bicategory.pureCoherence <| ← getMainGoal end Mathlib.Tactic.Bicategory
Quotient.lean
/- Copyright (c) 2024 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Riccardo Brasca -/ import Mathlib.LinearAlgebra.Dimension.DivisionRing import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.RingTheory.Artinian.Ring import Mathlib.RingTheory.Ideal.Over import Mathlib.RingTheory.Ideal.Quotient.Index import Mathlib.RingTheory.LocalRing.ResidueField.Defs import Mathlib.RingTheory.LocalRing.RingHom.Basic import Mathlib.RingTheory.Nakayama /-! We gather results about the quotients of local rings. -/ open Submodule FiniteDimensional Module variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] [IsLocalRing R] [Module.Finite R S] namespace IsLocalRing local notation "p" => maximalIdeal R local notation "pS" => Ideal.map (algebraMap R S) p theorem quotient_span_eq_top_iff_span_eq_top (s : Set S) : span (R ⧸ p) ((Ideal.Quotient.mk (I := pS)) '' s) = ⊤ ↔ span R s = ⊤ := by have H : (span (R ⧸ p) ((Ideal.Quotient.mk (I := pS)) '' s)).restrictScalars R = (span R s).map (IsScalarTower.toAlgHom R S (S ⧸ pS)) := by rw [map_span, ← restrictScalars_span R (R ⧸ p) Ideal.Quotient.mk_surjective, IsScalarTower.coe_toAlgHom', Ideal.Quotient.algebraMap_eq] constructor · intro hs rw [← top_le_iff] apply le_of_le_smul_of_le_jacobson_bot · exact Module.finite_def.mp ‹_› · exact (jacobson_eq_maximalIdeal ⊥ bot_ne_top).ge · rw [Ideal.smul_top_eq_map] rintro x - have : LinearMap.ker (IsScalarTower.toAlgHom R S (S ⧸ pS)) = restrictScalars R pS := by ext; simp [Ideal.Quotient.eq_zero_iff_mem] rw [← this, ← comap_map_eq, mem_comap, ← H, hs, restrictScalars_top] exact mem_top · intro hs rwa [hs, Submodule.map_top, LinearMap.range_eq_top.mpr, restrictScalars_eq_top_iff] at H rw [IsScalarTower.coe_toAlgHom', Ideal.Quotient.algebraMap_eq] exact Ideal.Quotient.mk_surjective attribute [local instance] Ideal.Quotient.field variable [Module.Free R S] {ι : Type*} theorem finrank_quotient_map : finrank (R ⧸ p) (S ⧸ pS) = finrank R S := by classical have : Module.Finite R (S ⧸ pS) := Module.Finite.of_surjective (IsScalarTower.toAlgHom R S (S ⧸ pS)).toLinearMap (Ideal.Quotient.mk_surjective (I := pS)) have : Module.Finite (R ⧸ p) (S ⧸ pS) := Module.Finite.of_restrictScalars_finite R _ _ apply le_antisymm · let b := Module.Free.chooseBasis R S conv_rhs => rw [finrank_eq_card_chooseBasisIndex] apply finrank_le_of_span_eq_top rw [Set.range_comp] apply (quotient_span_eq_top_iff_span_eq_top _).mpr b.span_eq · let b := Module.Free.chooseBasis (R ⧸ p) (S ⧸ pS) choose b' hb' using fun i ↦ Ideal.Quotient.mk_surjective (b i) conv_rhs => rw [finrank_eq_card_chooseBasisIndex] refine finrank_le_of_span_eq_top (v := b') ?_ apply (quotient_span_eq_top_iff_span_eq_top _).mp rw [← Set.range_comp, show Ideal.Quotient.mk pS ∘ b' = ⇑b from funext hb'] exact b.span_eq /-- Given a basis of `S`, the induced basis of `S / Ideal.map (algebraMap R S) p`. -/ noncomputable def basisQuotient [Fintype ι] (b : Basis ι R S) : Basis ι (R ⧸ p) (S ⧸ pS) := basisOfTopLeSpanOfCardEqFinrank (Ideal.Quotient.mk pS ∘ b) (by rw [Set.range_comp] exact ((quotient_span_eq_top_iff_span_eq_top _).mpr b.span_eq).ge) (by rw [finrank_quotient_map, finrank_eq_card_basis b]) lemma basisQuotient_apply [Fintype ι] (b : Basis ι R S) (i) : (basisQuotient b) i = Ideal.Quotient.mk pS (b i) := by delta basisQuotient rw [coe_basisOfTopLeSpanOfCardEqFinrank, Function.comp_apply] lemma basisQuotient_repr {ι} [Fintype ι] (b : Basis ι R S) (x) (i) : (basisQuotient b).repr (Ideal.Quotient.mk pS x) i = Ideal.Quotient.mk p (b.repr x i) := by refine congr_fun (g := Ideal.Quotient.mk p ∘ b.repr x) ?_ i apply (Finsupp.linearEquivFunOnFinite (R ⧸ p) _ _).symm.injective apply (basisQuotient b).repr.symm.injective simp only [Finsupp.linearEquivFunOnFinite_symm_coe, LinearEquiv.symm_apply_apply, Basis.repr_symm_apply] rw [Finsupp.linearCombination_eq_fintype_linearCombination_apply (R ⧸ p), Fintype.linearCombination_apply] simp only [Function.comp_apply, basisQuotient_apply, Ideal.Quotient.mk_smul_mk_quotient_map_quotient, ← Algebra.smul_def] rw [← map_sum, Basis.sum_repr b x] lemma exists_maximalIdeal_pow_le_of_finite_quotient (I : Ideal R) [Finite (R ⧸ I)] : ∃ n, maximalIdeal R ^ n ≤ I := by by_cases hI : I = ⊤ · simp [hI] have : Nontrivial (R ⧸ I) := Ideal.Quotient.nontrivial hI have := IsLocalRing.of_surjective' (Ideal.Quotient.mk I) Ideal.Quotient.mk_surjective have := IsLocalHom.of_surjective (Ideal.Quotient.mk I) Ideal.Quotient.mk_surjective obtain ⟨n, hn⟩ := IsArtinianRing.isNilpotent_jacobson_bot (R := R ⧸ I) have : (maximalIdeal R).map (Ideal.Quotient.mk I) = maximalIdeal (R ⧸ I) := by ext x obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x simp [sup_eq_left.mpr (le_maximalIdeal hI)] rw [jacobson_eq_maximalIdeal _ bot_ne_top, ← this, ← Ideal.map_pow, Ideal.zero_eq_bot, Ideal.map_eq_bot_iff_le_ker, Ideal.mk_ker] at hn exact ⟨n, hn⟩ lemma finite_quotient_iff [IsNoetherianRing R] [Finite (ResidueField R)] {I : Ideal R} : Finite (R ⧸ I) ↔ ∃ n, (maximalIdeal R) ^ n ≤ I := by refine ⟨fun _ ↦ exists_maximalIdeal_pow_le_of_finite_quotient I, ?_⟩ rintro ⟨n, hn⟩ have : Finite (R ⧸ maximalIdeal R) := ‹_› have := (Ideal.finite_quotient_pow (IsNoetherian.noetherian (maximalIdeal R)) n) exact Finite.of_surjective _ (Ideal.Quotient.factor_surjective hn) end IsLocalRing
Subalgebra.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.RingTheory.Finiteness.Basic import Mathlib.RingTheory.Finiteness.Bilinear /-! # Subalgebras that are finitely generated as submodules -/ open Function (Surjective) open Finsupp namespace Subalgebra open Submodule variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] theorem fg_bot_toSubmodule : (⊥ : Subalgebra R A).toSubmodule.FG := ⟨{1}, by simp [Algebra.toSubmodule_bot, one_eq_span]⟩ instance finite_bot : Module.Finite R (⊥ : Subalgebra R A) := Module.Finite.range (Algebra.linearMap R A) end Subalgebra namespace Submodule theorem fg_unit {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (I : (Submodule R A)ˣ) : (I : Submodule R A).FG := by obtain ⟨T, T', hT, hT', one_mem⟩ := mem_span_mul_finite_of_mem_mul (I.mul_inv ▸ one_le.mp le_rfl) refine ⟨T, span_eq_of_le _ hT ?_⟩ rw [← one_mul I, ← mul_one (span R (T : Set A))] conv_rhs => rw [← I.inv_mul, ← mul_assoc] refine mul_le_mul_left (le_trans ?_ <| mul_le_mul_right <| span_le.mpr hT') rwa [Units.val_one, span_mul_span, one_le] theorem fg_of_isUnit {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] {I : Submodule R A} (hI : IsUnit I) : I.FG := fg_unit hI.unit section Mul variable {R : Type*} {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] variable {M N : Submodule R A} theorem FG.mul (hm : M.FG) (hn : N.FG) : (M * N).FG := by rw [mul_eq_map₂]; exact hm.map₂ _ hn theorem FG.pow (h : M.FG) (n : ℕ) : (M ^ n).FG := Nat.recOn n ⟨{1}, by simp [one_eq_span]⟩ fun n ih => by simpa [pow_succ] using ih.mul h end Mul end Submodule
mxred.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div. From mathcomp Require Import choice fintype finfun bigop fingroup perm order. From mathcomp Require Import ssralg zmodp matrix mxalgebra poly polydiv mxpoly. (*****************************************************************************) (* In this file, we prove diagonalization theorems. For this purpose, we *) (* define conjugation, similarity and diagonalizability. *) (* *) (* conjmx V f := V *m f *m pinvmx V *) (* == the conjugation of f by V, i.e. "the" matrix of f *) (* in the basis of row vectors of V. *) (* Although this makes sense only when f stabilizes V, *) (* the definition can be stated more generally. *) (* similar_to P A C == where P is a base change matrix, A is a matrix, *) (* and C is a class of matrices, *) (* this states that conjmx P A is in C, *) (* which means A is similar to a matrix in C. *) (* *) (* From the latter, we derive serveral related notions: *) (* similar P A B := similar_to P A (pred1 B) *) (* == A is similar to B, with base change matrix P *) (* similar_in D A B == A is similar to B, *) (* with a base change matrix in D *) (* similar_in_to D A C == A is similar to a matrix in the class C, *) (* with a base change matrix in D *) (* all_similar_to D As C == all the matrices in the sequence As are similar *) (* to some matrix in the class C, *) (* with a base change matrix in D. *) (* *) (* We also specialize the class C, to diagonalizability: *) (* similar_diag P A := (similar_to P A is_diag_mx). *) (* diagonalizable_in D A := (similar_in_to D A is_diag_mx). *) (* diagonalizable A := (diagonalizable_in unitmx A). *) (* codiagonalizable_in D As := (all_similar_to D As is_diag_mx). *) (* codiagonalizable As := (codiagonalizable_in unitmx As). *) (* *) (* The main results of this file are: *) (* diagonalizablePeigen: *) (* a matrix is diagonalizable iff there is a sequence *) (* of scalars r, such that the sum of the associated *) (* eigenspaces is full. *) (* diagonalizableP: *) (* a matrix is diagonalizable iff its minimal polynomial *) (* divides a split polynomial with simple roots. *) (* codiagonalizableP: *) (* a sequence of matrices are diagonalizable in the same basis *) (* iff they are all diagonalizable and commute pairwize. *) (* *) (* We also specialize the class C, to trigonalizablility: *) (* similar_trig P A := (similar_to P A is_trig_mx). *) (* trigonalizable_in D A := (similar_in_to D A is_trig_mx). *) (* trigonalizable A := (trigonalizable_in unitmx A). *) (* cotrigonalizable_in D As := (all_similar_to D As is_trig_mx). *) (* cotrigonalizable As := (cotrigonalizable_in unitmx As). *) (* The theory of trigonalization is however not developed in this file. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Monoid.Theory. Local Open Scope ring_scope. Section ConjMx. Context {F : fieldType}. Definition conjmx (m n : nat) (V : 'M_(m, n)) (f : 'M[F]_n) : 'M_m := V *m f *m pinvmx V. Notation restrictmx V := (conjmx (row_base V)). Lemma stablemx_comp (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : stablemx W f -> stablemx V (conjmx W f) -> stablemx (V *m W) f. Proof. by move=> Wf /(submxMr W); rewrite -mulmxA mulmxKpV// mulmxA. Qed. Lemma stablemx_restrict m n (A : 'M[F]_n) (V : 'M_n) (W : 'M_(m, \rank V)): stablemx V A -> stablemx W (restrictmx V A) = stablemx (W *m row_base V) A. Proof. move=> A_stabV; rewrite mulmxA -[in RHS]mulmxA. rewrite -(submxMfree _ W (row_base_free V)) mulmxKpV //. by rewrite mulmx_sub ?stablemx_row_base. Qed. Lemma conjmxM (m n : nat) (V : 'M[F]_(m, n)) : {in [pred f | stablemx V f] &, {morph conjmx V : f g / f *m g}}. Proof. move=> f g; rewrite !inE => Vf Vg /=. by rewrite /conjmx 2!mulmxA mulmxA mulmxKpV ?stablemx_row_base. Qed. Lemma conjMmx (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : row_free (V *m W) -> stablemx W f -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> rfVW Wf VWf; apply: (row_free_inj rfVW); rewrite mulmxKpV ?stablemx_comp//. by rewrite mulmxA mulmxKpV// -[RHS]mulmxA mulmxKpV ?mulmxA. Qed. Lemma conjuMmx (m n : nat) (V : 'M[F]_m) (W : 'M_(m, n)) (f : 'M_n) : V \in unitmx -> row_free W -> stablemx W f -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Vu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree// -/(row_free V) row_free_unit. Qed. Lemma conjMumx (m n : nat) (V : 'M[F]_(m, n)) (W f : 'M_n) : W \in unitmx -> row_free V -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Wu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree ?row_free_unit. Qed. Lemma conjuMumx (n : nat) (V W f : 'M[F]_n) : V \in unitmx -> W \in unitmx -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. by move=> Vu Wu; rewrite conjuMmx ?stablemx_unit ?row_free_unit. Qed. Lemma conjmx_scalar (m n : nat) (V : 'M[F]_(m, n)) (a : F) : row_free V -> conjmx V a%:M = a%:M. Proof. by move=> rfV; rewrite /conjmx scalar_mxC mulmxKp. Qed. Lemma conj0mx (m n : nat) f : conjmx (0 : 'M[F]_(m, n)) f = 0. Proof. by rewrite /conjmx !mul0mx. Qed. Lemma conjmx0 (m n : nat) (V : 'M[F]_(m, n)) : conjmx V 0 = 0. Proof. by rewrite /conjmx mulmx0 mul0mx. Qed. Lemma conjumx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx V f = V *m f *m invmx V. Proof. by move=> uV; rewrite /conjmx pinvmxE. Qed. Lemma conj1mx (n : nat) (f : 'M[F]_n) : conjmx 1%:M f = f. Proof. by rewrite conjumx ?unitmx1// invmx1 mulmx1 mul1mx. Qed. Lemma conjVmx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) f = invmx V *m f *m V. Proof. by move=> Vunit; rewrite conjumx ?invmxK ?unitmx_inv. Qed. Lemma conjmxK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) (conjmx V f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulVmx ?conj1mx. Qed. Lemma conjmxVK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx V (conjmx (invmx V) f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulmxV ?conj1mx. Qed. Lemma horner_mx_conj m n p (B : 'M[F]_(n.+1, m.+1)) (f : 'M_m.+1) : row_free B -> stablemx B f -> horner_mx (conjmx B f) p = conjmx B (horner_mx f p). Proof. move=> B_free B_stab; rewrite/conjmx; elim/poly_ind: p => [|p c]. by rewrite !rmorph0 mulmx0 mul0mx. rewrite !(rmorphD, rmorphM)/= !(horner_mx_X, horner_mx_C) => ->. rewrite [_ * _]mulmxA [_ *m (B *m _)]mulmxA mulmxKpV ?horner_mx_stable//. apply: (row_free_inj B_free); rewrite [_ *m B]mulmxDl. pose stablemxE := (stablemxD, stablemxM, stablemxC, horner_mx_stable). by rewrite !mulmxKpV -?[B *m _ *m _]mulmxA ?stablemxE// mulmxDr -scalar_mxC. Qed. Lemma horner_mx_uconj n p (B : 'M[F]_(n.+1)) (f : 'M_n.+1) : B \is a GRing.unit -> horner_mx (B *m f *m invmx B) p = B *m horner_mx f p *m invmx B. Proof. move=> B_unit; rewrite -!conjumx//. by rewrite horner_mx_conj ?row_free_unit ?stablemx_unit. Qed. Lemma horner_mx_uconjC n p (B : 'M[F]_(n.+1)) (f : 'M_n.+1) : B \is a GRing.unit -> horner_mx (invmx B *m f *m B) p = invmx B *m horner_mx f p *m B. Proof. move=> B_unit; rewrite -[X in _ *m X](invmxK B). by rewrite horner_mx_uconj ?invmxK ?unitmx_inv. Qed. Lemma mxminpoly_conj m n (V : 'M[F]_(m.+1, n.+1)) (f : 'M_n.+1) : row_free V -> stablemx V f -> mxminpoly (conjmx V f) %| mxminpoly f. Proof. by move=> *; rewrite mxminpoly_min// horner_mx_conj// mx_root_minpoly conjmx0. Qed. Lemma mxminpoly_uconj n (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \in unitmx -> mxminpoly (conjmx V f) = mxminpoly f. Proof. have simp := (row_free_unit, stablemx_unit, unitmx_inv, unitmx1). move=> Vu; apply/eqP; rewrite -eqp_monic ?mxminpoly_monic// /eqp. apply/andP; split; first by rewrite mxminpoly_conj ?simp. by rewrite -[f in X in X %| _](conjmxK _ Vu) mxminpoly_conj ?simp. Qed. Section fixed_stablemx_space. Variables (m n : nat). Implicit Types (V : 'M[F]_(m, n)) (f : 'M[F]_n). Implicit Types (a : F) (p : {poly F}). Section Sub. Variable (k : nat). Implicit Types (W : 'M[F]_(k, m)). Lemma sub_kermxpoly_conjmx V f p W : stablemx V f -> row_free V -> (W <= kermxpoly (conjmx V f) p)%MS = (W *m V <= kermxpoly f p)%MS. Proof. move: n m => [|n'] [|m']// in V f W *; rewrite ?thinmx0// => fV rfV. - by rewrite /row_free mxrank0 in rfV. - by rewrite mul0mx !sub0mx. - apply/sub_kermxP/sub_kermxP; rewrite horner_mx_conj//; last first. by move=> /(congr1 (mulmxr (pinvmx V)))/=; rewrite mul0mx !mulmxA. move=> /(congr1 (mulmxr V))/=; rewrite ![W *m _]mulmxA ?mul0mx mulmxKpV//. by rewrite -mulmxA mulmx_sub// horner_mx_stable//. Qed. Lemma sub_eigenspace_conjmx V f a W : stablemx V f -> row_free V -> (W <= eigenspace (conjmx V f) a)%MS = (W *m V <= eigenspace f a)%MS. Proof. by move=> fV rfV; rewrite !eigenspace_poly sub_kermxpoly_conjmx. Qed. End Sub. Lemma eigenpoly_conjmx V f : stablemx V f -> row_free V -> {subset eigenpoly (conjmx V f) <= eigenpoly f}. Proof. move=> fV rfV a /eigenpolyP [x]; rewrite sub_kermxpoly_conjmx//. move=> xV_le_fa x_neq0; apply/eigenpolyP. by exists (x *m V); rewrite ?mulmx_free_eq0. Qed. Lemma eigenvalue_conjmx V f : stablemx V f -> row_free V -> {subset eigenvalue (conjmx V f) <= eigenvalue f}. Proof. by move=> fV rfV a; rewrite ![_ \in _]eigenvalue_poly; apply: eigenpoly_conjmx. Qed. Lemma conjmx_eigenvalue a V f : (V <= eigenspace f a)%MS -> row_free V -> conjmx V f = a%:M. Proof. by move=> /eigenspaceP Vfa rfV; rewrite /conjmx Vfa -mul_scalar_mx mulmxKp. Qed. End fixed_stablemx_space. End ConjMx. Notation restrictmx V := (conjmx (row_base V)). Definition similar_to {F : fieldType} {m n} (P : 'M_(m, n)) A (C : {pred 'M[F]_m}) := C (conjmx P A). Notation similar P A B := (similar_to P A (PredOfSimpl.coerce (pred1 B))). Notation similar_in D A B := (exists2 P, P \in D & similar P A B). Notation similar_in_to D A C := (exists2 P, P \in D & similar_to P A C). Notation all_similar_to D As C := (exists2 P, P \in D & all [pred A | similar_to P A C] As). Notation similar_diag P A := (similar_to P A is_diag_mx). Notation diagonalizable_in D A := (similar_in_to D A is_diag_mx). Notation diagonalizable A := (diagonalizable_in unitmx A). Notation codiagonalizable_in D As := (all_similar_to D As is_diag_mx). Notation codiagonalizable As := (codiagonalizable_in unitmx As). Notation similar_trig P A := (similar_to P A is_trig_mx). Notation trigonalizable_in D A := (similar_in_to D A is_trig_mx). Notation trigonalizable A := (trigonalizable_in unitmx A). Notation cotrigonalizable_in D As := (all_similar_to D As is_trig_mx). Notation cotrigonalizable As := (cotrigonalizable_in unitmx As). Section Similarity. Context {F : fieldType}. Lemma similarPp m n {P : 'M[F]_(m, n)} {A B} : stablemx P A -> similar P A B -> P *m A = B *m P. Proof. by move=> stablemxPA /eqP <-; rewrite mulmxKpV. Qed. Lemma similarW m n {P : 'M[F]_(m, n)} {A B} : row_free P -> P *m A = B *m P -> similar P A B. Proof. by rewrite /similar_to/= /conjmx => fP ->; rewrite mulmxKp. Qed. Section Similar. Context {n : nat}. Implicit Types (f g p : 'M[F]_n) (fs : seq 'M[F]_n) (d : 'rV[F]_n). Lemma similarP {p f g} : p \in unitmx -> reflect (p *m f = g *m p) (similar p f g). Proof. move=> p_unit; apply: (iffP idP); first exact/similarPp/stablemx_unit. by apply: similarW; rewrite row_free_unit. Qed. Lemma similarRL {p f g} : p \in unitmx -> reflect (g = p *m f *m invmx p) (similar p f g). Proof. by move=> ?; apply: (iffP eqP); rewrite conjumx. Qed. Lemma similarLR {p f g} : p \in unitmx -> reflect (f = conjmx (invmx p) g) (similar p f g). Proof. by move=> pu; rewrite conjVmx//; apply: (iffP (similarRL pu)) => ->; rewrite !mulmxA ?(mulmxK, mulmxKV, mulVmx, mulmxV, mul1mx, mulmx1). Qed. End Similar. Lemma similar_mxminpoly {n} {p f g : 'M[F]_n.+1} : p \in unitmx -> similar p f g -> mxminpoly f = mxminpoly g. Proof. by move=> pu /eqP<-; rewrite mxminpoly_uconj. Qed. Lemma similar_diag_row_base m n (P : 'M[F]_(m, n)) (A : 'M_n) : similar_diag (row_base P) A = is_diag_mx (restrictmx P A). Proof. by []. Qed. Lemma similar_diagPp m n (P : 'M[F]_(m, n)) A : reflect (forall i j : 'I__, i != j :> nat -> conjmx P A i j = 0) (similar_diag P A). Proof. exact: @is_diag_mxP. Qed. Lemma similar_diagP n (P : 'M[F]_n) A : P \in unitmx -> reflect (forall i j : 'I__, i != j :> nat -> (P *m A *m invmx P) i j = 0) (similar_diag P A). Proof. by move=> Pu; rewrite -conjumx//; exact: is_diag_mxP. Qed. Lemma similar_diagPex {m} {n} {P : 'M[F]_(m, n)} {A} : reflect (exists D, similar P A (diag_mx D)) (similar_diag P A). Proof. by apply: (iffP (diag_mxP _)) => -[D]/eqP; exists D. Qed. Lemma similar_diagLR n {P : 'M[F]_n} {A} : P \in unitmx -> reflect (exists D, A = conjmx (invmx P) (diag_mx D)) (similar_diag P A). Proof. by move=> Punit; apply: (iffP similar_diagPex) => -[D /(similarLR Punit)]; exists D. Qed. Lemma similar_diag_mxminpoly {n} {p f : 'M[F]_n.+1} (rs := undup [seq conjmx p f i i | i <- enum 'I_n.+1]) : p \in unitmx -> similar_diag p f -> mxminpoly f = \prod_(r <- rs) ('X - r%:P). Proof. rewrite /rs => pu /(similar_diagLR pu)[d {f rs}->]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by rewrite [in RHS](@eq_map _ _ _ (d 0))// => i; rewrite conjmxVK// mxE eqxx. Qed. End Similarity. Lemma similar_diag_sum (F : fieldType) (m n : nat) (p_ : 'I_n -> nat) (V_ : forall i, 'M[F]_(p_ i, m)) (f : 'M[F]_m) : mxdirect (\sum_i <<V_ i>>) -> (forall i, stablemx (V_ i) f) -> (forall i, row_free (V_ i)) -> similar_diag (\mxcol_i V_ i) f = [forall i, similar_diag (V_ i) f]. Proof. move=> Vd Vf rfV; have aVf : stablemx (\mxcol_i V_ i) f. rewrite (eqmx_stable _ (eqmx_col _)) stablemx_sums//. by move=> i; rewrite (eqmx_stable _ (genmxE _)). apply/similar_diagPex/'forall_similar_diagPex => /= [[D /(similarPp aVf) +] i|/(_ _)/sigW Dof]. rewrite mxcol_mul -[D]submxrowK diag_mxrow mul_mxdiag_mxcol. move=> /eq_mxcolP/(_ i); set D0 := (submxrow _ _) => VMeq. by exists D0; apply/similarW. exists (\mxrow_i tag (Dof i)); apply/similarW. rewrite -row_leq_rank eqmx_col (mxdirectP Vd)/=. by under [X in (_ <= X)%N]eq_bigr do rewrite genmxE (eqP (rfV _)). rewrite mxcol_mul diag_mxrow mul_mxdiag_mxcol; apply: eq_mxcol => i. by case: Dof => /= k /(similarPp); rewrite Vf => /(_ isT) ->. Qed. Section Diag. Variable (F : fieldType). Lemma codiagonalizable1 n (A : 'M[F]_n) : codiagonalizable [:: A] <-> diagonalizable A. Proof. by split=> -[P Punit PA]; exists P; move: PA; rewrite //= andbT. Qed. Lemma codiagonalizablePfull n (As : seq 'M[F]_n) : codiagonalizable As <-> exists m, exists2 P : 'M_(m, n), row_full P & all [pred A | similar_diag P A] As. Proof. split => [[P Punit SPA]|[m [P Pfull SPA]]]. by exists n => //; exists P; rewrite ?row_full_unit. have Qfull := fullrowsub_unit Pfull. exists (rowsub (fullrankfun Pfull) P) => //; apply/allP => A AAs/=. have /allP /(_ _ AAs)/= /similar_diagPex[d /similarPp] := SPA. rewrite submx_full// => /(_ isT) PA_eq. apply/similar_diagPex; exists (colsub (fullrankfun Pfull) d). apply/similarP => //; apply/row_matrixP => i. rewrite !row_mul row_diag_mx -scalemxAl -rowE !row_rowsub !mxE. have /(congr1 (row (fullrankfun Pfull i))) := PA_eq. by rewrite !row_mul row_diag_mx -scalemxAl -rowE => ->. Qed. Lemma codiagonalizable_on m n (V_ : 'I_n -> 'M[F]_m) (As : seq 'M[F]_m) : (\sum_i V_ i :=: 1%:M)%MS -> mxdirect (\sum_i V_ i) -> (forall i, all (fun A => stablemx (V_ i) A) As) -> (forall i, codiagonalizable (map (restrictmx (V_ i)) As)) -> codiagonalizable As. Proof. move=> V1 Vdirect /(_ _)/allP AV /(_ _) /sig2W/= Pof. pose P_ i := tag (Pof i). have P_unit i : P_ i \in unitmx by rewrite /P_; case: {+}Pof. have P_diag i A : A \in As -> similar_diag (P_ i *m row_base (V_ i)) A. move=> AAs; rewrite /P_; case: {+}Pof => /= P Punit. rewrite all_map => /allP/(_ A AAs); rewrite /similar_to/=. by rewrite conjuMmx ?row_base_free ?stablemx_row_base ?AV. pose P := \mxcol_i (P_ i *m row_base (V_ i)). have P_full i : row_full (P_ i) by rewrite row_full_unit. have PrV i : (P_ i *m row_base (V_ i) :=: V_ i)%MS. exact/(eqmx_trans _ (eq_row_base _))/eqmxMfull. apply/codiagonalizablePfull; eexists _; last exists P; rewrite /=. - rewrite -sub1mx eqmx_col. by under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. apply/allP => A AAs /=; rewrite similar_diag_sum. - by apply/forallP => i; apply: P_diag. - rewrite mxdirectE/=. under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. by under eq_bigr do rewrite genmxE PrV; rewrite -(mxdirectP Vdirect)//= V1. - by move=> i; rewrite (eqmx_stable _ (PrV _)) ?AV. - by move=> i; rewrite /row_free eqmxMfull ?eq_row_base ?row_full_unit. Qed. Lemma diagonalizable_diag {n} (d : 'rV[F]_n) : diagonalizable (diag_mx d). Proof. by exists 1%:M; rewrite ?unitmx1// /similar_to conj1mx diag_mx_is_diag. Qed. Hint Resolve diagonalizable_diag : core. Lemma diagonalizable_scalar {n} (a : F) : diagonalizable (a%:M : 'M_n). Proof. by rewrite -diag_const_mx. Qed. Hint Resolve diagonalizable_scalar : core. Lemma diagonalizable0 {n} : diagonalizable (0 : 'M[F]_n). Proof. by rewrite (_ : 0 = 0%:M)//; apply/matrixP => i j; rewrite !mxE// mul0rn. Qed. Hint Resolve diagonalizable0 : core. Lemma diagonalizablePeigen {n} {f : 'M[F]_n} : diagonalizable f <-> exists2 rs, uniq rs & (\sum_(r <- rs) eigenspace f r :=: 1%:M)%MS. Proof. split=> [df|[rs urs rsP]]. suff [rs rsP] : exists rs, (\sum_(r <- rs) eigenspace f r :=: 1%:M)%MS. exists (undup rs); rewrite ?undup_uniq//; apply: eqmx_trans rsP. elim: rs => //= r rs IHrs; rewrite big_cons. case: ifPn => in_rs; rewrite ?big_cons; last exact: adds_eqmx. apply/(eqmx_trans IHrs)/eqmx_sym/addsmx_idPr. have rrs : (index r rs < size rs)%N by rewrite index_mem. rewrite (big_nth 0) big_mkord (sumsmx_sup (Ordinal rrs)) ?nth_index//. move: df => [P Punit /(similar_diagLR Punit)[d ->]]. exists [seq d 0 i | i <- enum 'I_n]; rewrite big_image/=. apply: (@eqmx_trans _ _ _ _ _ _ P); apply/eqmxP; rewrite ?sub1mx ?submx1 ?row_full_unit//. rewrite submx_full ?row_full_unit//=. apply/row_subP => i; rewrite rowE (sumsmx_sup i)//. apply/eigenspaceP; rewrite conjVmx// !mulmxA mulmxK//. by rewrite -rowE row_diag_mx scalemxAl. have mxdirect_eigenspaces : mxdirect (\sum_(i < size rs) eigenspace f rs`_i). apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. rewrite (big_nth 0) big_mkord in rsP; apply/codiagonalizable1. apply/(codiagonalizable_on _ mxdirect_eigenspaces) => // i/=. case: n => [|n] in f {mxdirect_eigenspaces} rsP *. by rewrite thinmx0 sub0mx. by rewrite comm_mx_stable_eigenspace. apply/codiagonalizable1. by rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free. Qed. Lemma diagonalizableP n' (n := n'.+1) (f : 'M[F]_n) : diagonalizable f <-> exists2 rs, uniq rs & mxminpoly f %| \prod_(x <- rs) ('X - x%:P). Proof. split=> [[P Punit /similar_diagPex[d /(similarLR Punit)->]]|]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by eexists; [|by []]; rewrite undup_uniq. move=> [rs rsU rsP]; apply: diagonalizablePeigen.2. exists rs => //. rewrite (big_nth 0) big_mkord (eq_bigr _ (fun _ _ => eigenspace_poly _ _)). apply: (eqmx_trans (eqmx_sym (kermxpoly_prod _ _)) (kermxpoly_min _)). by move=> i j _ _; rewrite coprimep_XsubC root_XsubC nth_uniq. by rewrite (big_nth 0) big_mkord in rsP. Qed. Lemma diagonalizable_conj_diag m n (V : 'M[F]_(m, n)) (d : 'rV[F]_n) : stablemx V (diag_mx d) -> row_free V -> diagonalizable (conjmx V (diag_mx d)). Proof. (move: m n => [|m] [|n] in V d *; rewrite ?thinmx0; [by []|by []| |]) => Vd rdV. - by rewrite /row_free mxrank0 in rdV. - apply/diagonalizableP; pose u := undup [seq d 0 i | i <- enum 'I_n.+1]. exists u; first by rewrite undup_uniq. by rewrite (dvdp_trans (mxminpoly_conj rdV _))// mxminpoly_diag. Qed. Lemma codiagonalizableP n (fs : seq 'M[F]_n) : {in fs &, forall f g, comm_mx f g} /\ (forall f, f \in fs -> diagonalizable f) <-> codiagonalizable fs. Proof. split => [cdfs|[P Punit /allP/= fsD]]/=; last first. split; last by exists P; rewrite // fsD. move=> f g ffs gfs; move=> /(_ _ _)/similar_diagPex/sigW in fsD. have [[df /similarLR->//] [dg /similarLR->//]] := (fsD _ ffs, fsD _ gfs). by rewrite /comm_mx -!conjmxM 1?diag_mxC// inE stablemx_unit ?unitmx_inv. move: cdfs => [/(rwP (all_comm_mxP _)).1 cdfs1 cdfs2]. have [k] := ubnP (size fs); elim: k => [|k IHk]//= in n fs cdfs1 cdfs2 *. case: fs cdfs1 cdfs2 => [|f fs]//=; first by exists 1%:M; rewrite ?unitmx1. rewrite ltnS all_comm_mx_cons => /andP[/allP/(_ _ _)/eqP ffsC fsC dffs] fsk. have /diagonalizablePeigen [rs urs rs1] := dffs _ (mem_head _ _). rewrite (big_nth 0) big_mkord in rs1. have efg (i : 'I_(size rs)) g : g \in f :: fs -> stablemx (eigenspace f rs`_i) g. case: n => [|n'] in g f fs ffsC fsC {dffs rs1 fsk} * => g_ffs. by rewrite thinmx0 sub0mx. rewrite comm_mx_stable_eigenspace//. by move: g_ffs; rewrite !inE => /predU1P [->//|/ffsC]. apply/(@codiagonalizable_on _ _ _ (_ :: _) rs1) => [|i|i /=]. - apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. - by apply/allP => g g_ffs; rewrite efg. rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free//. set gs := map _ _; suff [P Punit /= Pgs] : codiagonalizable gs. exists P; rewrite /= ?Pgs ?andbT// /similar_to. by rewrite conjmx_scalar ?mx_scalar_is_diag// row_free_unit. apply: IHk; rewrite ?size_map/= ?ltnS//. apply/all_comm_mxP => _ _ /mapP[/= g gfs ->] /mapP[/= h hfs ->]. rewrite -!conjmxM ?inE ?stablemx_row_base ?efg ?inE ?gfs ?hfs ?orbT//. by rewrite (all_comm_mxP _ fsC). move=> _ /mapP[/= g gfs ->]. have: stablemx (row_base (eigenspace f rs`_i)) g. by rewrite stablemx_row_base efg// inE gfs orbT. have := dffs g; rewrite inE gfs orbT => /(_ isT) [P Punit]. move=> /similar_diagPex[D /(similarLR Punit)->] sePD. have rfeP : row_free (row_base (eigenspace f rs`_i) *m invmx P). by rewrite /row_free mxrankMfree ?row_free_unit ?unitmx_inv// eq_row_base. rewrite -conjMumx ?unitmx_inv ?row_base_free//. apply/diagonalizable_conj_diag => //. by rewrite stablemx_comp// stablemx_unit ?unitmx_inv. Qed. End Diag.
Countable.lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Finsupp.Encodable import Mathlib.Data.Set.Countable import Mathlib.LinearAlgebra.Finsupp.LinearCombination /-! # Countable modules -/ noncomputable section namespace Finsupp variable {M : Type*} {R : Type*} [Semiring R] [AddCommMonoid M] [Module R M] /-- If `R` is countable, then any `R`-submodule spanned by a countable family of vectors is countable. -/ instance {ι : Type*} [Countable R] [Countable ι] (v : ι → M) : Countable (Submodule.span R (Set.range v)) := by refine Set.countable_coe_iff.mpr (Set.Countable.mono ?_ (Set.countable_range (fun c : (ι →₀ R) => c.sum fun i _ => (c i) • v i))) exact fun _ h => Finsupp.mem_span_range_iff_exists_finsupp.mp (SetLike.mem_coe.mp h) end Finsupp
ZPow.lean
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Integer powers of square matrices In this file, we define integer power of matrices, relying on the nonsingular inverse definition for negative powers. ## Implementation details The main definition is a direct recursive call on the integer inductive type, as provided by the `DivInvMonoid.Pow` default implementation. The lemma names are taken from `Algebra.GroupWithZero.Power`. ## Tags matrix inverse, matrix powers -/ open Matrix namespace Matrix variable {n' : Type*} [DecidableEq n'] [Fintype n'] {R : Type*} [CommRing R] local notation "M" => Matrix n' n' R noncomputable instance : DivInvMonoid M := { show Monoid M by infer_instance, show Inv M by infer_instance with } section NatPow @[simp] theorem inv_pow' (A : M) (n : ℕ) : A⁻¹ ^ n = (A ^ n)⁻¹ := by induction n with | zero => simp | succ n ih => rw [pow_succ A, mul_inv_rev, ← ih, ← pow_succ'] theorem pow_sub' (A : M) {m n : ℕ} (ha : IsUnit A.det) (h : n ≤ m) : A ^ (m - n) = A ^ m * (A ^ n)⁻¹ := by rw [← tsub_add_cancel_of_le h, pow_add, Matrix.mul_assoc, mul_nonsing_inv, tsub_add_cancel_of_le h, Matrix.mul_one] simpa using ha.pow n theorem pow_inv_comm' (A : M) (m n : ℕ) : A⁻¹ ^ m * A ^ n = A ^ n * A⁻¹ ^ m := by induction n generalizing m with | zero => simp | succ n IH => rcases m with m | m · simp rcases nonsing_inv_cancel_or_zero A with ⟨h, h'⟩ | h · calc A⁻¹ ^ (m + 1) * A ^ (n + 1) = A⁻¹ ^ m * (A⁻¹ * A) * A ^ n := by simp only [pow_succ A⁻¹, pow_succ' A, Matrix.mul_assoc] _ = A ^ n * A⁻¹ ^ m := by simp only [h, Matrix.mul_one, IH m] _ = A ^ n * (A * A⁻¹) * A⁻¹ ^ m := by simp only [h', Matrix.mul_one] _ = A ^ (n + 1) * A⁻¹ ^ (m + 1) := by simp only [pow_succ A, pow_succ' A⁻¹, Matrix.mul_assoc] · simp [h] end NatPow section ZPow open Int @[simp] theorem one_zpow : ∀ n : ℤ, (1 : M) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | -[n+1] => by rw [zpow_negSucc, one_pow, inv_one] theorem zero_zpow : ∀ z : ℤ, z ≠ 0 → (0 : M) ^ z = 0 | (n : ℕ), h => by rw [zpow_natCast, zero_pow] exact mod_cast h | -[n+1], _ => by simp [zero_pow n.succ_ne_zero] theorem zero_zpow_eq (n : ℤ) : (0 : M) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, zpow_zero] · rw [zero_zpow _ h] theorem inv_zpow (A : M) : ∀ n : ℤ, A⁻¹ ^ n = (A ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow'] | -[n+1] => by rw [zpow_negSucc, zpow_negSucc, inv_pow'] @[simp] theorem zpow_neg_one (A : M) : A ^ (-1 : ℤ) = A⁻¹ := by convert DivInvMonoid.zpow_neg' 0 A simp only [zpow_one, Int.ofNat_zero, Int.natCast_succ, zpow_eq_pow, zero_add] @[simp] theorem zpow_neg_natCast (A : M) (n : ℕ) : A ^ (-n : ℤ) = (A ^ n)⁻¹ := by cases n · simp · exact DivInvMonoid.zpow_neg' _ _ theorem _root_.IsUnit.det_zpow {A : M} (h : IsUnit A.det) (n : ℤ) : IsUnit (A ^ n).det := by rcases n with n | n · simpa using h.pow n · simpa using h.pow n.succ theorem isUnit_det_zpow_iff {A : M} {z : ℤ} : IsUnit (A ^ z).det ↔ IsUnit A.det ∨ z = 0 := by induction z with | zero => simp | succ z => rw [← Int.natCast_succ, zpow_natCast, det_pow, isUnit_pow_succ_iff, ← Int.ofNat_zero, Int.ofNat_inj] simp | pred z => rw [← neg_add', ← Int.natCast_succ, zpow_neg_natCast, isUnit_nonsing_inv_det_iff, det_pow, isUnit_pow_succ_iff, neg_eq_zero, ← Int.ofNat_zero, Int.ofNat_inj] simp theorem zpow_neg {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (-n) = (A ^ n)⁻¹ | (n : ℕ) => zpow_neg_natCast _ _ | -[n+1] => by rw [zpow_negSucc, neg_negSucc, zpow_natCast, nonsing_inv_nonsing_inv] rw [det_pow] exact h.pow _ theorem inv_zpow' {A : M} (h : IsUnit A.det) (n : ℤ) : A⁻¹ ^ n = A ^ (-n) := by rw [zpow_neg h, inv_zpow] theorem zpow_add_one {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (n + 1) = A ^ n * A | (n : ℕ) => by simp only [← Nat.cast_succ, pow_succ, zpow_natCast] | -[n+1] => calc A ^ (-(n + 1) + 1 : ℤ) = (A ^ n)⁻¹ := by rw [neg_add, neg_add_cancel_right, zpow_neg h, zpow_natCast] _ = (A * A ^ n)⁻¹ * A := by rw [mul_inv_rev, Matrix.mul_assoc, nonsing_inv_mul _ h, Matrix.mul_one] _ = A ^ (-(n + 1 : ℤ)) * A := by rw [zpow_neg h, ← Int.natCast_succ, zpow_natCast, pow_succ'] theorem zpow_sub_one {A : M} (h : IsUnit A.det) (n : ℤ) : A ^ (n - 1) = A ^ n * A⁻¹ := calc A ^ (n - 1) = A ^ (n - 1) * A * A⁻¹ := by rw [mul_assoc, mul_nonsing_inv _ h, mul_one] _ = A ^ n * A⁻¹ := by rw [← zpow_add_one h, sub_add_cancel] theorem zpow_add {A : M} (ha : IsUnit A.det) (m n : ℤ) : A ^ (m + n) = A ^ m * A ^ n := by induction n with | zero => simp | succ n ihn => simp only [← add_assoc, zpow_add_one ha, ihn, mul_assoc] | pred n ihn => rw [zpow_sub_one ha, ← mul_assoc, ← ihn, ← zpow_sub_one ha, add_sub_assoc] theorem zpow_add_of_nonpos {A : M} {m n : ℤ} (hm : m ≤ 0) (hn : n ≤ 0) : A ^ (m + n) = A ^ m * A ^ n := by rcases nonsing_inv_cancel_or_zero A with (⟨h, _⟩ | h) · exact zpow_add (isUnit_det_of_left_inverse h) m n · obtain ⟨k, rfl⟩ := exists_eq_neg_ofNat hm obtain ⟨l, rfl⟩ := exists_eq_neg_ofNat hn simp_rw [← neg_add, ← Int.natCast_add, zpow_neg_natCast, ← inv_pow', h, pow_add] theorem zpow_add_of_nonneg {A : M} {m n : ℤ} (hm : 0 ≤ m) (hn : 0 ≤ n) : A ^ (m + n) = A ^ m * A ^ n := by obtain ⟨k, rfl⟩ := eq_ofNat_of_zero_le hm obtain ⟨l, rfl⟩ := eq_ofNat_of_zero_le hn rw [← Int.natCast_add, zpow_natCast, zpow_natCast, zpow_natCast, pow_add] theorem zpow_one_add {A : M} (h : IsUnit A.det) (i : ℤ) : A ^ (1 + i) = A * A ^ i := by rw [zpow_add h, zpow_one] theorem SemiconjBy.zpow_right {A X Y : M} (hx : IsUnit X.det) (hy : IsUnit Y.det) (h : SemiconjBy A X Y) : ∀ m : ℤ, SemiconjBy A (X ^ m) (Y ^ m) | (n : ℕ) => by simp [h.pow_right n] | -[n+1] => by have hx' : IsUnit (X ^ n.succ).det := by rw [det_pow] exact hx.pow n.succ have hy' : IsUnit (Y ^ n.succ).det := by rw [det_pow] exact hy.pow n.succ rw [zpow_negSucc, zpow_negSucc, nonsing_inv_apply _ hx', nonsing_inv_apply _ hy', SemiconjBy] refine (isRegular_of_isLeftRegular_det hy'.isRegular.left).left ?_ dsimp only rw [← mul_assoc, ← (h.pow_right n.succ).eq, mul_assoc, mul_smul, mul_adjugate, ← Matrix.mul_assoc, mul_smul (Y ^ _) (↑hy'.unit⁻¹ : R), mul_adjugate, smul_smul, smul_smul, hx'.val_inv_mul, hy'.val_inv_mul, one_smul, Matrix.mul_one, Matrix.one_mul] theorem Commute.zpow_right {A B : M} (h : Commute A B) (m : ℤ) : Commute A (B ^ m) := by rcases nonsing_inv_cancel_or_zero B with (⟨hB, _⟩ | hB) · refine SemiconjBy.zpow_right ?_ ?_ h _ <;> exact isUnit_det_of_left_inverse hB · cases m · simpa using h.pow_right _ · simp [← inv_pow', hB] theorem Commute.zpow_left {A B : M} (h : Commute A B) (m : ℤ) : Commute (A ^ m) B := (Commute.zpow_right h.symm m).symm theorem Commute.zpow_zpow {A B : M} (h : Commute A B) (m n : ℤ) : Commute (A ^ m) (B ^ n) := Commute.zpow_right (Commute.zpow_left h _) _ theorem Commute.zpow_self (A : M) (n : ℤ) : Commute (A ^ n) A := Commute.zpow_left (Commute.refl A) _ theorem Commute.self_zpow (A : M) (n : ℤ) : Commute A (A ^ n) := Commute.zpow_right (Commute.refl A) _ theorem Commute.zpow_zpow_self (A : M) (m n : ℤ) : Commute (A ^ m) (A ^ n) := Commute.zpow_zpow (Commute.refl A) _ _ theorem zpow_add_one_of_ne_neg_one {A : M} : ∀ n : ℤ, n ≠ -1 → A ^ (n + 1) = A ^ n * A | (n : ℕ), _ => by simp only [pow_succ, ← Nat.cast_succ, zpow_natCast] | -1, h => absurd rfl h | -((n : ℕ) + 2), _ => by rcases nonsing_inv_cancel_or_zero A with (⟨h, _⟩ | h) · apply zpow_add_one (isUnit_det_of_left_inverse h) · change A ^ (-((n + 1 : ℕ) : ℤ)) = A ^ (-((n + 2 : ℕ) : ℤ)) * A simp_rw [zpow_neg_natCast, ← inv_pow', h, zero_pow <| Nat.succ_ne_zero _, zero_mul] theorem zpow_mul (A : M) (h : IsUnit A.det) : ∀ m n : ℤ, A ^ (m * n) = (A ^ m) ^ n | (m : ℕ), (n : ℕ) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast, Int.natCast_mul] | (m : ℕ), -[n+1] => by rw [zpow_natCast, zpow_negSucc, ← pow_mul, ofNat_mul_negSucc, zpow_neg_natCast] | -[m+1], (n : ℕ) => by rw [zpow_natCast, zpow_negSucc, ← inv_pow', ← pow_mul, negSucc_mul_ofNat, zpow_neg_natCast, inv_pow'] | -[m+1], -[n+1] => by rw [zpow_negSucc, zpow_negSucc, negSucc_mul_negSucc, ← Int.natCast_mul, zpow_natCast, inv_pow', ← pow_mul, nonsing_inv_nonsing_inv] rw [det_pow] exact h.pow _ theorem zpow_mul' (A : M) (h : IsUnit A.det) (m n : ℤ) : A ^ (m * n) = (A ^ n) ^ m := by rw [mul_comm, zpow_mul _ h] @[simp, norm_cast] theorem coe_units_zpow (u : Mˣ) : ∀ n : ℤ, ((u ^ n : Mˣ) : M) = (u : M) ^ n | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, Units.val_pow_eq_pow_val] | -[k+1] => by rw [zpow_negSucc, zpow_negSucc, ← inv_pow, u⁻¹.val_pow_eq_pow_val, ← inv_pow', coe_units_inv] theorem zpow_ne_zero_of_isUnit_det [Nonempty n'] [Nontrivial R] {A : M} (ha : IsUnit A.det) (z : ℤ) : A ^ z ≠ 0 := by have := ha.det_zpow z contrapose! this rw [this, det_zero ‹_›] exact not_isUnit_zero theorem zpow_sub {A : M} (ha : IsUnit A.det) (z1 z2 : ℤ) : A ^ (z1 - z2) = A ^ z1 / A ^ z2 := by rw [sub_eq_add_neg, zpow_add ha, zpow_neg ha, div_eq_mul_inv] theorem Commute.mul_zpow {A B : M} (h : Commute A B) : ∀ i : ℤ, (A * B) ^ i = A ^ i * B ^ i | (n : ℕ) => by simp [h.mul_pow n] | -[n+1] => by rw [zpow_negSucc, zpow_negSucc, zpow_negSucc, ← mul_inv_rev, h.mul_pow n.succ, (h.pow_pow _ _).eq] theorem zpow_neg_mul_zpow_self (n : ℤ) {A : M} (h : IsUnit A.det) : A ^ (-n) * A ^ n = 1 := by rw [zpow_neg h, nonsing_inv_mul _ (h.det_zpow _)] theorem one_div_pow {A : M} (n : ℕ) : (1 / A) ^ n = 1 / A ^ n := by simp only [one_div, inv_pow'] theorem one_div_zpow {A : M} (n : ℤ) : (1 / A) ^ n = 1 / A ^ n := by simp only [one_div, inv_zpow] @[simp] theorem transpose_zpow (A : M) : ∀ n : ℤ, (A ^ n)ᵀ = Aᵀ ^ n | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, transpose_pow] | -[n+1] => by rw [zpow_negSucc, zpow_negSucc, transpose_nonsing_inv, transpose_pow] @[simp] theorem conjTranspose_zpow [StarRing R] (A : M) : ∀ n : ℤ, (A ^ n)ᴴ = Aᴴ ^ n | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, conjTranspose_pow] | -[n+1] => by rw [zpow_negSucc, zpow_negSucc, conjTranspose_nonsing_inv, conjTranspose_pow] theorem IsSymm.zpow {A : M} (h : A.IsSymm) (k : ℤ) : (A ^ k).IsSymm := by rw [IsSymm, transpose_zpow, h] end ZPow end Matrix
Associator.lean
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Robin Carlier -/ import Mathlib.CategoryTheory.Sums.Basic /-! # Associator for binary disjoint union of categories. The associator functor `((C ⊕ D) ⊕ E) ⥤ (C ⊕ (D ⊕ E))` and its inverse form an equivalence. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory open Sum Functor namespace CategoryTheory.sum variable (C : Type u₁) [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D] (E : Type u₃) [Category.{v₃} E] /-- The associator functor `(C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E)` for sums of categories. -/ def associator : (C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E) := (inl_ C (D ⊕ E) |>.sum' <| inl_ D E ⋙ inr_ C (D ⊕ E)).sum' <| inr_ D E ⋙ inr_ C (D ⊕ E) @[simp] theorem associator_obj_inl_inl (X) : (associator C D E).obj (inl (inl X)) = inl X := rfl @[simp] theorem associator_obj_inl_inr (X) : (associator C D E).obj (inl (inr X)) = inr (inl X) := rfl @[simp] theorem associator_obj_inr (X) : (associator C D E).obj (inr X) = inr (inr X) := rfl @[simp] theorem associator_map_inl_inl {X Y : C} (f : X ⟶ Y) : (associator C D E).map ((inl_ _ _).map ((inl_ _ _).map f)) = (inl_ _ _).map f := rfl @[simp] theorem associator_map_inl_inr {X Y : D} (f : X ⟶ Y) : (associator C D E).map ((inl_ _ _).map ((inr_ _ _).map f)) = (inr_ _ _).map ((inl_ _ _).map f) := by simp [associator] @[simp] theorem associator_map_inr {X Y : E} (f : X ⟶ Y) : (associator C D E).map ((inr_ _ _).map f) = (inr_ _ _).map ((inr_ _ _).map f) := by simp [associator] /-- Characterizing the composition of the associator and the left inclusion. -/ @[simps!] def inlCompAssociator : inl_ (C ⊕ D) E ⋙ associator C D E ≅ inl_ C (D ⊕ E) |>.sum' <| inl_ D E ⋙ inr_ C (D ⊕ E) := (Functor.inlCompSum' _ _) /-- Characterizing the composition of the associator and the right inclusion. -/ @[simps!] def inrCompAssociator : inr_ (C ⊕ D) E ⋙ associator C D E ≅ inr_ D E ⋙ inr_ C (D ⊕ E) := (Functor.inrCompSum' _ _) /-- Further characterizing the composition of the associator and the left inclusion. -/ @[simps!] def inlCompInlCompAssociator : inl_ C D ⋙ inl_ (C ⊕ D) E ⋙ associator C D E ≅ inl_ C (D ⊕ E) := isoWhiskerLeft (inl_ _ _) (inlCompAssociator C D E) ≪≫ Functor.inlCompSum' _ _ /-- Further characterizing the composition of the associator and the left inclusion. -/ @[simps!] def inrCompInlCompAssociator : inr_ C D ⋙ inl_ (C ⊕ D) E ⋙ associator C D E ≅ inl_ D E ⋙ inr_ C (D ⊕ E) := isoWhiskerLeft (inr_ _ _) (inlCompAssociator C D E) ≪≫ Functor.inrCompSum' _ _ /-- The inverse associator functor `C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E` for sums of categories. -/ def inverseAssociator : C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E := inl_ C D ⋙ inl_ (C ⊕ D) E |>.sum' <| (inr_ C D ⋙ inl_ (C ⊕ D) E).sum' <| inr_ (C ⊕ D) E @[simp] theorem inverseAssociator_obj_inl (X) : (inverseAssociator C D E).obj (inl X) = inl (inl X) := rfl @[simp] theorem inverseAssociator_obj_inr_inl (X) : (inverseAssociator C D E).obj (inr (inl X)) = inl (inr X) := rfl @[simp] theorem inverseAssociator_obj_inr_inr (X) : (inverseAssociator C D E).obj (inr (inr X)) = inr X := rfl @[simp] theorem inverseAssociator_map_inl {X Y : C} (f : X ⟶ Y) : (inverseAssociator C D E).map ((inl_ _ _).map f) = (inl_ _ _).map ((inl_ _ _).map f) := by simp [inverseAssociator] @[simp] theorem inverseAssociator_map_inr_inl {X Y : D} (f : X ⟶ Y) : (inverseAssociator C D E).map ((inr_ _ _).map ((inl_ _ _).map f)) = (inl_ _ _).map ((inr_ _ _).map f) := by simp [inverseAssociator] @[simp] theorem inverseAssociator_map_inr_inr {X Y : E} (f : X ⟶ Y) : (inverseAssociator C D E).map ((inr_ _ _).map ((inr_ _ _).map f)) = (inr_ _ _).map f := rfl /-- Characterizing the composition of the inverse of the associator and the left inclusion. -/ @[simps!] def inlCompInverseAssociator : inl_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ inl_ C D ⋙ inl_ (C ⊕ D) E := Functor.inlCompSum' _ _ /-- Characterizing the composition of the inverse of the associator and the right inclusion. -/ @[simps!] def inrCompInverseAssociator : inr_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ (inr_ C D ⋙ inl_ (C ⊕ D) E).sum' <| inr_ (C ⊕ D) E := Functor.inrCompSum' _ _ /-- Further characterizing the composition of the inverse of the associator and the right inclusion. -/ @[simps!] def inlCompInrCompInverseAssociator : inl_ D E ⋙ inr_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ inr_ C D ⋙ inl_ (C ⊕ D) E := isoWhiskerLeft (inl_ _ _) (inrCompInverseAssociator C D E) ≪≫ Functor.inlCompSum' _ _ /-- Further characterizing the composition of the inverse of the associator and the right inclusion. -/ @[simps!] def inrCompInrCompInverseAssociator : inr_ D E ⋙ inr_ C (D ⊕ E) ⋙ inverseAssociator C D E ≅ inr_ (C ⊕ D) E := isoWhiskerLeft (inr_ _ _) (inrCompInverseAssociator C D E) ≪≫ Functor.inrCompSum' _ _ /-- The equivalence of categories expressing associativity of sums of categories. -/ @[simps functor inverse] def associativity : (C ⊕ D) ⊕ E ≌ C ⊕ (D ⊕ E) where functor := associator C D E inverse := inverseAssociator C D E unitIso := Functor.sumIsoExt (Functor.sumIsoExt ((Functor.associator _ _ _).symm ≪≫ Functor.rightUnitor _ ≪≫ (isoWhiskerRight (inlCompInlCompAssociator C D E) (inverseAssociator C D E) ≪≫ inlCompInverseAssociator C D E).symm ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Functor.associator _ _ _)) ((Functor.associator _ _ _).symm ≪≫ Functor.rightUnitor _ ≪≫ (isoWhiskerRight (inrCompInlCompAssociator C D E) (inverseAssociator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inlCompInrCompInverseAssociator C D E).symm ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Functor.associator _ _ _))) (Functor.rightUnitor _ ≪≫ (isoWhiskerRight (inrCompAssociator C D E) (inverseAssociator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inrCompInrCompInverseAssociator C D E).symm ≪≫ Functor.associator _ _ _) counitIso := Functor.sumIsoExt ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (inlCompInverseAssociator C D E) (associator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inlCompInlCompAssociator C D E ≪≫ (Functor.rightUnitor _).symm) (Functor.sumIsoExt ((Functor.associator _ _ _).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (Functor.associator _ _ _ ≪≫ inlCompInrCompInverseAssociator C D E) (associator C D E) ≪≫ Functor.associator _ _ _ ≪≫ inrCompInlCompAssociator C D E ≪≫ (Functor.rightUnitor _).symm ≪≫ Functor.associator _ _ _) ((Functor.associator _ _ _).symm ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (Functor.associator _ _ _ ≪≫ inrCompInrCompInverseAssociator C D E) (associator C D E) ≪≫ inrCompAssociator C D E ≪≫ isoWhiskerLeft _ (Functor.rightUnitor _).symm)) functor_unitIso_comp x := match x with | inl (inl c) => by simp [inlCompInlCompAssociator, inlCompInverseAssociator] | inl (inr d) => by simp [inrCompInlCompAssociator, inlCompInrCompInverseAssociator] | inr e => by simp [inrCompAssociator, inrCompInrCompInverseAssociator] instance associatorIsEquivalence : (associator C D E).IsEquivalence := (by infer_instance : (associativity C D E).functor.IsEquivalence) instance inverseAssociatorIsEquivalence : (inverseAssociator C D E).IsEquivalence := (by infer_instance : (associativity C D E).inverse.IsEquivalence) -- TODO unitors? -- TODO pentagon natural transformation? ...satisfying? end CategoryTheory.sum
Cast.lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Group.Abs import Mathlib.Algebra.Order.Ring.Int import Mathlib.Data.Nat.Cast.Order.Ring /-! # Order properties of cast of integers This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`), particularly results involving algebraic homomorphisms or the order structure on `ℤ` which were not available in the import dependencies of `Mathlib/Data/Int/Cast/Basic.lean`. ## TODO Move order lemmas about `Nat.cast`, `Rat.cast`, `NNRat.cast` here. -/ open Function Nat variable {R : Type*} namespace Int section OrderedAddCommGroupWithOne variable [AddCommGroupWithOne R] [PartialOrder R] [AddLeftMono R] variable [ZeroLEOneClass R] lemma cast_mono : Monotone (Int.cast : ℤ → R) := by intro m n h rw [← sub_nonneg] at h lift n - m to ℕ using h with k hk rw [← sub_nonneg, ← cast_sub, ← hk, cast_natCast] exact k.cast_nonneg' @[gcongr] protected lemma GCongr.intCast_mono {m n : ℤ} (hmn : m ≤ n) : (m : R) ≤ n := cast_mono hmn variable [NeZero (1 : R)] {m n : ℤ} @[simp] lemma cast_nonneg : ∀ {n : ℤ}, (0 : R) ≤ n ↔ 0 ≤ n | (n : ℕ) => by simp | -[n+1] => by have : -(n : R) < 1 := lt_of_le_of_lt (by simp) zero_lt_one simpa [(negSucc_lt_zero n).not_ge, ← sub_eq_add_neg, le_neg] using this.not_ge @[simp, norm_cast] lemma cast_le : (m : R) ≤ n ↔ m ≤ n := by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg] lemma cast_strictMono : StrictMono (fun x : ℤ => (x : R)) := strictMono_of_le_iff_le fun _ _ => cast_le.symm @[simp, norm_cast] lemma cast_lt : (m : R) < n ↔ m < n := cast_strictMono.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.intCast_strictMono⟩ := Int.cast_lt @[simp] lemma cast_nonpos : (n : R) ≤ 0 ↔ n ≤ 0 := by rw [← cast_zero, cast_le] @[simp] lemma cast_pos : (0 : R) < n ↔ 0 < n := by rw [← cast_zero, cast_lt] @[simp] lemma cast_lt_zero : (n : R) < 0 ↔ n < 0 := by rw [← cast_zero, cast_lt] end OrderedAddCommGroupWithOne section LinearOrderedRing variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] {a b n : ℤ} {x : R} @[simp, norm_cast] lemma cast_min : ↑(min a b) = (min a b : R) := Monotone.map_min cast_mono @[simp, norm_cast] lemma cast_max : (↑(max a b) : R) = max (a : R) (b : R) := Monotone.map_max cast_mono @[simp, norm_cast] lemma cast_abs : (↑|a| : R) = |(a : R)| := by simp [abs_eq_max_neg] lemma cast_one_le_of_pos (h : 0 < a) : (1 : R) ≤ a := mod_cast Int.add_one_le_of_lt h lemma cast_le_neg_one_of_neg (h : a < 0) : (a : R) ≤ -1 := by rw [← Int.cast_one, ← Int.cast_neg, cast_le] exact Int.le_sub_one_of_lt h variable (R) in lemma cast_le_neg_one_or_one_le_cast_of_ne_zero (hn : n ≠ 0) : (n : R) ≤ -1 ∨ 1 ≤ (n : R) := hn.lt_or_gt.imp cast_le_neg_one_of_neg cast_one_le_of_pos lemma nneg_mul_add_sq_of_abs_le_one (n : ℤ) (hx : |x| ≤ 1) : (0 : R) ≤ n * x + n * n := by have hnx : 0 < n → 0 ≤ x + n := fun hn => by have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn) rwa [neg_add_cancel] at this have hnx' : n < 0 → x + n ≤ 0 := fun hn => by have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn) rwa [add_neg_cancel] at this rw [← mul_add, mul_nonneg_iff] rcases lt_trichotomy n 0 with (h | rfl | h) · exact Or.inr ⟨mod_cast h.le, hnx' h⟩ · simp [le_total 0 x] · exact Or.inl ⟨mod_cast h.le, hnx h⟩ -- TODO: move to a better place omit [LinearOrder R] [IsStrictOrderedRing R] in lemma cast_natAbs : (n.natAbs : R) = |n| := by cases n · simp · rw [abs_eq_natAbs, natAbs_negSucc, cast_succ, cast_natCast, cast_succ] end LinearOrderedRing end Int /-! ### Order dual -/ open OrderDual namespace OrderDual instance instIntCast [IntCast R] : IntCast Rᵒᵈ := ‹_› instance instAddGroupWithOne [AddGroupWithOne R] : AddGroupWithOne Rᵒᵈ := ‹_› instance instAddCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne Rᵒᵈ := ‹_› end OrderDual @[simp] lemma toDual_intCast [IntCast R] (n : ℤ) : toDual (n : R) = n := rfl @[simp] lemma ofDual_intCast [IntCast R] (n : ℤ) : (ofDual n : R) = n := rfl /-! ### Lexicographic order -/ namespace Lex instance instIntCast [IntCast R] : IntCast (Lex R) := ‹_› instance instAddGroupWithOne [AddGroupWithOne R] : AddGroupWithOne (Lex R) := ‹_› instance instAddCommGroupWithOne [AddCommGroupWithOne R] : AddCommGroupWithOne (Lex R) := ‹_› end Lex @[simp] lemma toLex_intCast [IntCast R] (n : ℤ) : toLex (n : R) = n := rfl @[simp] lemma ofLex_intCast [IntCast R] (n : ℤ) : (ofLex n : R) = n := rfl
NaturalTransformation.lean
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Monoidal.Functor import Mathlib.CategoryTheory.ObjectProperty.FullSubcategory /-! # Monoidal natural transformations Natural transformations between (lax) monoidal functors must satisfy an additional compatibility relation with the tensorators: `F.μ X Y ≫ app (X ⊗ Y) = (app X ⊗ app Y) ≫ G.μ X Y`. -/ open CategoryTheory universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ open CategoryTheory.Category open CategoryTheory.Functor namespace CategoryTheory open MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] {D : Type u₂} [Category.{v₂} D] [MonoidalCategory D] {E : Type u₃} [Category.{v₃} E] [MonoidalCategory E] {E' : Type u₄} [Category.{v₄} E'] [MonoidalCategory E'] variable {F₁ F₂ F₃ : C ⥤ D} (τ : F₁ ⟶ F₂) [F₁.LaxMonoidal] [F₂.LaxMonoidal] [F₃.LaxMonoidal] namespace NatTrans open Functor.LaxMonoidal /-- A natural transformation between (lax) monoidal functors is monoidal if it satisfies `ε F ≫ τ.app (𝟙_ C) = ε G` and `μ F X Y ≫ app (X ⊗ Y) = (app X ⊗ₘ app Y) ≫ μ G X Y`. -/ class IsMonoidal : Prop where unit : ε F₁ ≫ τ.app (𝟙_ C) = ε F₂ := by cat_disch tensor (X Y : C) : μ F₁ _ _ ≫ τ.app (X ⊗ Y) = (τ.app X ⊗ₘ τ.app Y) ≫ μ F₂ _ _ := by cat_disch namespace IsMonoidal attribute [reassoc (attr := simp)] unit tensor instance id : IsMonoidal (𝟙 F₁) where instance comp (τ' : F₂ ⟶ F₃) [IsMonoidal τ] [IsMonoidal τ'] : IsMonoidal (τ ≫ τ') where instance hcomp {G₁ G₂ : D ⥤ E} [G₁.LaxMonoidal] [G₂.LaxMonoidal] (τ' : G₁ ⟶ G₂) [IsMonoidal τ] [IsMonoidal τ'] : IsMonoidal (τ ◫ τ') where unit := by simp only [comp_obj, comp_ε, hcomp_app, assoc, naturality_assoc, unit_assoc, ← map_comp, unit] tensor X Y := by simp only [comp_obj, comp_μ, hcomp_app, assoc, naturality_assoc, tensor_assoc, tensor_comp, μ_natural_assoc] simp only [← map_comp, tensor] instance (F : C ⥤ D) [F.LaxMonoidal] : NatTrans.IsMonoidal F.leftUnitor.hom where instance (F : C ⥤ D) [F.LaxMonoidal] : NatTrans.IsMonoidal F.rightUnitor.hom where instance (F : C ⥤ D) (G : D ⥤ E) (H : E ⥤ E') [F.LaxMonoidal] [G.LaxMonoidal] [H.LaxMonoidal] : NatTrans.IsMonoidal (Functor.associator F G H).hom where unit := by simp only [comp_obj, comp_ε, assoc, Functor.map_comp, associator_hom_app, comp_id, Functor.comp_map] tensor X Y := by simp only [comp_obj, comp_μ, associator_hom_app, Functor.comp_map, map_comp, comp_id, tensorHom_id, id_whiskerRight, assoc, id_comp] end IsMonoidal instance {F G : C ⥤ D} {H K : C ⥤ E} (α : F ⟶ G) (β : H ⟶ K) [F.LaxMonoidal] [G.LaxMonoidal] [IsMonoidal α] [H.LaxMonoidal] [K.LaxMonoidal] [IsMonoidal β] : IsMonoidal (NatTrans.prod' α β) where unit := by ext · rw [prod_comp_fst, prod'_ε_fst, prod'_ε_fst, prod'_app_fst, IsMonoidal.unit] · rw [prod_comp_snd, prod'_ε_snd, prod'_ε_snd, prod'_app_snd, IsMonoidal.unit] tensor X Y := by ext · simp only [prod_comp_fst, prod'_μ_fst, prod'_app_fst, prodMonoidal_tensorHom, IsMonoidal.tensor] · simp only [prod_comp_snd, prod'_μ_snd, prod'_app_snd, prodMonoidal_tensorHom, IsMonoidal.tensor] end NatTrans namespace Iso variable (e : F₁ ≅ F₂) [NatTrans.IsMonoidal e.hom] instance : NatTrans.IsMonoidal e.inv where unit := by rw [← NatTrans.IsMonoidal.unit (τ := e.hom), assoc, hom_inv_id_app, comp_id] tensor X Y := by rw [← cancel_mono (e.hom.app (X ⊗ Y)), assoc, assoc, inv_hom_id_app, comp_id, NatTrans.IsMonoidal.tensor, ← MonoidalCategory.tensor_comp_assoc, inv_hom_id_app, inv_hom_id_app, tensorHom_id, id_whiskerRight, id_comp] end Iso namespace Adjunction variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) open Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal namespace IsMonoidal variable [F.Monoidal] [G.LaxMonoidal] [adj.IsMonoidal] instance : NatTrans.IsMonoidal adj.unit where unit := by dsimp rw [id_comp, ← unit_app_unit_comp_map_η adj, assoc, Monoidal.map_η_ε] dsimp rw [comp_id] tensor X Y := by dsimp rw [← unit_app_tensor_comp_map_δ_assoc, id_comp, Monoidal.map_δ_μ, comp_id] instance : NatTrans.IsMonoidal adj.counit where unit := by dsimp rw [assoc, map_ε_comp_counit_app_unit adj, ε_η] tensor X Y := by dsimp rw [assoc, map_μ_comp_counit_app_tensor, μ_δ_assoc, comp_id] end IsMonoidal namespace Equivalence variable (e : C ≌ D) [e.functor.Monoidal] [e.inverse.Monoidal] [e.IsMonoidal] instance : NatTrans.IsMonoidal e.unit := inferInstanceAs (NatTrans.IsMonoidal e.toAdjunction.unit) instance : NatTrans.IsMonoidal e.counit := inferInstanceAs (NatTrans.IsMonoidal e.toAdjunction.counit) end Equivalence end Adjunction namespace LaxMonoidalFunctor /-- The type of monoidal natural transformations between (bundled) lax monoidal functors. -/ structure Hom (F G : LaxMonoidalFunctor C D) where /-- the natural transformation between the underlying functors -/ hom : F.toFunctor ⟶ G.toFunctor isMonoidal : NatTrans.IsMonoidal hom := by infer_instance attribute [instance] Hom.isMonoidal instance : Category (LaxMonoidalFunctor C D) where Hom := Hom comp α β := ⟨α.1 ≫ β.1, by have := α.2; have := β.2; infer_instance⟩ id _ := ⟨𝟙 _, inferInstance⟩ @[simp] lemma id_hom (F : LaxMonoidalFunctor C D) : Hom.hom (𝟙 F) = 𝟙 _ := rfl @[reassoc, simp] lemma comp_hom {F G H : LaxMonoidalFunctor C D} (α : F ⟶ G) (β : G ⟶ H) : (α ≫ β).hom = α.hom ≫ β.hom := rfl @[ext] lemma hom_ext {F G : LaxMonoidalFunctor C D} {α β : F ⟶ G} (h : α.hom = β.hom) : α = β := by cases α; cases β; subst h; rfl /-- Constructor for morphisms in the category `LaxMonoidalFunctor C D`. -/ @[simps] def homMk {F G : LaxMonoidalFunctor C D} (f : F.toFunctor ⟶ G.toFunctor) [NatTrans.IsMonoidal f] : F ⟶ G := ⟨f, inferInstance⟩ /-- Constructor for isomorphisms in the category `LaxMonoidalFunctor C D`. -/ @[simps] def isoMk {F G : LaxMonoidalFunctor C D} (e : F.toFunctor ≅ G.toFunctor) [NatTrans.IsMonoidal e.hom] : F ≅ G where hom := homMk e.hom inv := homMk e.inv open Functor.LaxMonoidal /-- Constructor for isomorphisms between lax monoidal functors. -/ @[simps!] def isoOfComponents {F G : LaxMonoidalFunctor C D} (e : ∀ X, F.obj X ≅ G.obj X) (naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (e Y).hom = (e X).hom ≫ G.map f := by cat_disch) (unit : ε F.toFunctor ≫ (e (𝟙_ C)).hom = ε G.toFunctor := by cat_disch) (tensor : ∀ X Y, μ F.toFunctor X Y ≫ (e (X ⊗ Y)).hom = ((e X).hom ⊗ₘ (e Y).hom) ≫ μ G.toFunctor X Y := by cat_disch) : F ≅ G := @isoMk _ _ _ _ _ _ _ _ (NatIso.ofComponents e naturality) (by constructor <;> assumption) end LaxMonoidalFunctor end CategoryTheory
imset2_gproduct.v
From mathcomp Require Import all_boot all_fingroup. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Open Scope group_scope. Check @ker_sdprodm.
TruncLEHomology.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.Embedding.TruncGEHomology import Mathlib.Algebra.Homology.Embedding.TruncLE import Mathlib.Algebra.Homology.HomologySequence import Mathlib.Algebra.Homology.ShortComplex.Abelian import Mathlib.Algebra.Homology.HomologicalComplexAbelian /-! # The homology of a canonical truncation Given an embedding of complex shapes `e : Embedding c c'`, we relate the homology of `K : HomologicalComplex C c'` and of `K.truncLE e : HomologicalComplex C c'`. The main result is that `K.ιTruncLE e : K.truncLE e ⟶ K` induces a quasi-isomorphism in degree `e.f i` for all `i`. (Note that the complex `K.truncLE e` is exact in degrees that are not in the image of `e.f`.) All the results are obtained by dualising the results in the file `Embedding.TruncGEHomology`. Moreover, if `C` is an abelian category, we introduce the cokernel sequence `K.shortComplexTruncLE e` of the monomorphism `K.ιTruncLE e`. -/ open CategoryTheory Category Limits namespace HomologicalComplex variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'} {C : Type*} [Category C] section variable [HasZeroMorphisms C] (K L : HomologicalComplex C c') (φ : K ⟶ L) (e : c.Embedding c') [e.IsTruncLE] [∀ i', K.HasHomology i'] [∀ i', L.HasHomology i'] namespace truncLE' /-- `K.truncLE'ToRestriction e` is a quasi-isomorphism in degrees that are not at the boundary. -/ lemma quasiIsoAt_truncLE'ToRestriction (j : ι) (hj : ¬ e.BoundaryLE j) [(K.restriction e).HasHomology j] [(K.truncLE' e).HasHomology j] : QuasiIsoAt (K.truncLE'ToRestriction e) j := by dsimp only [truncLE'ToRestriction] have : (K.op.restriction e.op).HasHomology j := inferInstanceAs ((K.restriction e).op.HasHomology j) rw [quasiIsoAt_unopFunctor_map_iff] exact truncGE'.quasiIsoAt_restrictionToTruncGE' K.op e.op j (by simpa) instance truncLE'_hasHomology (i : ι) : (K.truncLE' e).HasHomology i := inferInstanceAs ((K.op.truncGE' e.op).unop.HasHomology i) end truncLE' variable [HasZeroObject C] instance (i' : ι') : (K.truncLE e).HasHomology i' := inferInstanceAs ((K.op.truncGE e.op).unop.HasHomology i') lemma quasiIsoAt_ιTruncLE {j : ι} {j' : ι'} (hj' : e.f j = j') : QuasiIsoAt (K.ιTruncLE e) j' := by have := K.op.quasiIsoAt_πTruncGE e.op hj' exact inferInstanceAs (QuasiIsoAt ((unopFunctor _ _ ).map (K.op.πTruncGE e.op).op) j') instance (i : ι) : QuasiIsoAt (K.ιTruncLE e) (e.f i) := K.quasiIsoAt_ιTruncLE e rfl lemma quasiIso_ιTruncLE_iff_isSupported : QuasiIso (K.ιTruncLE e) ↔ K.IsSupported e := by rw [← quasiIso_opFunctor_map_iff, ← isSupported_op_iff] exact K.op.quasiIso_πTruncGE_iff_isSupported e.op lemma acyclic_truncLE_iff_isSupportedOutside : (K.truncLE e).Acyclic ↔ K.IsSupportedOutside e := by rw [← acyclic_op_iff, ← isSupportedOutside_op_iff] exact K.op.acyclic_truncGE_iff_isSupportedOutside e.op variable {K L} lemma quasiIso_truncLEMap_iff : QuasiIso (truncLEMap φ e) ↔ ∀ (i : ι) (i' : ι') (_ : e.f i = i'), QuasiIsoAt φ i' := by rw [← quasiIso_opFunctor_map_iff] simp only [← quasiIsoAt_opFunctor_map_iff φ] apply quasiIso_truncGEMap_iff end section variable [Abelian C] (K : HomologicalComplex C c') (e : c.Embedding c') [e.IsTruncLE] /-- The cokernel sequence of the monomorphism `K.ιTruncLE e`. -/ @[simps X₁ X₂ f] noncomputable def shortComplexTruncLE : ShortComplex (HomologicalComplex C c') := ShortComplex.mk (K.ιTruncLE e) _ (cokernel.condition _) instance : Mono (K.shortComplexTruncLE e).f := by dsimp [shortComplexTruncLE] infer_instance instance : Epi (K.shortComplexTruncLE e).g := by dsimp [shortComplexTruncLE] infer_instance lemma shortComplexTruncLE_shortExact : (K.shortComplexTruncLE e).ShortExact where exact := ShortComplex.exact_of_g_is_cokernel _ (cokernelIsCokernel _) lemma mono_homologyMap_shortComplexTruncLE_g (i' : ι') (hi' : ∀ i, e.f i ≠ i') : Mono (homologyMap (K.shortComplexTruncLE e).g i') := ((K.shortComplexTruncLE_shortExact e).homology_exact₂ i').mono_g (by apply ((K.truncLE e).exactAt_of_isSupported e i' hi').isZero_homology.eq_of_src) @[simp] lemma shortComplexTruncLE_shortExact_δ_eq_zero (i' j' : ι') (hij' : c'.Rel i' j') : (K.shortComplexTruncLE_shortExact e).δ i' j' hij' = 0 := by by_cases hj : ∃ j, e.f j = j' · obtain ⟨j, rfl⟩ := hj rw [← cancel_mono (homologyMap (K.ιTruncLE e) (e.f j)), zero_comp] exact (K.shortComplexTruncLE_shortExact e).δ_comp i' _ hij' · apply ((K.truncLE e).exactAt_of_isSupported e j' (by simpa using hj)).isZero_homology.eq_of_tgt instance epi_homologyMap_shortComplexTruncLE_g (i' : ι') : Epi (homologyMap (K.shortComplexTruncLE e).g i') := by by_cases hi' : ∃ j', c'.Rel i' j' · obtain ⟨j', hj'⟩ := hi' exact ((K.shortComplexTruncLE_shortExact e).homology_exact₃ i' j' hj').epi_f (by simp) · exact epi_homologyMap_of_epi_of_not_rel _ _ (by simpa using hi') lemma isIso_homologyMap_shortComplexTruncLE_g (i' : ι') (hi' : ∀ i, e.f i ≠ i') : IsIso (homologyMap (K.shortComplexTruncLE e).g i') := by have := K.mono_homologyMap_shortComplexTruncLE_g e i' hi' apply isIso_of_mono_of_epi lemma quasiIsoAt_shortComplexTruncLE_g (i' : ι') (hi' : ∀ i, e.f i ≠ i') : QuasiIsoAt (K.shortComplexTruncLE e).g i' := by rw [quasiIsoAt_iff_isIso_homologyMap] exact K.isIso_homologyMap_shortComplexTruncLE_g e i' hi' lemma shortComplexTruncLE_X₃_isSupportedOutside : (K.shortComplexTruncLE e).X₃.IsSupportedOutside e where exactAt i := by rw [exactAt_iff_isZero_homology] by_cases hi : ∃ j', c'.Rel (e.f i) j' · obtain ⟨j', hj'⟩ := hi apply ((K.shortComplexTruncLE_shortExact e).homology_exact₃ (e.f i) j' hj').isZero_X₂ · rw [← cancel_epi (homologyMap (K.ιTruncLE e) (e.f i)), comp_zero] dsimp [shortComplexTruncLE] rw [← homologyMap_comp, cokernel.condition, homologyMap_zero] · simp · have : IsIso (homologyMap (K.shortComplexTruncLE e).f (e.f i)) := by dsimp; infer_instance rw [IsZero.iff_id_eq_zero, ← cancel_epi (homologyMap (K.shortComplexTruncLE e).g (e.f i)), comp_id, comp_zero, ← cancel_epi (homologyMap (K.shortComplexTruncLE e).f (e.f i)), comp_zero, ← homologyMap_comp, ShortComplex.zero, homologyMap_zero] end end HomologicalComplex
Prod.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Eric Wieser -/ import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Group.Graph import Mathlib.LinearAlgebra.Span.Basic /-! ### Products of modules This file defines constructors for linear maps whose domains or codomains are products. It contains theorems relating these to each other, as well as to `Submodule.prod`, `Submodule.map`, `Submodule.comap`, `LinearMap.range`, and `LinearMap.ker`. ## Main definitions - products in the domain: - `LinearMap.fst` - `LinearMap.snd` - `LinearMap.coprod` - `LinearMap.prod_ext` - products in the codomain: - `LinearMap.inl` - `LinearMap.inr` - `LinearMap.prod` - products in both domain and codomain: - `LinearMap.prodMap` - `LinearEquiv.prodMap` - `LinearEquiv.skewProd` - product with the trivial module: - `LinearEquiv.prodUnique` - `LinearEquiv.uniqueProd` -/ universe u v w x y z u' v' w' y' variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} variable {M₅ M₆ : Type*} section Prod namespace LinearMap variable (S : Type*) [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [AddCommMonoid M₅] [AddCommMonoid M₆] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] variable [Module R M₅] [Module R M₆] variable (f : M →ₗ[R] M₂) section variable (R M M₂) /-- The first projection of a product is a linear map. -/ def fst : M × M₂ →ₗ[R] M where toFun := Prod.fst map_add' _x _y := rfl map_smul' _x _y := rfl /-- The second projection of a product is a linear map. -/ def snd : M × M₂ →ₗ[R] M₂ where toFun := Prod.snd map_add' _x _y := rfl map_smul' _x _y := rfl end @[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl @[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl @[simp, norm_cast] lemma coe_fst : ⇑(fst R M M₂) = Prod.fst := rfl @[simp, norm_cast] lemma coe_snd : ⇑(snd R M M₂) = Prod.snd := rfl theorem fst_surjective : Function.Surjective (fst R M M₂) := fun x => ⟨(x, 0), rfl⟩ theorem snd_surjective : Function.Surjective (snd R M M₂) := fun x => ⟨(0, x), rfl⟩ /-- The prod of two linear maps is a linear map. -/ @[simps] def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ where toFun := Pi.prod f g map_add' x y := by simp only [Pi.prod, Prod.mk_add_mk, map_add] map_smul' c x := by simp only [Pi.prod, Prod.smul_mk, map_smul, RingHom.id_apply] theorem coe_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ⇑(f.prod g) = Pi.prod f g := rfl @[simp] theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (fst R M₂ M₃).comp (prod f g) = f := rfl @[simp] theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (snd R M₂ M₃).comp (prod f g) = g := rfl @[simp] theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = LinearMap.id := rfl theorem prod_comp (f : M₂ →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (h : M →ₗ[R] M₂) : (f.prod g).comp h = (f.comp h).prod (g.comp h) := rfl /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def prodEquiv [Module S M₂] [Module S M₃] [SMulCommClass R S M₂] [SMulCommClass R S M₃] : ((M →ₗ[R] M₂) × (M →ₗ[R] M₃)) ≃ₗ[S] M →ₗ[R] M₂ × M₃ where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) map_add' _ _ := rfl map_smul' _ _ := rfl section variable (R M M₂) /-- The left injection into a product is a linear map. -/ def inl : M →ₗ[R] M × M₂ := prod LinearMap.id 0 /-- The right injection into a product is a linear map. -/ def inr : M₂ →ₗ[R] M × M₂ := prod 0 LinearMap.id theorem range_inl : range (inl R M M₂) = ker (snd R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.fst, Prod.ext rfl h.symm⟩ theorem ker_snd : ker (snd R M M₂) = range (inl R M M₂) := Eq.symm <| range_inl R M M₂ theorem range_inr : range (inr R M M₂) = ker (fst R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.snd, Prod.ext h.symm rfl⟩ theorem ker_fst : ker (fst R M M₂) = range (inr R M M₂) := Eq.symm <| range_inr R M M₂ @[simp] theorem fst_comp_inl : fst R M M₂ ∘ₗ inl R M M₂ = id := rfl @[simp] theorem snd_comp_inl : snd R M M₂ ∘ₗ inl R M M₂ = 0 := rfl @[simp] theorem fst_comp_inr : fst R M M₂ ∘ₗ inr R M M₂ = 0 := rfl @[simp] theorem snd_comp_inr : snd R M M₂ ∘ₗ inr R M M₂ = id := rfl end @[simp] theorem coe_inl : (inl R M M₂ : M → M × M₂) = fun x => (x, 0) := rfl theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl @[simp] theorem coe_inr : (inr R M M₂ : M₂ → M × M₂) = Prod.mk 0 := rfl theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl theorem inl_eq_prod : inl R M M₂ = prod LinearMap.id 0 := rfl theorem inr_eq_prod : inr R M M₂ = prod 0 LinearMap.id := rfl theorem inl_injective : Function.Injective (inl R M M₂) := fun _ => by simp theorem inr_injective : Function.Injective (inr R M M₂) := fun _ => by simp /-- The coprod function `x : M × M₂ ↦ f x.1 + g x.2` is a linear map. -/ def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ := f.comp (fst _ _ _) + g.comp (snd _ _ _) @[simp] theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M × M₂) : coprod f g x = f x.1 + g x.2 := rfl @[simp] theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inl R M M₂) = f := by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply] @[simp] theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inr R M M₂) = g := by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply] @[simp] theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = LinearMap.id := by ext <;> simp only [Prod.mk_add_mk, add_zero, id_apply, coprod_apply, inl_apply, inr_apply, zero_add] theorem coprod_zero_left (g : M₂ →ₗ[R] M₃) : (0 : M →ₗ[R] M₃).coprod g = g.comp (snd R M M₂) := zero_add _ theorem coprod_zero_right (f : M →ₗ[R] M₃) : f.coprod (0 : M₂ →ₗ[R] M₃) = f.comp (fst R M M₂) := add_zero _ theorem comp_coprod (f : M₃ →ₗ[R] M₄) (g₁ : M →ₗ[R] M₃) (g₂ : M₂ →ₗ[R] M₃) : f.comp (g₁.coprod g₂) = (f.comp g₁).coprod (f.comp g₂) := ext fun x => f.map_add (g₁ x.1) (g₂ x.2) theorem fst_eq_coprod : fst R M M₂ = coprod LinearMap.id 0 := by ext; simp theorem snd_eq_coprod : snd R M M₂ = coprod 0 LinearMap.id := by ext; simp @[simp] theorem coprod_comp_prod (f : M₂ →ₗ[R] M₄) (g : M₃ →ₗ[R] M₄) (f' : M →ₗ[R] M₂) (g' : M →ₗ[R] M₃) : (f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' := rfl @[simp] theorem coprod_map_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (S : Submodule R M) (S' : Submodule R M₂) : (Submodule.prod S S').map (LinearMap.coprod f g) = S.map f ⊔ S'.map g := SetLike.coe_injective <| by simp only [LinearMap.coprod_apply, Submodule.coe_sup, Submodule.map_coe] rw [← Set.image2_add, Set.image2_image_left, Set.image2_image_right] exact Set.image_prod fun m m₂ => f m + g m₂ @[simp] theorem coprod_comp_inl_inr (f : M × M₂ →ₗ[R] M₃) : (f.comp (inl R M M₂)).coprod (f.comp (inr R M M₂)) = f := by rw [← comp_coprod, coprod_inl_inr, comp_id] /-- Taking the product of two maps with the same codomain is equivalent to taking the product of their domains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def coprodEquiv [Module S M₃] [SMulCommClass R S M₃] : ((M →ₗ[R] M₃) × (M₂ →ₗ[R] M₃)) ≃ₗ[S] M × M₂ →ₗ[R] M₃ where toFun f := f.1.coprod f.2 invFun f := (f.comp (inl _ _ _), f.comp (inr _ _ _)) left_inv f := by simp only [coprod_inl, coprod_inr] right_inv f := by simp only [← comp_coprod, comp_id, coprod_inl_inr] map_add' a b := by ext simp only [Prod.snd_add, add_apply, coprod_apply, Prod.fst_add, add_add_add_comm] map_smul' r a := by dsimp ext simp only [smul_add, smul_apply, coprod_apply] theorem prod_ext_iff {f g : M × M₂ →ₗ[R] M₃} : f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) := (coprodEquiv ℕ).symm.injective.eq_iff.symm.trans Prod.ext_iff /-- Split equality of linear maps from a product into linear maps over each component, to allow `ext` to apply lemmas specific to `M →ₗ M₃` and `M₂ →ₗ M₃`. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem prod_ext {f g : M × M₂ →ₗ[R] M₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _)) (hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g := prod_ext_iff.2 ⟨hl, hr⟩ /-- `Prod.map` of two linear maps. -/ def prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : M × M₂ →ₗ[R] M₃ × M₄ := (f.comp (fst R M M₂)).prod (g.comp (snd R M M₂)) theorem coe_prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : ⇑(f.prodMap g) = Prod.map f g := rfl @[simp] theorem prodMap_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) : f.prodMap g x = (f x.1, g x.2) := rfl theorem prodMap_comap_prod (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) (S : Submodule R M₂) (S' : Submodule R M₄) : (Submodule.prod S S').comap (LinearMap.prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ theorem ker_prodMap (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) : ker (LinearMap.prodMap f g) = Submodule.prod (ker f) (ker g) := by dsimp only [ker] rw [← prodMap_comap_prod, Submodule.prod_bot] @[simp] theorem prodMap_id : (id : M →ₗ[R] M).prodMap (id : M₂ →ₗ[R] M₂) = id := rfl @[simp] theorem prodMap_one : (1 : M →ₗ[R] M).prodMap (1 : M₂ →ₗ[R] M₂) = 1 := rfl theorem prodMap_comp (f₁₂ : M →ₗ[R] M₂) (f₂₃ : M₂ →ₗ[R] M₃) (g₁₂ : M₄ →ₗ[R] M₅) (g₂₃ : M₅ →ₗ[R] M₆) : f₂₃.prodMap g₂₃ ∘ₗ f₁₂.prodMap g₁₂ = (f₂₃ ∘ₗ f₁₂).prodMap (g₂₃ ∘ₗ g₁₂) := rfl theorem prodMap_mul (f₁₂ : M →ₗ[R] M) (f₂₃ : M →ₗ[R] M) (g₁₂ : M₂ →ₗ[R] M₂) (g₂₃ : M₂ →ₗ[R] M₂) : f₂₃.prodMap g₂₃ * f₁₂.prodMap g₁₂ = (f₂₃ * f₁₂).prodMap (g₂₃ * g₁₂) := rfl theorem prodMap_add (f₁ : M →ₗ[R] M₃) (f₂ : M →ₗ[R] M₃) (g₁ : M₂ →ₗ[R] M₄) (g₂ : M₂ →ₗ[R] M₄) : (f₁ + f₂).prodMap (g₁ + g₂) = f₁.prodMap g₁ + f₂.prodMap g₂ := rfl @[simp] theorem prodMap_zero : (0 : M →ₗ[R] M₂).prodMap (0 : M₃ →ₗ[R] M₄) = 0 := rfl @[simp] theorem prodMap_smul [DistribMulAction S M₃] [DistribMulAction S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] (s : S) (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : prodMap (s • f) (s • g) = s • prodMap f g := rfl variable (R M M₂ M₃ M₄) /-- `LinearMap.prodMap` as a `LinearMap` -/ @[simps] def prodMapLinear [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] : (M →ₗ[R] M₃) × (M₂ →ₗ[R] M₄) →ₗ[S] M × M₂ →ₗ[R] M₃ × M₄ where toFun f := prodMap f.1 f.2 map_add' _ _ := rfl map_smul' _ _ := rfl /-- `LinearMap.prodMap` as a `RingHom` -/ @[simps] def prodMapRingHom : (M →ₗ[R] M) × (M₂ →ₗ[R] M₂) →+* M × M₂ →ₗ[R] M × M₂ where toFun f := prodMap f.1 f.2 map_one' := prodMap_one map_zero' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl variable {R M M₂ M₃ M₄} section map_mul variable {A : Type*} [NonUnitalNonAssocSemiring A] [Module R A] variable {B : Type*} [NonUnitalNonAssocSemiring B] [Module R B] theorem inl_map_mul (a₁ a₂ : A) : LinearMap.inl R A B (a₁ * a₂) = LinearMap.inl R A B a₁ * LinearMap.inl R A B a₂ := Prod.ext rfl (by simp) theorem inr_map_mul (b₁ b₂ : B) : LinearMap.inr R A B (b₁ * b₂) = LinearMap.inr R A B b₁ * LinearMap.inr R A B b₂ := Prod.ext (by simp) rfl end map_mul end LinearMap end Prod namespace LinearMap variable (R M M₂) variable [CommSemiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] /-- `LinearMap.prodMap` as an `AlgHom` -/ @[simps!] def prodMapAlgHom : Module.End R M × Module.End R M₂ →ₐ[R] Module.End R (M × M₂) := { prodMapRingHom R M M₂ with commutes' := fun _ => rfl } end LinearMap namespace LinearMap open Submodule variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] theorem range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : range (f.coprod g) = range f ⊔ range g := Submodule.ext fun x => by simp [mem_sup] theorem isCompl_range_inl_inr : IsCompl (range <| inl R M M₂) (range <| inr R M M₂) := by constructor · rw [disjoint_def] rintro ⟨_, _⟩ ⟨x, hx⟩ ⟨y, hy⟩ simp only [Prod.ext_iff, inl_apply, inr_apply] at hx hy ⊢ exact ⟨hy.1.symm, hx.2.symm⟩ · rw [codisjoint_iff_le_sup] rintro ⟨x, y⟩ - simp only [mem_sup, mem_range] refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, ?_⟩ simp theorem sup_range_inl_inr : (range <| inl R M M₂) ⊔ (range <| inr R M M₂) = ⊤ := IsCompl.sup_eq_top isCompl_range_inl_inr theorem disjoint_inl_inr : Disjoint (range <| inl R M M₂) (range <| inr R M M₂) := by simp +contextual [disjoint_def, @eq_comm M 0] theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : Submodule R M) (q : Submodule R M₂) : map (coprod f g) (p.prod q) = map f p ⊔ map g q := coprod_map_prod f g p q theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : Submodule R M₂) (q : Submodule R M₃) : comap (prod f g) (p.prod q) = comap f p ⊓ comap g q := Submodule.ext fun _x => Iff.rfl theorem prod_eq_inf_comap (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.comap (LinearMap.fst R M M₂) ⊓ q.comap (LinearMap.snd R M M₂) := Submodule.ext fun _x => Iff.rfl theorem prod_eq_sup_map (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.map (LinearMap.inl R M M₂) ⊔ q.map (LinearMap.inr R M M₂) := by rw [← map_coprod_prod, coprod_inl_inr, map_id] theorem span_inl_union_inr {s : Set M} {t : Set M₂} : span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) := by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image] @[simp] theorem ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ker (prod f g) = ker f ⊓ ker g := by rw [ker, ← prod_bot, comap_prod_prod]; rfl theorem range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : range (prod f g) ≤ (range f).prod (range g) := by simp only [SetLike.le_def, prod_apply, mem_range, mem_prod, exists_imp] rintro _ x rfl exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩ theorem ker_prod_ker_le_ker_coprod {M₂ : Type*} [AddCommMonoid M₂] [Module R M₂] {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (ker f).prod (ker g) ≤ ker (f.coprod g) := by rintro ⟨y, z⟩ simp +contextual theorem ker_coprod_of_disjoint_range {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (hd : Disjoint (range f) (range g)) : ker (f.coprod g) = (ker f).prod (ker g) := by apply le_antisymm _ (ker_prod_ker_le_ker_coprod f g) rintro ⟨y, z⟩ h simp only [mem_ker, mem_prod, coprod_apply] at h ⊢ have : f y ∈ (range f) ⊓ (range g) := by simp only [true_and, mem_range, mem_inf, exists_apply_eq_apply] use -z rwa [eq_comm, map_neg, ← sub_eq_zero, sub_neg_eq_add] rw [hd.eq_bot, mem_bot] at this rw [this] at h simpa [this] using h end LinearMap namespace Submodule open LinearMap variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] theorem sup_eq_range (p q : Submodule R M) : p ⊔ q = range (p.subtype.coprod q.subtype) := Submodule.ext fun x => by simp [Submodule.mem_sup] variable (p : Submodule R M) (q : Submodule R M₂) @[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ := by ext ⟨x, y⟩ simp only [and_left_comm, eq_comm, mem_map, Prod.mk_inj, inl_apply, mem_bot, exists_eq_left', mem_prod] @[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q := by ext ⟨x, y⟩; simp [and_left_comm, eq_comm, and_comm] @[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ := by ext ⟨x, y⟩; simp @[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q := by ext ⟨x, y⟩; simp @[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp @[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp @[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)] @[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q := by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)] @[simp] theorem ker_inl : ker (inl R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inl] @[simp] theorem ker_inr : ker (inr R M M₂) = ⊥ := by rw [ker, ← prod_bot, prod_comap_inr] @[simp] theorem range_fst : range (fst R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_fst] @[simp] theorem range_snd : range (snd R M M₂) = ⊤ := by rw [range_eq_map, ← prod_top, prod_map_snd] variable (R M M₂) /-- `M` as a submodule of `M × N`. -/ def fst : Submodule R (M × M₂) := (⊥ : Submodule R M₂).comap (LinearMap.snd R M M₂) /-- `M` as a submodule of `M × N` is isomorphic to `M`. -/ @[simps] def fstEquiv : Submodule.fst R M M₂ ≃ₗ[R] M where toFun x := x.1.1 invFun m := ⟨⟨m, 0⟩, by aesop⟩ map_add' := by simp map_smul' := by simp left_inv x := by aesop (add norm simp Submodule.fst) right_inv x := by simp theorem fst_map_fst : (Submodule.fst R M M₂).map (LinearMap.fst R M M₂) = ⊤ := by aesop theorem fst_map_snd : (Submodule.fst R M M₂).map (LinearMap.snd R M M₂) = ⊥ := by aesop (add simp fst) /-- `N` as a submodule of `M × N`. -/ def snd : Submodule R (M × M₂) := (⊥ : Submodule R M).comap (LinearMap.fst R M M₂) /-- `N` as a submodule of `M × N` is isomorphic to `N`. -/ @[simps] def sndEquiv : Submodule.snd R M M₂ ≃ₗ[R] M₂ where toFun x := x.1.2 invFun n := ⟨⟨0, n⟩, by aesop⟩ map_add' := by simp map_smul' := by simp left_inv x := by aesop (add norm simp Submodule.snd) theorem snd_map_fst : (Submodule.snd R M M₂).map (LinearMap.fst R M M₂) = ⊥ := by aesop (add simp snd) theorem snd_map_snd : (Submodule.snd R M M₂).map (LinearMap.snd R M M₂) = ⊤ := by aesop theorem fst_sup_snd : Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂ = ⊤ := by rw [eq_top_iff] rintro ⟨m, n⟩ - rw [show (m, n) = (m, 0) + (0, n) by simp] apply Submodule.add_mem (Submodule.fst R M M₂ ⊔ Submodule.snd R M M₂) · exact Submodule.mem_sup_left (Submodule.mem_comap.mpr (by simp)) · exact Submodule.mem_sup_right (Submodule.mem_comap.mpr (by simp)) theorem fst_inf_snd : Submodule.fst R M M₂ ⊓ Submodule.snd R M M₂ = ⊥ := by aesop theorem le_prod_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : q ≤ p₁.prod p₂ ↔ map (LinearMap.fst R M M₂) q ≤ p₁ ∧ map (LinearMap.snd R M M₂) q ≤ p₂ := by constructor · intro h constructor · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).1 · rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩ exact (h hy1).2 · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩ theorem prod_le_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} {q : Submodule R (M × M₂)} : p₁.prod p₂ ≤ q ↔ map (LinearMap.inl R M M₂) p₁ ≤ q ∧ map (LinearMap.inr R M M₂) p₂ ≤ q := by constructor · intro h constructor · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨hx, zero_mem p₂⟩ · rintro _ ⟨x, hx, rfl⟩ apply h exact ⟨zero_mem p₁, hx⟩ · rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩ have h1' : (LinearMap.inl R _ _) x1 ∈ q := by apply hH simpa using h1 have h2' : (LinearMap.inr R _ _) x2 ∈ q := by apply hK simpa using h2 simpa using add_mem h1' h2' theorem prod_eq_bot_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊥ ↔ p₁ = ⊥ ∧ p₂ = ⊥ := by simp only [eq_bot_iff, prod_le_iff, (gc_map_comap _).le_iff_le, comap_bot, ker_inl, ker_inr] theorem prod_eq_top_iff {p₁ : Submodule R M} {p₂ : Submodule R M₂} : p₁.prod p₂ = ⊤ ↔ p₁ = ⊤ ∧ p₂ = ⊤ := by simp only [eq_top_iff, le_prod_iff, map_top, range_fst, range_snd] end Submodule namespace LinearEquiv /-- Product of modules is commutative up to linear isomorphism. -/ @[simps apply] def prodComm (R M N : Type*) [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] : (M × N) ≃ₗ[R] N × M := { AddEquiv.prodComm with toFun := Prod.swap map_smul' := fun _r ⟨_m, _n⟩ => rfl } section prodComm variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] theorem fst_comp_prodComm : (LinearMap.fst R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.snd R M M₂) := by ext <;> simp theorem snd_comp_prodComm : (LinearMap.snd R M₂ M).comp (prodComm R M M₂).toLinearMap = (LinearMap.fst R M M₂) := by ext <;> simp end prodComm /-- Product of modules is associative up to linear isomorphism. -/ @[simps apply] def prodAssoc (R M₁ M₂ M₃ : Type*) [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] [Module R M₁] [Module R M₂] [Module R M₃] : ((M₁ × M₂) × M₃) ≃ₗ[R] (M₁ × (M₂ × M₃)) := { AddEquiv.prodAssoc with map_smul' := fun _r ⟨_m, _n⟩ => rfl } section prodAssoc variable {M₁ : Type*} variable [Semiring R] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M₁] [Module R M₂] [Module R M₃] theorem fst_comp_prodAssoc : (LinearMap.fst R M₁ (M₂ × M₃)).comp (prodAssoc R M₁ M₂ M₃).toLinearMap = (LinearMap.fst R M₁ M₂).comp (LinearMap.fst R (M₁ × M₂) M₃) := by ext <;> simp theorem snd_comp_prodAssoc : (LinearMap.snd R M₁ (M₂ × M₃)).comp (prodAssoc R M₁ M₂ M₃).toLinearMap = (LinearMap.snd R M₁ M₂).prodMap (LinearMap.id : M₃ →ₗ[R] M₃) := by ext <;> simp end prodAssoc section variable (R M M₂ M₃ M₄) variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] /-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm : ((M × M₂) × M₃ × M₄) ≃ₗ[R] (M × M₃) × M₂ × M₄ := { AddEquiv.prodProdProdComm M M₂ M₃ M₄ with toFun := fun mnmn => ((mnmn.1.1, mnmn.2.1), (mnmn.1.2, mnmn.2.2)) invFun := fun mmnn => ((mmnn.1.1, mmnn.2.1), (mmnn.1.2, mmnn.2.2)) map_smul' := fun _c _mnmn => rfl } @[simp] theorem prodProdProdComm_symm : (prodProdProdComm R M M₂ M₃ M₄).symm = prodProdProdComm R M M₃ M₂ M₄ := rfl @[simp] theorem prodProdProdComm_toAddEquiv : (prodProdProdComm R M M₂ M₃ M₄ : _ ≃+ _) = AddEquiv.prodProdProdComm M M₂ M₃ M₄ := rfl end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Product of linear equivalences; the maps come from `Equiv.prodCongr`. -/ protected def prodCongr : (M × M₃) ≃ₗ[R] M₂ × M₄ := { e₁.toAddEquiv.prodCongr e₂.toAddEquiv with map_smul' := fun c _x => Prod.ext (e₁.map_smulₛₗ c _) (e₂.map_smulₛₗ c _) } @[deprecated (since := "2025-04-17")] alias prod := LinearEquiv.prodCongr theorem prodCongr_symm : (e₁.prodCongr e₂).symm = e₁.symm.prodCongr e₂.symm := rfl @[deprecated (since := "2025-04-17")] alias prod_symm := prodCongr_symm @[simp] theorem prodCongr_apply (p) : e₁.prodCongr e₂ p = (e₁ p.1, e₂ p.2) := rfl @[deprecated (since := "2025-04-17")] alias prod_apply := prodCongr_apply @[simp, norm_cast] theorem coe_prodCongr : (e₁.prodCongr e₂ : M × M₃ →ₗ[R] M₂ × M₄) = (e₁ : M →ₗ[R] M₂).prodMap (e₂ : M₃ →ₗ[R] M₄) := rfl @[deprecated (since := "2025-04-17")] alias coe_prod := coe_prodCongr end section variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommGroup M₄] variable {module_M : Module R M} {module_M₂ : Module R M₂} variable {module_M₃ : Module R M₃} {module_M₄ : Module R M₄} variable (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) /-- Equivalence given by a block lower diagonal matrix. `e₁` and `e₂` are diagonal square blocks, and `f` is a rectangular block below the diagonal. -/ protected def skewProd (f : M →ₗ[R] M₄) : (M × M₃) ≃ₗ[R] M₂ × M₄ := { ((e₁ : M →ₗ[R] M₂).comp (LinearMap.fst R M M₃)).prod ((e₂ : M₃ →ₗ[R] M₄).comp (LinearMap.snd R M M₃) + f.comp (LinearMap.fst R M M₃)) with invFun := fun p : M₂ × M₄ => (e₁.symm p.1, e₂.symm (p.2 - f (e₁.symm p.1))) left_inv := fun p => by simp right_inv := fun p => by simp } @[simp] theorem skewProd_apply (f : M →ₗ[R] M₄) (x) : e₁.skewProd e₂ f x = (e₁ x.1, e₂ x.2 + f x.1) := rfl @[simp] theorem skewProd_symm_apply (f : M →ₗ[R] M₄) (x) : (e₁.skewProd e₂ f).symm x = (e₁.symm x.1, e₂.symm (x.2 - f (e₁.symm x.1))) := rfl end section Unique variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] [Unique M₂] /-- Multiplying by the trivial module from the left does not change the structure. This is the `LinearEquiv` version of `AddEquiv.uniqueProd`. -/ @[simps!] def uniqueProd : (M₂ × M) ≃ₗ[R] M := AddEquiv.uniqueProd.toLinearEquiv (by simp [AddEquiv.uniqueProd]) lemma coe_uniqueProd : (uniqueProd (R := R) (M := M) (M₂ := M₂) : (M₂ × M) ≃ M) = Equiv.uniqueProd M M₂ := rfl /-- Multiplying by the trivial module from the right does not change the structure. This is the `LinearEquiv` version of `AddEquiv.prodUnique`. -/ @[simps!] def prodUnique : (M × M₂) ≃ₗ[R] M := AddEquiv.prodUnique.toLinearEquiv (by simp [AddEquiv.prodUnique]) lemma coe_prodUnique : (prodUnique (R := R) (M := M) (M₂ := M₂) : (M × M₂) ≃ M) = Equiv.prodUnique M M₂ := rfl end Unique end LinearEquiv namespace LinearMap open Submodule variable [Ring R] variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M] [Module R M₂] [Module R M₃] /-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of `Prod f g` is equal to the product of `range f` and `range g`. -/ theorem range_prod_eq {f : M →ₗ[R] M₂} {g : M →ₗ[R] M₃} (h : ker f ⊔ ker g = ⊤) : range (prod f g) = (range f).prod (range g) := by refine le_antisymm (f.range_prod_le g) ?_ simp only [SetLike.le_def, prod_apply, mem_range, mem_prod, exists_imp, and_imp, Prod.forall, Pi.prod] rintro _ _ x rfl y rfl -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify `(f := f)` simp only [Prod.mk_inj, ← sub_mem_ker_iff (f := f)] have : y - x ∈ ker f ⊔ ker g := by simp only [h, mem_top] rcases mem_sup.1 this with ⟨x', hx', y', hy', H⟩ refine ⟨x' + x, ?_, ?_⟩ · rwa [add_sub_cancel_right] · simp [← eq_sub_iff_add_eq.1 H, map_add, mem_ker.mp hy'] end LinearMap namespace LinearMap /-! ## Tunnels and tailings NOTE: The proof of strong rank condition for noetherian rings is changed. `LinearMap.tunnel` and `LinearMap.tailing` are not used in mathlib anymore. These are marked as deprecated with no replacements. If you use them in external projects, please consider using other arguments instead. Some preliminary work for establishing the strong rank condition for noetherian rings. Given a morphism `f : M × N →ₗ[R] M` which is `i : Injective f`, we can find an infinite decreasing `tunnel f i n` of copies of `M` inside `M`, and sitting beside these, an infinite sequence of copies of `N`. We picturesquely name these as `tailing f i n` for each individual copy of `N`, and `tailings f i n` for the supremum of the first `n + 1` copies: they are the pieces left behind, sitting inside the tunnel. By construction, each `tailing f i (n + 1)` is disjoint from `tailings f i n`; later, when we assume `M` is noetherian, this implies that `N` must be trivial, and establishes the strong rank condition for any left-noetherian ring. -/ section Graph variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommGroup M₃] [AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) /-- Graph of a linear map. -/ def graph : Submodule R (M × M₂) where carrier := { p | p.2 = f p.1 } add_mem' (ha : _ = _) (hb : _ = _) := by change _ + _ = f (_ + _) rw [map_add, ha, hb] zero_mem' := Eq.symm (map_zero f) smul_mem' c x (hx : _ = _) := by change _ • _ = f (_ • _) rw [map_smul, hx] @[simp] theorem mem_graph_iff (x : M × M₂) : x ∈ f.graph ↔ x.2 = f x.1 := Iff.rfl theorem graph_eq_ker_coprod : g.graph = ker ((-g).coprod LinearMap.id) := by ext x change _ = _ ↔ -g x.1 + x.2 = _ rw [add_comm, add_neg_eq_zero] theorem graph_eq_range_prod : f.graph = range (LinearMap.id.prod f) := by ext x exact ⟨fun hx => ⟨x.1, Prod.ext rfl hx.symm⟩, fun ⟨u, hu⟩ => hu ▸ rfl⟩ end Graph end LinearMap section LineTest open Set Function variable {R S G H I : Type*} [Semiring R] [Semiring S] {σ : R →+* S} [RingHomSurjective σ] [AddCommMonoid G] [Module R G] [AddCommMonoid H] [Module S H] [AddCommMonoid I] [Module S I] /-- **Vertical line test** for linear maps. Let `f : G → H × I` be a linear (or semilinear) map to a product. Assume that `f` is surjective on the first factor and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` at most once. Then the image of `f` is the graph of some linear map `f' : H → I`. -/ lemma LinearMap.exists_range_eq_graph {f : G →ₛₗ[σ] H × I} (hf₁ : Surjective (Prod.fst ∘ f)) (hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 → (f g₁).2 = (f g₂).2) : ∃ f' : H →ₗ[S] I, LinearMap.range f = LinearMap.graph f' := by obtain ⟨f', hf'⟩ := AddMonoidHom.exists_mrange_eq_mgraph (G := G) (H := H) (I := I) (f := f) hf₁ hf simp only [SetLike.ext_iff, AddMonoidHom.mem_mrange, AddMonoidHom.coe_coe, AddMonoidHom.mem_mgraph] at hf' use { toFun := f'.toFun map_add' := f'.map_add' map_smul' := by intro s h simp only [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, RingHom.id_apply] refine (hf' (s • h, _)).mp ?_ rw [← Prod.smul_mk, ← LinearMap.mem_range] apply Submodule.smul_mem rw [LinearMap.mem_range, hf'] } ext x simpa only [mem_range, Eq.comm, ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, mem_graph_iff, coe_mk, AddHom.coe_mk, AddMonoidHom.coe_coe, Set.mem_range] using hf' x /-- **Vertical line test** for linear maps. Let `G ≤ H × I` be a submodule of a product of modules. Assume that `G` maps bijectively to the first factor. Then `G` is the graph of some linear map `f : H →ₗ[R] I`. -/ lemma Submodule.exists_eq_graph {G : Submodule S (H × I)} (hf₁ : Bijective (Prod.fst ∘ G.subtype)) : ∃ f : H →ₗ[S] I, G = LinearMap.graph f := by simpa only [range_subtype] using LinearMap.exists_range_eq_graph hf₁.surjective (fun a b h ↦ congr_arg (Prod.snd ∘ G.subtype) (hf₁.injective h)) /-- **Line test** for module isomorphisms. Let `f : G → H × I` be a linear (or semilinear) map to a product of modules. Assume that `f` is surjective onto both factors and that the image of `f` intersects every "vertical line" `{(h, i) | i : I}` and every "horizontal line" `{(h, i) | h : H}` at most once. Then the image of `f` is the graph of some module isomorphism `f' : H ≃ I`. -/ lemma LinearMap.exists_linearEquiv_eq_graph {f : G →ₛₗ[σ] H × I} (hf₁ : Surjective (Prod.fst ∘ f)) (hf₂ : Surjective (Prod.snd ∘ f)) (hf : ∀ g₁ g₂, (f g₁).1 = (f g₂).1 ↔ (f g₁).2 = (f g₂).2) : ∃ e : H ≃ₗ[S] I, range f = e.toLinearMap.graph := by obtain ⟨e₁, he₁⟩ := f.exists_range_eq_graph hf₁ fun _ _ ↦ (hf _ _).1 obtain ⟨e₂, he₂⟩ := ((LinearEquiv.prodComm _ _ _).toLinearMap.comp f).exists_range_eq_graph (by simpa) <| by simp [hf] have he₁₂ h i : e₁ h = i ↔ e₂ i = h := by simp only [SetLike.ext_iff, LinearMap.mem_graph_iff] at he₁ he₂ rw [Eq.comm, ← he₁ (h, i), Eq.comm, ← he₂ (i, h)] simp only [mem_range, coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.prodComm_apply, Prod.swap_eq_iff_eq_swap, Prod.swap_prod_mk] exact ⟨ { toFun := e₁ map_smul' := e₁.map_smul' map_add' := e₁.map_add' invFun := e₂ left_inv := fun h ↦ by rw [← he₁₂] right_inv := fun i ↦ by rw [he₁₂] }, he₁⟩ /-- **Goursat's lemma** for module isomorphisms. Let `G ≤ H × I` be a submodule of a product of modules. Assume that the natural maps from `G` to both factors are bijective. Then `G` is the graph of some module isomorphism `f : H ≃ I`. -/ lemma Submodule.exists_equiv_eq_graph {G : Submodule S (H × I)} (hG₁ : Bijective (Prod.fst ∘ G.subtype)) (hG₂ : Bijective (Prod.snd ∘ G.subtype)) : ∃ e : H ≃ₗ[S] I, G = e.toLinearMap.graph := by simpa only [range_subtype] using LinearMap.exists_linearEquiv_eq_graph hG₁.surjective hG₂.surjective fun _ _ ↦ hG₁.injective.eq_iff.trans hG₂.injective.eq_iff.symm end LineTest
Polynomial.lean
import Mathlib.Algebra.Polynomial.Basic import Mathlib.Algebra.Module.ULift open Polynomial def p0 : ℕ[X] := ⟨⟨{}, Pi.single 0 0, by intro; simp [Pi.single, Function.update_apply]⟩⟩ example : reprStr p0 = "0" := by native_decide example : reprStr (Option.some p0) = "some 0" := by native_decide example : (reprPrec p0 65).pretty = "0" := by native_decide def pX : ℕ[X] := ⟨⟨{1}, Pi.single 1 1, by intro; simp [Pi.single, Function.update_apply]⟩⟩ example : reprStr pX = "X" := by native_decide example : reprStr (Option.some pX) = "some X" := by native_decide def pXsq : ℕ[X] := ⟨⟨{2}, Pi.single 2 1, by intro; simp [Pi.single, Function.update_apply]⟩⟩ example : reprStr pXsq = "X ^ 2" := by native_decide example : reprStr (Option.some pXsq) = "some (X ^ 2)" := by native_decide example : (reprPrec pXsq 65).pretty = "X ^ 2" := by native_decide example : (reprPrec pXsq 70).pretty = "X ^ 2" := by native_decide example : (reprPrec pXsq 80).pretty = "(X ^ 2)" := by native_decide def p1 : ℕ[X] := ⟨⟨{1}, Pi.single 1 37, by intro; simp [Pi.single, Function.update_apply]⟩⟩ example : reprStr p1 = "C 37 * X" := by native_decide example : reprStr (Option.some p1) = "some (C 37 * X)" := by native_decide example : (reprPrec p1 65).pretty = "C 37 * X" := by native_decide example : (reprPrec p1 70).pretty = "(C 37 * X)" := by native_decide def p2 : ℕ[X] := ⟨⟨{0, 2}, Pi.single 0 57 + Pi.single 2 22, by intro; simp [Pi.single, Function.update_apply]; tauto⟩⟩ example : reprStr p2 = "C 57 + C 22 * X ^ 2" := by native_decide example : (reprPrec p2 65).pretty = "(C 57 + C 22 * X ^ 2)" := by native_decide -- test that parens are added inside `C` def pu1 : (ULift.{1} ℕ)[X] := ⟨⟨{1}, Pi.single 1 (ULift.up 37), by intro; simp [Pi.single, Function.update_apply, ←ULift.down_inj]⟩⟩ example : reprStr pu1 = "C (ULift.up 37) * X" := by native_decide
SwapVar.lean
/- Copyright (c) 2022 Arthur Paulino. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arthur Paulino -/ import Lean.Elab.ElabRules import Mathlib.Util.Tactic /-! # Defines the `swap_var` tactic Swap the names of two hypotheses. -/ open Lean Meta Elab.Tactic namespace Mathlib.Tactic /-- The parser for swap rules -/ syntax swapRule := ident " ↔"? ppSpace ident /-- `swap_var swap_rule₁, swap_rule₂, ⋯` applies `swap_rule₁` then `swap_rule₂` then `⋯`. A *swap_rule* is of the form `x y` or `x ↔ y`, and "applying it" means swapping the variable name `x` by `y` and vice-versa on all hypotheses and the goal. ```lean example {P Q : Prop} (q : P) (p : Q) : P ∧ Q := by swap_var p ↔ q exact ⟨p, q⟩ ``` -/ elab "swap_var " swapRules:(colGt swapRule),+ : tactic => do let mvarId ← getMainGoal let mdecl ← mvarId.getDecl let localInstances := mdecl.localInstances let lctx ← swapRules.getElems.foldlM (init := mdecl.lctx) fun lctx swapRule ↦ do withLCtx lctx localInstances do let `(swapRule| $n₁:ident $[↔]? $n₂:ident) := swapRule | unreachable! let n₁ := n₁.getId let n₂ := n₂.getId let fvarId₁ := (← getLocalDeclFromUserName n₁).fvarId let fvarId₂ := (← getLocalDeclFromUserName n₂).fvarId return lctx.setUserName fvarId₁ n₂ |>.setUserName fvarId₂ n₁ let mdecl := { mdecl with lctx := lctx } modifyMCtx fun mctx ↦ { mctx with decls := mctx.decls.insert mvarId mdecl } end Mathlib.Tactic
Free.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Module.FinitePresentation import Mathlib.RingTheory.Localization.Finiteness import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.StrongRankCondition /-! # Free modules and localization ## Main result - `Module.FinitePresentation.exists_free_localizedModule_powers`: If `M` is a finitely presented `R`-module such that `Mₛ` is free over `Rₛ` for some `S : Submonoid R`, then `Mᵣ` is already free over `Rᵣ` for some `r ∈ S`. ## Future projects - Show that a finitely presented flat module has locally constant dimension. - Show that the flat locus of a finitely presented module is open. -/ variable {R M N N'} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] variable (S : Submonoid R) [AddCommGroup N'] [Module R N'] variable {M' : Type*} [AddCommGroup M'] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f] variable {N' : Type*} [AddCommGroup N'] [Module R N'] (g : N →ₗ[R] N') [IsLocalizedModule S g] include f in /-- If `M` is a finitely presented `R`-module, then any `Rₛ`-basis of `Mₛ` for some `S : Submonoid R` can be lifted to a `Rᵣ`-basis of `Mᵣ` for some `r ∈ S`. -/ lemma Module.FinitePresentation.exists_basis_localizedModule_powers (Rₛ) [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ M'] [IsScalarTower R Rₛ M'] [IsLocalization S Rₛ] [Module.FinitePresentation R M] {I} [Finite I] (b : Basis I Rₛ M') : ∃ (r : R) (hr : r ∈ S) (b' : Basis I (Localization (.powers r)) (LocalizedModule (.powers r) M)), ∀ i, (LocalizedModule.lift (.powers r) f fun s ↦ IsLocalizedModule.map_units f ⟨s.1, SetLike.le_def.mp (Submonoid.powers_le.mpr hr) s.2⟩) (b' i) = b i := by have : Module.FinitePresentation R (I →₀ R) := Module.finitePresentation_of_projective _ _ obtain ⟨r, hr, e, he⟩ := Module.FinitePresentation.exists_lift_equiv_of_isLocalizedModule S f (Finsupp.mapRange.linearMap (Algebra.linearMap R Rₛ)) (b.repr.restrictScalars R) let e' := IsLocalizedModule.iso (.powers r) (Finsupp.mapRange.linearMap (α := I) (Algebra.linearMap R (Localization (.powers r)))) refine ⟨r, hr, .ofRepr (e ≪≫ₗ ?_), ?_⟩ · exact { __ := e', toLinearMap := e'.extendScalarsOfIsLocalization (.powers r) (Localization (.powers r)) } · intro i have : e'.symm _ = _ := LinearMap.congr_fun (IsLocalizedModule.iso_symm_comp (.powers r) (Finsupp.mapRange.linearMap (Algebra.linearMap R (Localization (.powers r))))) (Finsupp.single i 1) simp only [Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single, Algebra.linearMap_apply, map_one, LocalizedModule.mkLinearMap_apply] at this change LocalizedModule.lift _ _ _ (e.symm (e'.symm _)) = _ replace he := LinearMap.congr_fun he (e.symm (e'.symm (Finsupp.single i 1))) simp only [LinearMap.coe_comp, LinearMap.coe_restrictScalars, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.apply_symm_apply, LinearEquiv.restrictScalars_apply] at he apply b.repr.injective rw [← he, Basis.repr_self, this, LocalizedModule.lift_mk] simp include f in /-- If `M` is a finitely presented `R`-module such that `Mₛ` is free over `Rₛ` for some `S : Submonoid R`, then `Mᵣ` is already free over `Rᵣ` for some `r ∈ S`. -/ lemma Module.FinitePresentation.exists_free_localizedModule_powers (Rₛ) [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ M'] [IsScalarTower R Rₛ M'] [Nontrivial Rₛ] [IsLocalization S Rₛ] [Module.FinitePresentation R M] [Module.Free Rₛ M'] : ∃ r, r ∈ S ∧ Module.Free (Localization (.powers r)) (LocalizedModule (.powers r) M) ∧ Module.finrank (Localization (.powers r)) (LocalizedModule (.powers r) M) = Module.finrank Rₛ M' := by let I := Module.Free.ChooseBasisIndex Rₛ M' let b : Basis I Rₛ M' := Module.Free.chooseBasis Rₛ M' have : Module.Finite Rₛ M' := Module.Finite.of_isLocalizedModule S (Rₚ := Rₛ) f obtain ⟨r, hr, b', _⟩ := Module.FinitePresentation.exists_basis_localizedModule_powers S f Rₛ b have := (show Localization (.powers r) →+* Rₛ from IsLocalization.map (M := .powers r) (T := S) _ (RingHom.id _) (Submonoid.powers_le.mpr hr)).domain_nontrivial refine ⟨r, hr, .of_basis b', ?_⟩ rw [Module.finrank_eq_nat_card_basis b, Module.finrank_eq_nat_card_basis b']
Inverse.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.FDeriv.Equiv /-! # Inverse function theorem - the easy half In this file we prove that `g' (f x) = (f' x)⁻¹` provided that `f` is strictly differentiable at `x`, `f' x ≠ 0`, and `g` is a local left inverse of `f` that is continuous at `f x`. This is the easy half of the inverse function theorem: the harder half states that `g` exists. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative, inverse function -/ universe u v open scoped Topology open Filter Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : 𝕜 → F} variable {f' : F} variable {s : Set 𝕜} {x : 𝕜} {c : F} theorem HasStrictDerivAt.hasStrictFDerivAt_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜} (hf : HasStrictDerivAt f f' x) (hf' : f' ≠ 0) : HasStrictFDerivAt f (ContinuousLinearEquiv.unitsEquivAut 𝕜 (Units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x := hf theorem HasDerivAt.hasFDerivAt_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜} (hf : HasDerivAt f f' x) (hf' : f' ≠ 0) : HasFDerivAt f (ContinuousLinearEquiv.unitsEquivAut 𝕜 (Units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x := hf /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem HasStrictDerivAt.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜} (hg : ContinuousAt g a) (hf : HasStrictDerivAt f f' (g a)) (hf' : f' ≠ 0) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasStrictDerivAt g f'⁻¹ a := (hf.hasStrictFDerivAt_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a nonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem PartialHomeomorph.hasStrictDerivAt_symm (f : PartialHomeomorph 𝕜 𝕜) {a f' : 𝕜} (ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : HasStrictDerivAt f f' (f.symm a)) : HasStrictDerivAt f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuousAt ha) hf' (f.eventually_right_inverse ha) /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem HasDerivAt.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜} (hg : ContinuousAt g a) (hf : HasDerivAt f f' (g a)) (hf' : f' ≠ 0) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasDerivAt g f'⁻¹ a := (hf.hasFDerivAt_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a nonzero derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem PartialHomeomorph.hasDerivAt_symm (f : PartialHomeomorph 𝕜 𝕜) {a f' : 𝕜} (ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : HasDerivAt f f' (f.symm a)) : HasDerivAt f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuousAt ha) hf' (f.eventually_right_inverse ha) theorem HasDerivWithinAt.eventually_ne (h : HasDerivWithinAt f f' s x) (hf' : f' ≠ 0) : ∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ c := h.hasFDerivWithinAt.eventually_ne ⟨‖f'‖⁻¹, fun z => by field_simp [norm_smul, mt norm_eq_zero.1 hf']⟩ theorem HasDerivAt.eventually_ne (h : HasDerivAt f f' x) (hf' : f' ≠ 0) : ∀ᶠ z in 𝓝[≠] x, f z ≠ c := by simpa only [compl_eq_univ_diff] using (hasDerivWithinAt_univ.2 h).eventually_ne hf' theorem HasDerivAt.tendsto_nhdsNE (h : HasDerivAt f f' x) (hf' : f' ≠ 0) : Tendsto f (𝓝[≠] x) (𝓝[≠] f x) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.continuousAt.continuousWithinAt (h.eventually_ne hf') @[deprecated (since := "2025-03-02")] alias HasDerivAt.tendsto_punctured_nhds := HasDerivAt.tendsto_nhdsNE /-- If a function is equal to a constant at a set of points that accumulates to `x` in `s`, then its derivative within `s` at `x` equals zero, either because it has derivative zero or because it isn't differentiable at this point. -/ theorem derivWithin_zero_of_frequently_const {c} (h : ∃ᶠ y in 𝓝[s \ {x}] x, f y = c) : derivWithin f s x = 0 := by by_cases hf : DifferentiableWithinAt 𝕜 f s x · contrapose h rw [not_frequently] exact hf.hasDerivWithinAt.eventually_ne h · exact derivWithin_zero_of_not_differentiableWithinAt hf /-- If a function is equal to a constant at a set of points that accumulates to `x`, then its derivative at `x` equals zero, either because it has derivative zero or because it isn't differentiable at this point. -/ theorem deriv_zero_of_frequently_const {c} (h : ∃ᶠ y in 𝓝[≠] x, f y = c) : deriv f x = 0 := by rw [← derivWithin_univ, derivWithin_zero_of_frequently_const] rwa [← compl_eq_univ_diff] theorem not_differentiableWithinAt_of_local_left_inverse_hasDerivWithinAt_zero {f g : 𝕜 → 𝕜} {a : 𝕜} {s t : Set 𝕜} (ha : a ∈ s) (hsu : UniqueDiffWithinAt 𝕜 s a) (hf : HasDerivWithinAt f 0 t (g a)) (hst : MapsTo g s t) (hfg : f ∘ g =ᶠ[𝓝[s] a] id) : ¬DifferentiableWithinAt 𝕜 g s a := by intro hg have := (hf.comp a hg.hasDerivWithinAt hst).congr_of_eventuallyEq_of_mem hfg.symm ha simpa using hsu.eq_deriv _ this (hasDerivWithinAt_id _ _) theorem not_differentiableAt_of_local_left_inverse_hasDerivAt_zero {f g : 𝕜 → 𝕜} {a : 𝕜} (hf : HasDerivAt f 0 (g a)) (hfg : f ∘ g =ᶠ[𝓝 a] id) : ¬DifferentiableAt 𝕜 g a := by intro hg have := (hf.comp a hg.hasDerivAt).congr_of_eventuallyEq hfg.symm simpa using this.unique (hasDerivAt_id a)
binomial.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import div fintype tuple finfun bigop prime finset. (******************************************************************************) (* This files contains the definition of: *) (* 'C(n, m) == the binomial coefficient n choose m. *) (* n ^_ m == the falling (or lower) factorial of n with m terms, i.e., *) (* the product n * (n - 1) * ... * (n - m + 1). *) (* Note that n ^_ m = 0 if m > n, and 'C(n, m) = n ^_ m %/ m`!. *) (* *) (* In additions to the properties of these functions, we prove a few seminal *) (* results such as bin2_sum, Wilson and expnDn; their proofs are good *) (* examples of how to manipulate expressions with bigops. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. (** More properties of the factorial **) Lemma fact_prod n : n`! = \prod_(1 <= i < n.+1) i. Proof. elim: n => [|n IHn] //; first by rewrite big_nil. by apply/esym; rewrite factS IHn // !big_add1 big_nat_recr //= mulnC. Qed. Lemma fact_split n m : m <= n -> n`! = m`! * \prod_(m.+1 <= k < n.+1) k. Proof. by move=> leq_mn; rewrite !fact_prod -big_cat_nat. Qed. Lemma logn_fact p n : prime p -> logn p n`! = \sum_(1 <= k < n.+1) n %/ p ^ k. Proof. move=> p_prime; transitivity (\sum_(1 <= i < n.+1) logn p i). rewrite big_add1; elim: n => /= [|n IHn]; first by rewrite logn1 big_geq. by rewrite big_nat_recr // -IHn /= factS mulnC lognM ?fact_gt0. transitivity (\sum_(1 <= i < n.+1) \sum_(1 <= k < n.+1) (p ^ k %| i)). apply: eq_big_nat => i /andP[i_gt0 le_i_n]; rewrite logn_count_dvd //. rewrite -!big_mkcond (big_nat_widen _ _ n.+1) 1?ltnW //; apply: eq_bigl => k. by apply: andb_idr => /dvdn_leq/(leq_trans (ltn_expl _ (prime_gt1 _)))->. by rewrite exchange_big_nat; apply: eq_bigr => i _; rewrite divn_count_dvd. Qed. Theorem Wilson p : p > 1 -> prime p = (p %| ((p.-1)`!).+1). Proof. have dFact n: 0 < n -> (n.-1)`! = \prod_(0 <= i < n | i != 0) i. move=> n_gt0; rewrite -big_filter fact_prod; symmetry; apply: congr_big => //. rewrite /index_iota subn1 -[n]prednK //=; apply/all_filterP. by rewrite all_predC has_pred1 mem_iota. move=> lt1p; have p_gt0 := ltnW lt1p. apply/idP/idP=> [pr_p | dv_pF]; last first. apply/primeP; split=> // d dv_dp; have: d <= p by apply: dvdn_leq. rewrite orbC leq_eqVlt => /orP[-> // | ltdp]. have:= dvdn_trans dv_dp dv_pF; rewrite dFact // big_mkord. rewrite (bigD1 (Ordinal ltdp)) /=; last by rewrite -lt0n (dvdn_gt0 p_gt0). by rewrite orbC -addn1 dvdn_addr ?dvdn_mulr // dvdn1 => ->. pose Fp1 := Ordinal lt1p; pose Fp0 := Ordinal p_gt0. have ltp1p: p.-1 < p by [rewrite prednK]; pose Fpn1 := Ordinal ltp1p. case eqF1n1: (Fp1 == Fpn1); first by rewrite -{1}[p]prednK -1?((1 =P p.-1) _). have toFpP m: m %% p < p by rewrite ltn_mod. pose toFp := Ordinal (toFpP _); pose mFp (i j : 'I_p) := toFp (i * j). have Fp_mod (i : 'I_p) : i %% p = i by apply: modn_small. have mFpA: associative mFp. by move=> i j k; apply: val_inj; rewrite /= modnMml modnMmr mulnA. have mFpC: commutative mFp by move=> i j; apply: val_inj; rewrite /= mulnC. have mFp1: left_id Fp1 mFp by move=> i; apply: val_inj; rewrite /= mul1n. have mFp1r: right_id Fp1 mFp by move=> i; apply: val_inj; rewrite /= muln1. pose mFpcM := Monoid.isComLaw.Build 'I_p Fp1 mFp mFpA mFpC mFp1. pose mFpCL : Monoid.com_law _ := HB.pack mFp mFpcM. pose mFpM := Monoid.Law.sort mFpCL. pose vFp (i : 'I_p) := toFp (egcdn i p).1. have vFpV i: i != Fp0 -> mFp (vFp i) i = Fp1. rewrite -val_eqE /= -lt0n => i_gt0; apply: val_inj => /=. rewrite modnMml; case: egcdnP => //= _ km -> _; rewrite {km}modnMDl. suffices: coprime i p by move/eqnP->; rewrite modn_small. rewrite coprime_sym prime_coprime //; apply/negP=> /(dvdn_leq i_gt0). by rewrite leqNgt ltn_ord. have vFp0 i: i != Fp0 -> vFp i != Fp0. by move/vFpV; apply/contra_eq_neq => ->; rewrite -val_eqE /= mul0n mod0n. have vFpK: {in predC1 Fp0, involutive vFp}. move=> i n0i; rewrite /= -[vFp _]mFp1r -(vFpV _ n0i) mFpA. by rewrite vFpV (vFp0, mFp1). have le_pmFp (i : 'I_p) m: i <= p + m. by apply: leq_trans (ltnW _) (leq_addr _ _). have eqFp (i j : 'I_p): (i == j) = (p %| p + i - j). by rewrite -eqn_mod_dvd ?(modnDl, Fp_mod). have vFpId i: (vFp i == i :> nat) = xpred2 Fp1 Fpn1 i. have [->{i} | ni0] := eqVneq i Fp0. by rewrite -!val_eqE /= egcd0n modn_small //= -(subnKC lt1p). rewrite 2![i == _]eqFp -Euclid_dvdM // -[_ - p.-1]subSS prednK //. have lt0i: 0 < i by rewrite lt0n. rewrite -addnS addKn -addnBA // mulnDl -{2}(addn1 i) -subn_sqr. rewrite addnBA ?leq_sqr // mulnS -addnA -mulnn -mulnDl. rewrite -(subnK (le_pmFp (vFp i) i)) mulnDl addnCA. rewrite -[1 ^ 2]/(Fp1 : nat) -addnBA // dvdn_addl. by rewrite Euclid_dvdM // -eqFp eq_sym orbC /dvdn Fp_mod eqn0Ngt lt0i. by rewrite -eqn_mod_dvd // Fp_mod modnDl -(vFpV _ ni0). suffices [mod_fact]: toFp (p.-1)`! = Fpn1. by rewrite /dvdn -addn1 -modnDml mod_fact addn1 prednK // modnn. rewrite dFact //; rewrite ((big_morph toFp) Fp1 mFpM) //; first last. - by apply: val_inj; rewrite /= modn_small. - by move=> i j; apply: val_inj; rewrite /= modnMm. rewrite big_mkord (eq_bigr id) => [|i _]; last by apply: val_inj => /=. pose ltv i := vFp i < i; rewrite (bigID ltv) -/mFpM [mFpM _ _]mFpC. rewrite (bigD1 Fp1) -/mFpM; last by rewrite [ltv _]ltn_neqAle vFpId. rewrite [mFpM _ _]mFp1 (bigD1 Fpn1) -?mFpA -/mFpM; last first. rewrite -lt0n -ltnS prednK // lt1p. by rewrite [ltv _]ltn_neqAle vFpId eqxx orbT eq_sym eqF1n1. rewrite (reindex_onto vFp vFp) -/mFpM => [|i]; last by do 3!case/andP; auto. rewrite (eq_bigl (xpredD1 ltv Fp0)) => [|i]; last first. rewrite andbC -!andbA -2!negb_or -vFpId orbC -leq_eqVlt -ltnNge. have [->|ni0] := eqVneq i; last by rewrite vFpK // eqxx vFp0. by case: eqP => // ->; rewrite !andbF. rewrite -{2}[mFp]/mFpM -[mFpM _ _]big_split -/mFpM. by rewrite big1 ?mFp1r //= => i /andP [/vFpV]. Qed. (** The falling factorial *) Fixpoint ffact_rec n m := if m is m'.+1 then n * ffact_rec n.-1 m' else 1. Definition falling_factorial := ffact_rec. Arguments falling_factorial : simpl never. Notation "n ^_ m" := (falling_factorial n m) (at level 30, right associativity) : nat_scope. Lemma ffactE : falling_factorial = ffact_rec. Proof. by []. Qed. Lemma ffactn0 n : n ^_ 0 = 1. Proof. by []. Qed. Lemma ffact0n m : 0 ^_ m = (m == 0). Proof. by case: m. Qed. Lemma ffactnS n m : n ^_ m.+1 = n * n.-1 ^_ m. Proof. by []. Qed. Lemma ffactSS n m : n.+1 ^_ m.+1 = n.+1 * n ^_ m. Proof. by []. Qed. Lemma ffactn1 n : n ^_ 1 = n. Proof. exact: muln1. Qed. Lemma ffactnSr n m : n ^_ m.+1 = n ^_ m * (n - m). Proof. elim: n m => [|n IHn] [|m] //=; first by rewrite ffactn1 mul1n. by rewrite !ffactSS IHn mulnA. Qed. Lemma ffact_prod n m : n ^_ m = \prod_(i < m) (n - i). Proof. elim: m n => [n | m IH [|n] //]; first by rewrite ffactn0 big_ord0. by rewrite big_ord_recr /= sub0n muln0. by rewrite ffactSS IH big_ord_recl subn0. Qed. Lemma ffact_gt0 n m : (0 < n ^_ m) = (m <= n). Proof. by elim: n m => [|n IHn] [|m] //=; rewrite ffactSS muln_gt0 IHn. Qed. Lemma ffact_small n m : n < m -> n ^_ m = 0. Proof. by rewrite ltnNge -ffact_gt0; case: posnP. Qed. Lemma ffactnn n : n ^_ n = n`!. Proof. by elim: n => [|n IHn] //; rewrite ffactnS IHn. Qed. Lemma ffact_fact n m : m <= n -> n ^_ m * (n - m)`! = n`!. Proof. by elim: n m => [|n IHn] [|m] //= le_m_n; rewrite ?mul1n // -mulnA IHn. Qed. Lemma ffact_factd n m : m <= n -> n ^_ m = n`! %/ (n - m)`!. Proof. by move/ffact_fact <-; rewrite mulnK ?fact_gt0. Qed. (** Binomial coefficients *) Fixpoint binomial n m := match n, m with | n'.+1, m'.+1 => binomial n' m + binomial n' m' | _, 0 => 1 | 0, _.+1 => 0 end. Arguments binomial : simpl never. Notation "''C' ( n , m )" := (binomial n m) : nat_scope. Lemma binE n m : binomial n m = match n, m with | n'.+1, m'.+1 => binomial n' m + binomial n' m' | _, 0 => 1 | 0, _.+1 => 0 end. Proof. by case: n. Qed. Lemma bin0 n : 'C(n, 0) = 1. Proof. by case: n. Qed. Lemma bin0n m : 'C(0, m) = (m == 0). Proof. by case: m. Qed. Lemma binS n m : 'C(n.+1, m.+1) = 'C(n, m.+1) + 'C(n, m). Proof. by []. Qed. Lemma bin1 n : 'C(n, 1) = n. Proof. by elim: n => //= n IHn; rewrite binS bin0 IHn addn1. Qed. Lemma bin_gt0 n m : (0 < 'C(n, m)) = (m <= n). Proof. by elim: n m => [|n IHn] [|m] //; rewrite addn_gt0 !IHn orbC ltn_neqAle andKb. Qed. Lemma leq_bin2l n1 n2 m : n1 <= n2 -> 'C(n1, m) <= 'C(n2, m). Proof. by elim: n1 n2 m => [|n1 IHn] [|n2] [|n] le_n12 //; rewrite leq_add ?IHn. Qed. Lemma bin_small n m : n < m -> 'C(n, m) = 0. Proof. by rewrite ltnNge -bin_gt0; case: posnP. Qed. Lemma binn n : 'C(n, n) = 1. Proof. by elim: n => [|n IHn] //; rewrite binS bin_small. Qed. (* Multiply to move diagonally down and right in the Pascal triangle. *) Lemma mul_bin_diag n m : n * 'C(n.-1, m) = m.+1 * 'C(n, m.+1). Proof. rewrite [RHS]mulnC; elim: n m => [|[|n] IHn] [|m] //=; first by rewrite bin1. by rewrite mulSn [in _ * _]binS mulnDr addnCA !IHn -mulnS -mulnDl -binS. Qed. Lemma bin_fact n m : m <= n -> 'C(n, m) * (m`! * (n - m)`!) = n`!. Proof. elim: n m => [|n IHn] [|m] // le_m_n; first by rewrite bin0 !mul1n. by rewrite !factS -!mulnA mulnCA mulnA -mul_bin_diag -mulnA IHn. Qed. (* In fact the only exception for bin_factd is n = 0 and m = 1 *) Lemma bin_factd n m : 0 < n -> 'C(n, m) = n`! %/ (m`! * (n - m)`!). Proof. have [/bin_fact<-|*] := leqP m n; first by rewrite mulnK ?muln_gt0 ?fact_gt0. by rewrite divnMA bin_small ?divn_small ?fact_gt0 ?ltn_fact. Qed. Lemma bin_ffact n m : 'C(n, m) * m`! = n ^_ m. Proof. have [lt_n_m | le_m_n] := ltnP n m; first by rewrite bin_small ?ffact_small. by rewrite ffact_factd // -(bin_fact le_m_n) mulnA mulnK ?fact_gt0. Qed. Lemma bin_ffactd n m : 'C(n, m) = n ^_ m %/ m`!. Proof. by rewrite -bin_ffact mulnK ?fact_gt0. Qed. Lemma bin_sub n m : m <= n -> 'C(n, n - m) = 'C(n, m). Proof. by move=> le_m_n; rewrite !bin_ffactd !ffact_factd ?leq_subr // divnAC subKn. Qed. (* Multiply to move down in the Pascal triangle. *) Lemma mul_bin_down n m : n * 'C(n.-1, m) = (n - m) * 'C(n, m). Proof. case: n => //= n; have [lt_n_m | le_m_n] := ltnP n m. by rewrite (eqnP lt_n_m) mulnC bin_small. by rewrite -!['C(_, m)]bin_sub ?leqW ?subSn ?mul_bin_diag. Qed. (* Multiply to move left in the Pascal triangle. *) Lemma mul_bin_left n m : m.+1 * 'C(n, m.+1) = (n - m) * 'C(n, m). Proof. by rewrite -mul_bin_diag mul_bin_down. Qed. Lemma binSn n : 'C(n.+1, n) = n.+1. Proof. by rewrite -bin_sub ?leqnSn // subSnn bin1. Qed. Lemma bin2 n : 'C(n, 2) = (n * n.-1)./2. Proof. by rewrite -[n.-1]bin1 mul_bin_diag -divn2 mulKn. Qed. Lemma bin2odd n : odd n -> 'C(n, 2) = n * n.-1./2. Proof. by case: n => // n oddn; rewrite bin2 -!divn2 muln_divA ?dvdn2. Qed. Lemma prime_dvd_bin k p : prime p -> 0 < k < p -> p %| 'C(p, k). Proof. move=> p_pr /andP[k_gt0 lt_k_p]. suffices /Gauss_dvdr<-: coprime p (p - k) by rewrite -mul_bin_down dvdn_mulr. by rewrite prime_coprime // dvdn_subr 1?ltnW // gtnNdvd. Qed. Lemma bin2_sum n : \sum_(0 <= i < n) i = 'C(n, 2). Proof. elim: n => [|n IHn]; first by rewrite big_geq. by rewrite big_nat_recr // IHn binS bin1. Qed. #[deprecated(since="mathcomp 2.3.0", note="Use bin2_sum instead.")] Notation triangular_sum := bin2_sum (only parsing). (* textbook proof of `bin2_sum`. Should be moved out of the main library, to a dedicated "showcase" library. Lemma textbook_triangular_sum n : \sum_(0 <= i < n) i = 'C(n, 2). Proof. rewrite bin2; apply: canRL half_double _. rewrite -addnn {1}big_nat_rev -big_split big_mkord /= ?add0n. rewrite (eq_bigr (fun _ => n.-1)); first by rewrite sum_nat_const card_ord. by case: n => [|n] [i le_i_n] //=; rewrite subSS subnK. Qed. *) Theorem expnDn a b n : (a + b) ^ n = \sum_(i < n.+1) 'C(n, i) * (a ^ (n - i) * b ^ i). Proof. elim: n => [|n IHn]; rewrite big_ord_recl muln1 ?big_ord0 //. rewrite expnS {}IHn /= mulnDl !big_distrr /= big_ord_recl muln1 subn0. rewrite !big_ord_recr /= !binn !subnn bin0 !subn0 !mul1n -!expnS -addnA. congr (_ + _); rewrite addnA -big_split /=; congr (_ + _). apply: eq_bigr => i _; rewrite mulnCA (mulnA a) -expnS subnSK //=. by rewrite (mulnC b) -2!mulnA -expnSr -mulnDl. Qed. #[deprecated(since="mathcomp 2.3.0", note="Use expnDn instead.")] Definition Pascal := expnDn. Lemma Vandermonde k l i : \sum_(j < i.+1) 'C(k, j) * 'C(l, i - j) = 'C(k + l , i). Proof. pose f k i := \sum_(j < i.+1) 'C(k, j) * 'C(l, i - j). suffices{k i} fxx k i: f k.+1 i.+1 = f k i.+1 + f k i. elim: k i => [i | k IHk [|i]]; last by rewrite -/(f _ _) fxx /f !IHk -binS. by rewrite big_ord_recl big1_eq addn0 mul1n subn0. by rewrite big_ord_recl big_ord0 addn0 !bin0 muln1. rewrite {}/f big_ord_recl (big_ord_recl (i.+1)) !bin0 !mul1n. rewrite -addnA -big_split /=; congr (_ + _). by apply: eq_bigr => j _; rewrite -mulnDl. Qed. Lemma subn_exp m n k : m ^ k - n ^ k = (m - n) * (\sum_(i < k) m ^ (k.-1 -i) * n ^ i). Proof. case: k => [|k]; first by rewrite big_ord0 muln0. rewrite mulnBl !big_distrr big_ord_recl big_ord_recr /= subn0 muln1. rewrite subnn mul1n -!expnS subnDA; congr (_ - _); apply: canRL (addnK _) _. congr (_ + _); apply: eq_bigr => i _. by rewrite (mulnCA n) -expnS mulnA -expnS subnSK /=. Qed. Lemma predn_exp m k : (m ^ k).-1 = m.-1 * (\sum_(i < k) m ^ i). Proof. rewrite -!subn1 -[in LHS](exp1n k) subn_exp; congr (_ * _). symmetry; rewrite (reindex_inj rev_ord_inj); apply: eq_bigr => i _ /=. by rewrite -subn1 -subnDA exp1n muln1. Qed. Lemma dvdn_pred_predX n e : (n.-1 %| (n ^ e).-1)%N. Proof. by rewrite predn_exp dvdn_mulr. Qed. Lemma modn_summ I r (P : pred I) F d : \sum_(i <- r | P i) F i %% d = \sum_(i <- r | P i) F i %[mod d]. Proof. by apply/eqP; elim/big_rec2: _ => // i m n _; rewrite modnDml eqn_modDl. Qed. Lemma prime_modn_expSn p n : prime p -> n.+1 ^ p = (n ^ p).+1 %[mod p]. Proof. case: p => // p pP. rewrite -[(_ ^ _).+1]addn0 (expnDn 1) big_ord_recr big_ord_recl /=. rewrite subnn binn exp1n !mul1n addnAC -modnDmr; congr ((_ + _) %% _). apply/eqP/dvdn_sum => -[i ?] _; exact/dvdn_mulr/prime_dvd_bin. Qed. Lemma fermat_little a p : prime p -> a ^ p = a %[mod p]. Proof. move=> pP. elim: a => [|a IH]; first by rewrite exp0n // prime_gt0. by rewrite prime_modn_expSn // -addn1 -modnDml IH modnDml addn1. Qed. (* Combinatorial characterizations. *) Section Combinations. Implicit Types T D : finType. Lemma card_uniq_tuples T n (A : pred T) : #|[set t : n.-tuple T | all A t & uniq t]| = #|A| ^_ n. Proof. elim: n A => [|n IHn] A. by rewrite (@eq_card1 _ [tuple]) // => t; rewrite [t]tuple0 inE. rewrite -sum1dep_card (partition_big (@thead _ _) A) /= => [|t]; last first. by case/tupleP: t => x t; do 2!case/andP. rewrite ffactnS -sum_nat_const; apply: eq_bigr => x Ax. rewrite (cardD1 x) [x \in A]Ax /= -(IHn [predD1 A & x]) -sum1dep_card. rewrite (reindex (fun t : n.-tuple T => [tuple of x :: t])) /=; last first. pose ttail (t : n.+1.-tuple T) := [tuple of behead t]. exists ttail => [t _ | t /andP[_ /eqP <-]]; first exact: val_inj. by rewrite -tuple_eta. apply: eq_bigl=> t; rewrite Ax theadE eqxx andbT /= andbA; congr (_ && _). by rewrite all_predI all_predC has_pred1 andbC. Qed. Lemma card_inj_ffuns_on D T (R : pred T) : #|[set f : {ffun D -> T} in ffun_on R | injectiveb f]| = #|R| ^_ #|D|. Proof. rewrite -card_uniq_tuples. have bijFF: {on (_ : pred _), bijective (@Finfun D T)}. by exists fgraph => x _; [apply: FinfunK | apply: fgraphK]. rewrite -(on_card_preimset (bijFF _)); apply: eq_card => /= t. rewrite !inE -(big_andE predT) -big_image /= big_all. by rewrite -[t in RHS]FinfunK -codom_ffun. Qed. Lemma card_inj_ffuns D T : #|[set f : {ffun D -> T} | injectiveb f]| = #|T| ^_ #|D|. Proof. rewrite -card_inj_ffuns_on; apply: eq_card => f. by rewrite 2!inE; case: ffun_onP. Qed. Lemma cards_draws T (B : {set T}) k : #|[set A : {set T} | A \subset B & #|A| == k]| = 'C(#|B|, k). Proof. have [ltTk | lekT] := ltnP #|B| k. rewrite bin_small // eq_card0 // => A. rewrite inE eqn_leq [k <= _]leqNgt. have [AsubB /=|//] := boolP (A \subset B). by rewrite (leq_ltn_trans (subset_leq_card AsubB)) ?andbF. apply/eqP; rewrite -(eqn_pmul2r (fact_gt0 k)) bin_ffact // eq_sym. rewrite -sum_nat_cond_const -{1 3}(card_ord k). rewrite -card_inj_ffuns_on -sum1dep_card. pose imIk (f : {ffun 'I_k -> T}) := f @: 'I_k. rewrite (partition_big imIk (fun A => (A \subset B) && (#|A| == k))) /= => [|f]; last first. move=> /andP [/ffun_onP f_ffun /injectiveP inj_f]. rewrite card_imset ?card_ord // eqxx andbT. by apply/subsetP => x /imsetP [i _ ->]; rewrite f_ffun. apply/eqP; apply: eq_bigr => A /andP [AsubB /eqP cardAk]. have [f0 inj_f0 im_f0]: exists2 f, injective f & f @: 'I_k = A. rewrite -cardAk; exists enum_val; first exact: enum_val_inj. apply/setP=> a; apply/imsetP/idP=> [[i _ ->] | Aa]; first exact: enum_valP. by exists (enum_rank_in Aa a); rewrite ?enum_rankK_in. rewrite (reindex (fun p : {ffun _} => [ffun i => f0 (p i)])) /=; last first. pose ff0' f i := odflt i [pick j | f i == f0 j]. exists (fun f => [ffun i => ff0' f i]) => [p _ | f]. apply/ffunP=> i; rewrite ffunE /ff0'; case: pickP => [j | /(_ (p i))]. by rewrite ffunE (inj_eq inj_f0) => /eqP. by rewrite ffunE eqxx. rewrite -im_f0 => /andP[/andP[/ffun_onP f_ffun /injectiveP injf] /eqP im_f]. apply/ffunP=> i; rewrite !ffunE /ff0'; case: pickP => [y /eqP //|]. have /imsetP[j _ eq_f0j_fi]: f i \in f0 @: 'I_k by rewrite -im_f imset_f. by move/(_ j)/eqP. rewrite -ffactnn -card_inj_ffuns -sum1dep_card; apply: eq_bigl => p. rewrite -andbA. apply/and3P/injectiveP=> [[_ /injectiveP inj_f0p _] i j eq_pij | inj_p]. by apply: inj_f0p; rewrite !ffunE eq_pij. set f := finfun _. have injf: injective f by move=> i j /[!ffunE] /inj_f0; apply: inj_p. have imIkf : imIk f == A. rewrite eqEcard card_imset // cardAk card_ord leqnn andbT -im_f0. by apply/subsetP=> x /imsetP[i _ ->]; rewrite ffunE imset_f. split; [|exact/injectiveP|exact: imIkf]. by apply/ffun_onP => x; apply: (subsetP AsubB); rewrite -(eqP imIkf) imset_f. Qed. Lemma card_draws T k : #|[set A : {set T} | #|A| == k]| = 'C(#|T|, k). Proof. by rewrite -cardsT -cards_draws; apply: eq_card => A; rewrite !inE subsetT. Qed. Lemma card_ltn_sorted_tuples m n : #|[set t : m.-tuple 'I_n | sorted ltn (map val t)]| = 'C(n, m). Proof. have [-> | n_gt0] := posnP n; last pose i0 := Ordinal n_gt0. case: m => [|m]; last by apply: eq_card0; case/tupleP=> [[]]. by apply: (@eq_card1 _ [tuple]) => t; rewrite [t]tuple0 inE. rewrite -[n in RHS]card_ord -card_draws. pose f_t (t : m.-tuple 'I_n) := [set i in t]. pose f_A (A : {set 'I_n}) := [tuple of mkseq (nth i0 (enum A)) m]. have val_fA (A : {set 'I_n}) : #|A| = m -> val (f_A A) = enum A. by move=> Am; rewrite -[enum _](mkseq_nth i0) -cardE Am. have inc_A (A : {set 'I_n}) : sorted ltn (map val (enum A)). rewrite -[enum _](eq_filter (mem_enum _)). rewrite -(eq_filter (mem_map val_inj _)) -filter_map. by rewrite (sorted_filter ltn_trans) // unlock val_ord_enum iota_ltn_sorted. rewrite -!sum1dep_card (reindex_onto f_t f_A) /= => [|A]; last first. by move/eqP=> cardAm; apply/setP=> x; rewrite inE -(mem_enum A) -val_fA. apply: eq_bigl => t. apply/idP/idP => [inc_t|/andP [/eqP t_m /eqP <-]]; last by rewrite val_fA. have ft_m: #|f_t t| = m. rewrite cardsE (card_uniqP _) ?size_tuple // -(map_inj_uniq val_inj). exact: (sorted_uniq ltn_trans ltnn). rewrite ft_m eqxx -val_eqE val_fA // -(inj_eq (inj_map val_inj)) /=. apply/eqP/(irr_sorted_eq ltn_trans ltnn) => // y. by apply/mapP/mapP=> [] [x t_x ->]; exists x; rewrite // mem_enum inE in t_x *. Qed. Lemma card_sorted_tuples m n : #|[set t : m.-tuple 'I_n.+1 | sorted leq (map val t)]| = 'C(m + n, m). Proof. set In1 := 'I_n.+1; pose x0 : In1 := ord0. have add_mnP (i : 'I_m) (x : In1) : i + x < m + n. by rewrite -ltnS -addSn -!addnS leq_add. pose add_mn t i := Ordinal (add_mnP i (tnth t i)). pose add_mn_nat (t : m.-tuple In1) i := i + nth x0 t i. have add_mnC t: val \o add_mn t =1 add_mn_nat t \o val. by move=> i; rewrite /= (tnth_nth x0). pose f_add t := [tuple of map (add_mn t) (ord_tuple m)]. rewrite -card_ltn_sorted_tuples -!sum1dep_card (reindex f_add) /=. apply: eq_bigl => t; rewrite -map_comp (eq_map (add_mnC t)) map_comp. rewrite enumT unlock val_ord_enum -[in LHS](drop0 t). have [m0 | m_gt0] := posnP m. by rewrite {2}m0 /= drop_oversize // size_tuple m0. have def_m := subnK m_gt0; rewrite -{2}def_m addn1 /= {1}/add_mn_nat. move: 0 (m - 1) def_m => i k; rewrite -[in RHS](size_tuple t) => def_m. rewrite (drop_nth x0) /=; last by rewrite -def_m leq_addl. elim: k i (nth x0 t i) def_m => [|k IHk] i x /=. by rewrite add0n => ->; rewrite drop_size. rewrite addSnnS => def_m; rewrite -addSn leq_add2l -IHk //. by rewrite (drop_nth x0) // -def_m leq_addl. pose sub_mn (t : m.-tuple 'I_(m + n)) i : In1 := inord (tnth t i - i). exists (fun t => [tuple of map (sub_mn t) (ord_tuple m)]) => [t _ | t]. apply: eq_from_tnth => i; apply: val_inj. by rewrite /sub_mn !(tnth_ord_tuple, tnth_map) addKn inord_val. rewrite inE /= => inc_t; apply: eq_from_tnth => i; apply: val_inj. rewrite tnth_map tnth_ord_tuple /= tnth_map tnth_ord_tuple. suffices [le_i_ti le_ti_ni]: i <= tnth t i /\ tnth t i <= i + n. by rewrite /sub_mn inordK ?subnKC // ltnS leq_subLR. pose y0 := tnth t i; rewrite (tnth_nth y0) -(nth_map _ (val i)) ?size_tuple //. case def_e: (map _ _) => [|x e] /=; first by rewrite nth_nil ?leq_addr. set nth_i := nth (i : nat); rewrite def_e in inc_t; split. have: i < size (x :: e) by rewrite -def_e size_map size_tuple ltn_ord. elim: (val i) => //= j IHj lt_j_e. by apply: leq_trans (pathP (val i) inc_t _ lt_j_e); rewrite ltnS IHj 1?ltnW. move: (_ - _) (subnK (valP i)) => k /=. elim: k (val i) => /= [|k IHk] j; rewrite -ltnS -addSn ?add0n => def_m. by rewrite def_m -def_e /nth_i (nth_map y0) ?ltn_ord // size_tuple -def_m. rewrite (leq_trans _ (IHk _ _)) -1?addSnnS //; apply: (pathP _ inc_t). rewrite -ltnS (leq_trans (leq_addl k _)) // -addSnnS def_m. by rewrite -(size_tuple t) -(size_map val) def_e. Qed. Lemma card_partial_ord_partitions m n : #|[set t : m.-tuple 'I_n.+1 | \sum_(i <- t) i <= n]| = 'C(m + n, m). Proof. symmetry; set In1 := 'I_n.+1; pose x0 : In1 := ord0. pose add_mn (i j : In1) : In1 := inord (i + j). pose f_add (t : m.-tuple In1) := [tuple of scanl add_mn x0 t]. rewrite -card_sorted_tuples -!sum1dep_card (reindex f_add) /=. apply: eq_bigl => t; rewrite -[\sum_(i <- t) i]add0n. transitivity (path leq x0 (map val (f_add t))) => /=; first by case: map. rewrite -{1 2}[0]/(val x0); elim: {t}(val t) (x0) => /= [|x t IHt] s. by rewrite big_nil addn0 -ltnS ltn_ord. rewrite big_cons addnA IHt /= val_insubd ltnS. have [_ | ltn_n_sx] := leqP (s + x) n; first by rewrite leq_addr. rewrite -(leq_add2r x) leqNgt (leq_trans (valP x)) //=. by rewrite leqNgt (leq_trans ltn_n_sx) ?leq_addr. pose sub_mn (i j : In1) := Ordinal (leq_ltn_trans (leq_subr i j) (valP j)). exists (fun t : m.-tuple In1 => [tuple of pairmap sub_mn x0 t]) => /= t inc_t. apply: val_inj => /=; have{inc_t}: path leq x0 (map val (f_add t)). by move: inc_t; rewrite inE /=; case: map. rewrite [map _ _]/=; elim: {t}(val t) (x0) => //= x t IHt s. case/andP=> le_s_sx /IHt->; congr (_ :: _); apply: val_inj => /=. move: le_s_sx; rewrite val_insubd. case le_sx_n: (_ < n.+1); first by rewrite addKn. by case: (val s) le_sx_n; rewrite ?ltn_ord. apply: val_inj => /=; have{inc_t}: path leq x0 (map val t). by move: inc_t; rewrite inE /=; case: map. elim: {t}(val t) (x0) => //= x t IHt s /andP[le_s_sx inc_t]. suffices ->: add_mn s (sub_mn s x) = x by rewrite IHt. by apply: val_inj; rewrite /add_mn /= subnKC ?inord_val. Qed. Lemma card_ord_partitions m n : #|[set t : m.+1.-tuple 'I_n.+1 | \sum_(i <- t) i == n]| = 'C(m + n, m). Proof. symmetry; set In1 := 'I_n.+1; pose x0 : In1 := ord0. pose f_add (t : m.-tuple In1) := [tuple of sub_ord (\sum_(x <- t) x) :: t]. rewrite -card_partial_ord_partitions -!sum1dep_card (reindex f_add) /=. by apply: eq_bigl => t; rewrite big_cons /= addnC (sameP maxn_idPr eqP) maxnE. exists (fun t : m.+1.-tuple In1 => [tuple of behead t]) => [t _|]. exact: val_inj. case/tupleP=> x t /[!(inE, big_cons)] /eqP def_n. by apply: val_inj; congr (_ :: _); apply: val_inj; rewrite /= -{1}def_n addnK. Qed. End Combinations.
Card.lean
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Algebra.NoZeroSMulDivisors.Basic import Mathlib.SetTheory.Cardinal.Basic /-! # Cardinality of a module This file proves that the cardinality of a module without zero divisors is at least the cardinality of its base ring. -/ open Function universe u v namespace Cardinal /-- The cardinality of a nontrivial module over a ring is at least the cardinality of the ring if there are no zero divisors (for instance if the ring is a field) -/ theorem mk_le_of_module (R : Type u) (E : Type v) [AddCommGroup E] [Ring R] [Module R E] [Nontrivial E] [NoZeroSMulDivisors R E] : Cardinal.lift.{v} (#R) ≤ Cardinal.lift.{u} (#E) := by obtain ⟨x, hx⟩ : ∃ (x : E), x ≠ 0 := exists_ne 0 have : Injective (fun k ↦ k • x) := smul_left_injective R hx exact lift_mk_le_lift_mk_of_injective this end Cardinal
imset2_finset.v
From mathcomp Require Import all_boot. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Check @imset2_pair.
Abs.lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import Mathlib.Algebra.Order.Group.Defs import Mathlib.Algebra.Order.Group.Unbundled.Abs import Mathlib.Algebra.Order.Monoid.Unbundled.Pow /-! # Absolute values in ordered groups The absolute value of an element in a group which is also a lattice is its supremum with its negation. This generalizes the usual absolute value on real numbers (`|x| = max x (-x)`). ## Notations - `|a|`: The *absolute value* of an element `a` of an additive lattice ordered group - `|a|ₘ`: The *absolute value* of an element `a` of a multiplicative lattice ordered group -/ open Function variable {G : Type*} section LinearOrderedCommGroup variable [CommGroup G] [LinearOrder G] [IsOrderedMonoid G] {a b c : G} @[to_additive] lemma mabs_pow (n : ℕ) (a : G) : |a ^ n|ₘ = |a|ₘ ^ n := by obtain ha | ha := le_total a 1 · rw [mabs_of_le_one ha, ← mabs_inv, ← inv_pow, mabs_of_one_le] exact one_le_pow_of_one_le' (one_le_inv'.2 ha) n · rw [mabs_of_one_le ha, mabs_of_one_le (one_le_pow_of_one_le' ha n)] @[to_additive] private lemma mabs_mul_eq_mul_mabs_le (hab : a ≤ b) : |a * b|ₘ = |a|ₘ * |b|ₘ ↔ 1 ≤ a ∧ 1 ≤ b ∨ a ≤ 1 ∧ b ≤ 1 := by obtain ha | ha := le_or_gt 1 a <;> obtain hb | hb := le_or_gt 1 b · simp [ha, hb, mabs_of_one_le, one_le_mul ha hb] · exact (lt_irrefl (1 : G) <| ha.trans_lt <| hab.trans_lt hb).elim swap · simp [ha.le, hb.le, mabs_of_le_one, mul_le_one', mul_comm] have : (|a * b|ₘ = a⁻¹ * b ↔ b ≤ 1) ↔ (|a * b|ₘ = |a|ₘ * |b|ₘ ↔ 1 ≤ a ∧ 1 ≤ b ∨ a ≤ 1 ∧ b ≤ 1) := by simp [ha.le, ha.not_ge, hb, mabs_of_le_one, mabs_of_one_le] refine this.mp ⟨fun h ↦ ?_, fun h ↦ by simp only [h.antisymm hb, mabs_of_lt_one ha, mul_one]⟩ obtain ab | ab := le_or_gt (a * b) 1 · refine (eq_one_of_inv_eq' ?_).le rwa [mabs_of_le_one ab, mul_inv_rev, mul_comm, mul_right_inj] at h · rw [mabs_of_one_lt ab, mul_left_inj] at h rw [eq_one_of_inv_eq' h.symm] at ha cases ha.false @[to_additive] lemma mabs_mul_eq_mul_mabs_iff (a b : G) : |a * b|ₘ = |a|ₘ * |b|ₘ ↔ 1 ≤ a ∧ 1 ≤ b ∨ a ≤ 1 ∧ b ≤ 1 := by obtain ab | ab := le_total a b · exact mabs_mul_eq_mul_mabs_le ab · simpa only [mul_comm, and_comm] using mabs_mul_eq_mul_mabs_le ab @[to_additive] theorem mabs_le : |a|ₘ ≤ b ↔ b⁻¹ ≤ a ∧ a ≤ b := by rw [mabs_le', and_comm, inv_le'] @[to_additive] theorem le_mabs' : a ≤ |b|ₘ ↔ b ≤ a⁻¹ ∨ a ≤ b := by rw [le_mabs, or_comm, le_inv'] @[to_additive] theorem inv_le_of_mabs_le (h : |a|ₘ ≤ b) : b⁻¹ ≤ a := (mabs_le.mp h).1 @[to_additive] theorem le_of_mabs_le (h : |a|ₘ ≤ b) : a ≤ b := (mabs_le.mp h).2 /-- The **triangle inequality** in `LinearOrderedCommGroup`s. -/ @[to_additive /-- The **triangle inequality** in `LinearOrderedAddCommGroup`s. -/] theorem mabs_mul (a b : G) : |a * b|ₘ ≤ |a|ₘ * |b|ₘ := by rw [mabs_le, mul_inv] constructor <;> gcongr <;> apply_rules [inv_mabs_le, le_mabs_self] @[to_additive] theorem mabs_mul' (a b : G) : |a|ₘ ≤ |b|ₘ * |b * a|ₘ := by simpa using mabs_mul b⁻¹ (b * a) @[to_additive] theorem mabs_div (a b : G) : |a / b|ₘ ≤ |a|ₘ * |b|ₘ := by rw [div_eq_mul_inv, ← mabs_inv b] exact mabs_mul a _ @[to_additive] theorem mabs_div_le_iff : |a / b|ₘ ≤ c ↔ a / b ≤ c ∧ b / a ≤ c := by rw [mabs_le, inv_le_div_iff_le_mul, div_le_iff_le_mul', and_comm, div_le_iff_le_mul'] @[to_additive] theorem mabs_div_lt_iff : |a / b|ₘ < c ↔ a / b < c ∧ b / a < c := by rw [mabs_lt, inv_lt_div_iff_lt_mul', div_lt_iff_lt_mul', and_comm, div_lt_iff_lt_mul'] @[to_additive] theorem div_le_of_mabs_div_le_left (h : |a / b|ₘ ≤ c) : b / c ≤ a := div_le_comm.1 <| (mabs_div_le_iff.1 h).2 @[to_additive] theorem div_le_of_mabs_div_le_right (h : |a / b|ₘ ≤ c) : a / c ≤ b := div_le_of_mabs_div_le_left (mabs_div_comm a b ▸ h) @[to_additive] theorem div_lt_of_mabs_div_lt_left (h : |a / b|ₘ < c) : b / c < a := div_lt_comm.1 <| (mabs_div_lt_iff.1 h).2 @[to_additive] theorem div_lt_of_mabs_div_lt_right (h : |a / b|ₘ < c) : a / c < b := div_lt_of_mabs_div_lt_left (mabs_div_comm a b ▸ h) @[to_additive] theorem mabs_div_mabs_le_mabs_div (a b : G) : |a|ₘ / |b|ₘ ≤ |a / b|ₘ := div_le_iff_le_mul.2 <| calc |a|ₘ = |a / b * b|ₘ := by rw [div_mul_cancel] _ ≤ |a / b|ₘ * |b|ₘ := mabs_mul _ _ @[to_additive] theorem mabs_mabs_div_mabs_le_mabs_div (a b : G) : |(|a|ₘ / |b|ₘ)|ₘ ≤ |a / b|ₘ := mabs_div_le_iff.2 ⟨mabs_div_mabs_le_mabs_div _ _, by rw [mabs_div_comm]; apply mabs_div_mabs_le_mabs_div⟩ /-- `|a / b|ₘ ≤ n` if `1 ≤ a ≤ n` and `1 ≤ b ≤ n`. -/ @[to_additive /-- `|a - b| ≤ n` if `0 ≤ a ≤ n` and `0 ≤ b ≤ n`. -/] theorem mabs_div_le_of_one_le_of_le {a b n : G} (one_le_a : 1 ≤ a) (a_le_n : a ≤ n) (one_le_b : 1 ≤ b) (b_le_n : b ≤ n) : |a / b|ₘ ≤ n := by rw [mabs_div_le_iff, div_le_iff_le_mul, div_le_iff_le_mul] exact ⟨le_mul_of_le_of_one_le a_le_n one_le_b, le_mul_of_le_of_one_le b_le_n one_le_a⟩ /-- `|a / b|ₘ < n` if `1 ≤ a < n` and `1 ≤ b < n`. -/ @[to_additive /-- `|a - b| < n` if `0 ≤ a < n` and `0 ≤ b < n`. -/] theorem mabs_div_lt_of_one_le_of_lt {a b n : G} (one_le_a : 1 ≤ a) (a_lt_n : a < n) (one_le_b : 1 ≤ b) (b_lt_n : b < n) : |a / b|ₘ < n := by rw [mabs_div_lt_iff, div_lt_iff_lt_mul, div_lt_iff_lt_mul] exact ⟨lt_mul_of_lt_of_one_le a_lt_n one_le_b, lt_mul_of_lt_of_one_le b_lt_n one_le_a⟩ @[to_additive] theorem mabs_eq (hb : 1 ≤ b) : |a|ₘ = b ↔ a = b ∨ a = b⁻¹ := by refine ⟨eq_or_eq_inv_of_mabs_eq, ?_⟩ rintro (rfl | rfl) <;> simp only [mabs_inv, mabs_of_one_le hb] @[to_additive] theorem mabs_le_max_mabs_mabs (hab : a ≤ b) (hbc : b ≤ c) : |b|ₘ ≤ max |a|ₘ |c|ₘ := mabs_le'.2 ⟨by simp [hbc.trans (le_mabs_self c)], by simp [(inv_le_inv_iff.mpr hab).trans (inv_le_mabs a)]⟩ omit [IsOrderedMonoid G] in @[to_additive] theorem min_mabs_mabs_le_mabs_max : min |a|ₘ |b|ₘ ≤ |max a b|ₘ := (le_total a b).elim (fun h => (min_le_right _ _).trans_eq <| congr_arg _ (max_eq_right h).symm) fun h => (min_le_left _ _).trans_eq <| congr_arg _ (max_eq_left h).symm omit [IsOrderedMonoid G] in @[to_additive] theorem min_mabs_mabs_le_mabs_min : min |a|ₘ |b|ₘ ≤ |min a b|ₘ := (le_total a b).elim (fun h => (min_le_left _ _).trans_eq <| congr_arg _ (min_eq_left h).symm) fun h => (min_le_right _ _).trans_eq <| congr_arg _ (min_eq_right h).symm omit [IsOrderedMonoid G] in @[to_additive] theorem mabs_max_le_max_mabs_mabs : |max a b|ₘ ≤ max |a|ₘ |b|ₘ := (le_total a b).elim (fun h => (congr_arg _ <| max_eq_right h).trans_le <| le_max_right _ _) fun h => (congr_arg _ <| max_eq_left h).trans_le <| le_max_left _ _ omit [IsOrderedMonoid G] in @[to_additive] theorem mabs_min_le_max_mabs_mabs : |min a b|ₘ ≤ max |a|ₘ |b|ₘ := (le_total a b).elim (fun h => (congr_arg _ <| min_eq_left h).trans_le <| le_max_left _ _) fun h => (congr_arg _ <| min_eq_right h).trans_le <| le_max_right _ _ @[to_additive] theorem eq_of_mabs_div_eq_one {a b : G} (h : |a / b|ₘ = 1) : a = b := div_eq_one.1 <| mabs_eq_one.1 h @[to_additive] theorem mabs_div_le (a b c : G) : |a / c|ₘ ≤ |a / b|ₘ * |b / c|ₘ := calc |a / c|ₘ = |a / b * (b / c)|ₘ := by rw [div_mul_div_cancel] _ ≤ |a / b|ₘ * |b / c|ₘ := mabs_mul _ _ @[to_additive] theorem mabs_div_le_max_div {a b c : G} (hac : a ≤ b) (hcd : b ≤ c) (d : G) : |b / d|ₘ ≤ max (c / d) (d / a) := by rcases le_total d b with h | h · rw [mabs_of_one_le <| one_le_div'.mpr h] exact le_max_of_le_left <| div_le_div_right' hcd _ · rw [mabs_of_le_one <| div_le_one'.mpr h, inv_div] exact le_max_of_le_right <| div_le_div_left' hac _ @[to_additive] theorem mabs_mul_three (a b c : G) : |a * b * c|ₘ ≤ |a|ₘ * |b|ₘ * |c|ₘ := (mabs_mul _ _).trans (mul_le_mul_right' (mabs_mul _ _) _) @[to_additive] theorem mabs_div_le_of_le_of_le {a b lb ub : G} (hal : lb ≤ a) (hau : a ≤ ub) (hbl : lb ≤ b) (hbu : b ≤ ub) : |a / b|ₘ ≤ ub / lb := mabs_div_le_iff.2 ⟨div_le_div'' hau hbl, div_le_div'' hbu hal⟩ @[deprecated (since := "2025-03-02")] alias dist_bdd_within_interval := abs_sub_le_of_le_of_le @[to_additive] theorem eq_of_mabs_div_le_one (h : |a / b|ₘ ≤ 1) : a = b := eq_of_mabs_div_eq_one (le_antisymm h (one_le_mabs (a / b))) @[to_additive] lemma eq_of_mabs_div_lt_all {x y : G} (h : ∀ ε > 1, |x / y|ₘ < ε) : x = y := eq_of_mabs_div_le_one <| le_of_forall_gt h @[to_additive] lemma eq_of_mabs_div_le_all [DenselyOrdered G] {x y : G} (h : ∀ ε > 1, |x / y|ₘ ≤ ε) : x = y := eq_of_mabs_div_le_one <| forall_gt_imp_ge_iff_le_of_dense.mp h @[to_additive] theorem mabs_div_le_one : |a / b|ₘ ≤ 1 ↔ a = b := ⟨eq_of_mabs_div_le_one, by rintro rfl; rw [div_self', mabs_one]⟩ @[to_additive] theorem mabs_div_pos : 1 < |a / b|ₘ ↔ a ≠ b := not_le.symm.trans mabs_div_le_one.not @[to_additive (attr := simp)] theorem mabs_eq_self : |a|ₘ = a ↔ 1 ≤ a := by rw [mabs_eq_max_inv, max_eq_left_iff, inv_le_self_iff] @[to_additive (attr := simp)] theorem mabs_eq_inv_self : |a|ₘ = a⁻¹ ↔ a ≤ 1 := by rw [mabs_eq_max_inv, max_eq_right_iff, le_inv_self_iff] /-- For an element `a` of a multiplicative linear ordered group, either `|a|ₘ = a` and `1 ≤ a`, or `|a|ₘ = a⁻¹` and `a < 1`. -/ @[to_additive /-- For an element `a` of an additive linear ordered group, either `|a| = a` and `0 ≤ a`, or `|a| = -a` and `a < 0`. Use cases on this lemma to automate linarith in inequalities -/] theorem mabs_cases (a : G) : |a|ₘ = a ∧ 1 ≤ a ∨ |a|ₘ = a⁻¹ ∧ a < 1 := by cases le_or_gt 1 a <;> simp [*, le_of_lt] @[to_additive (attr := simp)] theorem max_one_mul_max_inv_one_eq_mabs_self (a : G) : max a 1 * max a⁻¹ 1 = |a|ₘ := by symm rcases le_total 1 a with (ha | ha) <;> simp [ha] end LinearOrderedCommGroup section LinearOrderedAddCommGroup variable [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G] {a b c : G} @[to_additive] theorem apply_abs_le_mul_of_one_le' {H : Type*} [MulOneClass H] [LE H] [MulLeftMono H] [MulRightMono H] {f : G → H} {a : G} (h₁ : 1 ≤ f a) (h₂ : 1 ≤ f (-a)) : f |a| ≤ f a * f (-a) := (le_total a 0).rec (fun ha => (abs_of_nonpos ha).symm ▸ le_mul_of_one_le_left' h₁) fun ha => (abs_of_nonneg ha).symm ▸ le_mul_of_one_le_right' h₂ @[to_additive] theorem apply_abs_le_mul_of_one_le {H : Type*} [MulOneClass H] [LE H] [MulLeftMono H] [MulRightMono H] {f : G → H} (h : ∀ x, 1 ≤ f x) (a : G) : f |a| ≤ f a * f (-a) := apply_abs_le_mul_of_one_le' (h _) (h _) end LinearOrderedAddCommGroup
Proper.lean
/- Copyright (c) 2024 Christian Merten, Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten, Andrew Yang -/ import Mathlib.AlgebraicGeometry.Morphisms.Separated import Mathlib.AlgebraicGeometry.Morphisms.Finite /-! # Proper morphisms A morphism of schemes is proper if it is separated, universally closed and (locally) of finite type. Note that we don't require quasi-compact, since this is implied by universally closed. ## Main results - `AlgebraicGeometry.isField_of_universallyClosed`: If `X` is an integral scheme that is universally closed over `Spec K`, then `Γ(X, ⊤)` is a field. - `AlgebraicGeometry.finite_appTop_of_universallyClosed`: If `X` is an integral scheme that is universally closed and of finite type over `Spec K`, then `Γ(X, ⊤)` is finite dimensional over `K`. -/ noncomputable section open CategoryTheory universe u namespace AlgebraicGeometry variable {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) /-- A morphism is proper if it is separated, universally closed and locally of finite type. -/ @[mk_iff] class IsProper : Prop extends IsSeparated f, UniversallyClosed f, LocallyOfFiniteType f where lemma isProper_eq : @IsProper = (@IsSeparated ⊓ @UniversallyClosed : MorphismProperty Scheme) ⊓ @LocallyOfFiniteType := by ext X Y f rw [isProper_iff, ← and_assoc] rfl namespace IsProper instance : MorphismProperty.RespectsIso @IsProper := by rw [isProper_eq] infer_instance instance stableUnderComposition : MorphismProperty.IsStableUnderComposition @IsProper := by rw [isProper_eq] infer_instance instance : MorphismProperty.IsMultiplicative @IsProper := by rw [isProper_eq] infer_instance instance [IsProper f] [IsProper g] : IsProper (f ≫ g) where instance (priority := 900) [IsFinite f] : IsProper f where instance isStableUnderBaseChange : MorphismProperty.IsStableUnderBaseChange @IsProper := by rw [isProper_eq] infer_instance instance : IsLocalAtTarget @IsProper := by rw [isProper_eq] infer_instance end IsProper lemma IsFinite.eq_isProper_inf_isAffineHom : @IsFinite = (@IsProper ⊓ @IsAffineHom : MorphismProperty _) := by have : (@IsAffineHom ⊓ @IsSeparated : MorphismProperty _) = @IsAffineHom := inf_eq_left.mpr fun _ _ _ _ ↦ inferInstance rw [inf_comm, isProper_eq, inf_assoc, ← inf_assoc, this, eq_inf, IsIntegralHom.eq_universallyClosed_inf_isAffineHom, inf_assoc, inf_left_comm] variable {f} in lemma IsFinite.iff_isProper_and_isAffineHom : IsFinite f ↔ IsProper f ∧ IsAffineHom f := by rw [eq_isProper_inf_isAffineHom] rfl instance (priority := 100) [IsFinite f] : IsProper f := (IsFinite.iff_isProper_and_isAffineHom.mp ‹_›).1 @[stacks 01W6 "(1)"] lemma UniversallyClosed.of_comp_of_isSeparated [UniversallyClosed (f ≫ g)] [IsSeparated g] : UniversallyClosed f := by rw [← Limits.pullback.lift_snd (𝟙 _) f (Category.id_comp (f ≫ g))] have := MorphismProperty.pullback_snd (P := @UniversallyClosed) (f ≫ g) g inferInstance infer_instance @[stacks 01W6 "(2)"] lemma IsProper.of_comp_of_isSeparated [IsProper (f ≫ g)] [IsSeparated g] : IsProper f := by rw [← Limits.pullback.lift_snd (𝟙 _) f (Category.id_comp (f ≫ g))] have := MorphismProperty.pullback_snd (P := @IsProper) (f ≫ g) g inferInstance infer_instance section GlobalSection variable (K : Type u) [Field K] /-- If `f : X ⟶ Y` is universally closed and `Y` is affine, then the map on global sections is integral. -/ theorem isIntegral_appTop_of_universallyClosed (f : X ⟶ Y) [UniversallyClosed f] [IsAffine Y] : f.appTop.hom.IsIntegral := by have : CompactSpace X := (quasiCompact_over_affine_iff f).mp inferInstance have : UniversallyClosed (X.toSpecΓ ≫ Spec.map f.appTop) := by rwa [← Scheme.toSpecΓ_naturality, MorphismProperty.cancel_right_of_respectsIso (P := @UniversallyClosed)] have : UniversallyClosed X.toSpecΓ := .of_comp_of_isSeparated _ (Spec.map f.appTop) rw [← IsIntegralHom.SpecMap_iff, IsIntegralHom.iff_universallyClosed_and_isAffineHom] exact ⟨.of_comp_surjective X.toSpecΓ _, inferInstance⟩ /-- If `X` is an integral scheme that is universally closed over `Spec K`, then `Γ(X, ⊤)` is a field. -/ theorem isField_of_universallyClosed (f : X ⟶ Spec(K)) [IsIntegral X] [UniversallyClosed f] : IsField Γ(X, ⊤) := by let F := (Scheme.ΓSpecIso _).inv ≫ f.appTop have : F.hom.IsIntegral := by apply RingHom.isIntegral_respectsIso.2 (e := (Scheme.ΓSpecIso _).symm.commRingCatIsoToRingEquiv) exact isIntegral_appTop_of_universallyClosed f algebraize [F.hom] exact isField_of_isIntegral_of_isField' (Field.toIsField K) /-- If `X` is an integral scheme that is universally closed and of finite type over `Spec K`, then `Γ(X, ⊤)` is a finite field extension over `K`. -/ theorem finite_appTop_of_universallyClosed (f : X ⟶ Spec(K)) [IsIntegral X] [UniversallyClosed f] [LocallyOfFiniteType f] : f.appTop.hom.Finite := by have x : X := Nonempty.some inferInstance obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ := (isBasis_affine_open X).exists_subset_of_mem_open (Set.mem_univ x) isOpen_univ letI := ((Scheme.ΓSpecIso (.of K)).commRingCatIsoToRingEquiv.toMulEquiv.isField (Field.toIsField K)).toField letI := (isField_of_universallyClosed K f).toField have : Nonempty U := ⟨⟨x, hxU⟩⟩ apply RingHom.finite_of_algHom_finiteType_of_isJacobsonRing (A := Γ(X, U)) (g := (X.presheaf.map (homOfLE le_top).op).hom) exact LocallyOfFiniteType.finiteType_of_affine_subset ⟨⊤, isAffineOpen_top _⟩ ⟨U, hU⟩ (by simp) end GlobalSection end AlgebraicGeometry
TuringMachine.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Tape import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.PFun import Mathlib.Computability.PostTuringMachine /-! # Turing machines The files `PostTuringMachine.lean` and `TuringMachine.lean` define a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. `PostTuringMachine.lean` covers the TM0 model and TM1 model; `TuringMachine.lean` adds the TM2 model. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Γ` is the alphabet on the tape. * `Λ` is the set of labels, or internal machine states. * `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Λ`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Λ → Stmt`, although different models have different ways of halting and other actions. * `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Γ`. * `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open List (Vector) open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-! ## The TM2 model The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks, each with elements of different types (the alphabet of stack `k : K` is `Γ k`). The statements are: * `push k (f : σ → Γ k) q` puts `f a` on the `k`-th stack, then does `q`. * `pop k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, and removes this element from the stack, then does `q`. * `peek k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, then does `q`. * `load (f : σ → σ) q` reads nothing but applies `f` to the internal state, then does `q`. * `branch (f : σ → Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`. * `goto (f : σ → Λ)` jumps to label `f a`. * `halt` halts on the next step. The configuration is a tuple `(l, var, stk)` where `l : Option Λ` is the current label to run or `none` for the halting state, `var : σ` is the (finite) internal state, and `stk : ∀ k, List (Γ k)` is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not `ListBlank`s, they have definite ends that can be detected by the `pop` command.) Given a designated stack `k` and a value `L : List (Γ k)`, the initial configuration has all the stacks empty except the designated "input" stack; in `eval` this designated stack also functions as the output stack. -/ namespace TM2 variable {K : Type*} -- Index type of stacks variable (Γ : K → Type*) -- Type of stack elements variable (Λ : Type*) -- Type of function labels variable (σ : Type*) -- Type of variable settings /-- The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks. The operation `push` puts an element on one of the stacks, and `pop` removes an element from a stack (and modifying the internal state based on the result). `peek` modifies the internal state but does not remove an element. -/ inductive Stmt | push : ∀ k, (σ → Γ k) → Stmt → Stmt | peek : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt | pop : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt | load : (σ → σ) → Stmt → Stmt | branch : (σ → Bool) → Stmt → Stmt → Stmt | goto : (σ → Λ) → Stmt | halt : Stmt open Stmt instance Stmt.inhabited : Inhabited (Stmt Γ Λ σ) := ⟨halt⟩ /-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite size.) -/ structure Cfg where /-- The current label to run (or `none` for the halting state) -/ l : Option Λ /-- The internal state -/ var : σ /-- The (finite) collection of internal stacks -/ stk : ∀ k, List (Γ k) instance Cfg.inhabited [Inhabited σ] : Inhabited (Cfg Γ Λ σ) := ⟨⟨default, default, default⟩⟩ variable {Γ Λ σ} section variable [DecidableEq K] /-- The step function for the TM2 model. -/ def stepAux : Stmt Γ Λ σ → σ → (∀ k, List (Γ k)) → Cfg Γ Λ σ | push k f q, v, S => stepAux q v (update S k (f v :: S k)) | peek k f q, v, S => stepAux q (f v (S k).head?) S | pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail) | load a q, v, S => stepAux q (a v) S | branch f q₁ q₂, v, S => cond (f v) (stepAux q₁ v S) (stepAux q₂ v S) | goto f, v, S => ⟨some (f v), v, S⟩ | halt, v, S => ⟨none, v, S⟩ /-- The step function for the TM2 model. -/ def step (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ) | ⟨none, _, _⟩ => none | ⟨some l, v, S⟩ => some (stepAux (M l) v S) attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3 stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2 /-- The (reflexive) reachability relation for the TM2 model. -/ def Reaches (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Cfg Γ Λ σ → Prop := ReflTransGen fun a b ↦ b ∈ step M a end /-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/ def SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop | push _ _ q => SupportsStmt S q | peek _ _ q => SupportsStmt S q | pop _ _ q => SupportsStmt S q | load _ q => SupportsStmt S q | branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂ | goto l => ∀ v, l v ∈ S | halt => True section open scoped Classical in /-- The set of subtree statements in a statement. -/ noncomputable def stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ) | Q@(push _ _ q) => insert Q (stmts₁ q) | Q@(peek _ _ q) => insert Q (stmts₁ q) | Q@(pop _ _ q) => insert Q (stmts₁ q) | Q@(load _ q) => insert Q (stmts₁ q) | Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂) | Q@(goto _) => {Q} | Q@halt => {Q} theorem stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁] theorem stmts₁_trans {q₁ q₂ : Stmt Γ Λ σ} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by classical intro h₁₂ q₀ h₀₁ induction q₂ with ( simp only [stmts₁] at h₁₂ ⊢ simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂) | branch f q₁ q₂ IH₁ IH₂ => rcases h₁₂ with (rfl | h₁₂ | h₁₂) · unfold stmts₁ at h₀₁ exact h₀₁ · exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂)) · exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IH₂ h₁₂)) | goto l => subst h₁₂; exact h₀₁ | halt => subst h₁₂; exact h₀₁ | load _ q IH | _ _ _ q IH => rcases h₁₂ with (rfl | h₁₂) · unfold stmts₁ at h₀₁ exact h₀₁ · exact Finset.mem_insert_of_mem (IH h₁₂) theorem stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h : q₁ ∈ stmts₁ q₂) (hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by induction q₂ with simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h hs | branch f q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2] | goto l => subst h; exact hs | halt => subst h; trivial | load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs] open scoped Classical in /-- The set of statements accessible from initial set `S` of labels. -/ noncomputable def stmts (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) : Finset (Option (Stmt Γ Λ σ)) := Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q)) theorem stmts_trans {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h₁ : q₁ ∈ stmts₁ q₂) : some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_trans h₂ h₁⟩ end variable [Inhabited Λ] /-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in `S` jump only to other states in `S`. -/ def Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) := default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q) theorem stmts_supportsStmt {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q : Stmt Γ Λ σ} (ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls) variable [DecidableEq K] theorem step_supports (M : Λ → Stmt Γ Λ σ) {S : Finset Λ} (ss : Supports M S) : ∀ {c c' : Cfg Γ Λ σ}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S | ⟨some l₁, v, T⟩, c', h₁, h₂ => by replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂) simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c' revert h₂; induction M l₁ generalizing v T with intro hs | branch p q₁' q₂' IH₁ IH₂ => unfold stepAux; cases p v · exact IH₂ _ _ hs.2 · exact IH₁ _ _ hs.1 | goto => exact Finset.some_mem_insertNone.2 (hs _) | halt => apply Multiset.mem_cons_self | load _ _ IH | _ _ _ _ IH => exact IH _ _ hs variable [Inhabited σ] /-- The initial state of the TM2 model. The input is provided on a designated stack. -/ def init (k : K) (L : List (Γ k)) : Cfg Γ Λ σ := ⟨some default, default, update (fun _ ↦ []) k L⟩ /-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/ def eval (M : Λ → Stmt Γ Λ σ) (k : K) (L : List (Γ k)) : Part (List (Γ k)) := (Turing.eval (step M) (init k L)).map fun c ↦ c.stk k end TM2 /-! ## TM2 emulator in TM1 To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack 1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this: ``` bottom: ... | _ | T | _ | _ | _ | _ | ... stack 1: ... | _ | b | a | _ | _ | _ | ... stack 2: ... | _ | f | e | d | c | _ | ... ``` where a tape element is a vertical slice through the diagram. Here the alphabet is `Γ' := Bool × ∀ k, Option (Γ k)`, where: * `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the tail of all stacks. It is never modified. * `stk k : Option (Γ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is the blank value). Note that the head of the stack is at the far end; this is so that push and pop don't have to do any shifting. In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions, it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the end of the appropriate stack, make its changes, and then return to the bottom. So the states are: * `normal (l : Λ)`: waiting at `bottom` to execute function `l` * `go k (s : StAct k) (q : Stmt₂)`: travelling to the right to get to the end of stack `k` in order to perform stack action `s`, and later continue with executing `q` * `ret (q : Stmt₂)`: travelling to the left after having performed a stack action, and executing `q` once we arrive Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)` steps to run when emulated in TM1, where `m` is the length of the input. -/ namespace TM2to1 -- A displaced lemma proved in unnecessary generality theorem stk_nth_val {K : Type*} {Γ : K → Type*} {L : ListBlank (∀ k, Option (Γ k))} {k S} (n) (hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) : L.nth n k = S.reverse[n]? := by rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.getElem?_map] cases S.reverse[n]? <;> rfl variable (K : Type*) variable (Γ : K → Type*) variable {Λ σ : Type*} /-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom, plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/ def Γ' := Bool × ∀ k, Option (Γ k) variable {K Γ} instance Γ'.inhabited : Inhabited (Γ' K Γ) := ⟨⟨false, fun _ ↦ none⟩⟩ instance Γ'.fintype [DecidableEq K] [Fintype K] [∀ k, Fintype (Γ k)] : Fintype (Γ' K Γ) := instFintypeProd _ _ /-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function to express the program state in terms of a tape with only the stacks themselves. -/ def addBottom (L : ListBlank (∀ k, Option (Γ k))) : ListBlank (Γ' K Γ) := ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩) theorem addBottom_map (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by simp only [addBottom, ListBlank.map_cons] convert ListBlank.cons_head_tail L generalize ListBlank.tail L = L' refine L'.induction_on fun l ↦ ?_; simp theorem addBottom_modifyNth (f : (∀ k, Option (Γ k)) → ∀ k, Option (Γ k)) (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) : (addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by cases n <;> simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons] congr; symm; apply ListBlank.map_modifyNth; intro; rfl theorem addBottom_nth_snd (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) : ((addBottom L).nth n).2 = L.nth n := by conv => rhs; rw [← addBottom_map L, ListBlank.nth_map] theorem addBottom_nth_succ_fst (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) : ((addBottom L).nth (n + 1)).1 = false := by rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map] theorem addBottom_head_fst (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).head.1 = true := by rw [addBottom, ListBlank.head_cons] variable (K Γ σ) in /-- A stack action is a command that interacts with the top of a stack. Our default position is at the bottom of all the stacks, so we have to hold on to this action while going to the end to modify the stack. -/ inductive StAct (k : K) | push : (σ → Γ k) → StAct k | peek : (σ → Option (Γ k) → σ) → StAct k | pop : (σ → Option (Γ k) → σ) → StAct k instance StAct.inhabited {k : K} : Inhabited (StAct K Γ σ k) := ⟨StAct.peek fun s _ ↦ s⟩ section open StAct /-- The TM2 statement corresponding to a stack action. -/ def stRun {k : K} : StAct K Γ σ k → TM2.Stmt Γ Λ σ → TM2.Stmt Γ Λ σ | push f => TM2.Stmt.push k f | peek f => TM2.Stmt.peek k f | pop f => TM2.Stmt.pop k f /-- The effect of a stack action on the local variables, given the value of the stack. -/ def stVar {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → σ | push _ => v | peek f => f v l.head? | pop f => f v l.head? /-- The effect of a stack action on the stack. -/ def stWrite {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → List (Γ k) | push f => f v :: l | peek _ => l | pop _ => l.tail /-- We have partitioned the TM2 statements into "stack actions", which require going to the end of the stack, and all other actions, which do not. This is a modified recursor which lumps the stack actions into one. -/ @[elab_as_elim] def stmtStRec.{l} {motive : TM2.Stmt Γ Λ σ → Sort l} (run : ∀ (k) (s : StAct K Γ σ k) (q) (_ : motive q), motive (stRun s q)) (load : ∀ (a q) (_ : motive q), motive (TM2.Stmt.load a q)) (branch : ∀ (p q₁ q₂) (_ : motive q₁) (_ : motive q₂), motive (TM2.Stmt.branch p q₁ q₂)) (goto : ∀ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : ∀ n, motive n | TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q) | TM2.Stmt.branch _ q₁ q₂ => branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt q₂) | TM2.Stmt.goto _ => goto _ | TM2.Stmt.halt => halt theorem supports_run (S : Finset Λ) {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) : TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by cases s <;> rfl end variable (K Γ Λ σ) /-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and return to the bottom, respectively. -/ inductive Λ' | normal : Λ → Λ' | go (k : K) : StAct K Γ σ k → TM2.Stmt Γ Λ σ → Λ' | ret : TM2.Stmt Γ Λ σ → Λ' variable {K Γ Λ σ} open Λ' instance Λ'.inhabited [Inhabited Λ] : Inhabited (Λ' K Γ Λ σ) := ⟨normal default⟩ open TM1.Stmt section variable [DecidableEq K] /-- The program corresponding to state transitions at the end of a stack. Here we start out just after the top of the stack, and should end just after the new top of the stack. -/ def trStAct {k : K} (q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ) : StAct K Γ σ k → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ | StAct.push f => (write fun a s ↦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q | StAct.peek f => move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| move Dir.right q | StAct.pop f => branch (fun a _ ↦ a.1) (load (fun _ s ↦ f s none) q) (move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| write (fun a _ ↦ (a.1, update a.2 k none)) q) /-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty except for the input stack, and the stack bottom mark is set at the head. -/ def trInit (k : K) (L : List (Γ k)) : List (Γ' K Γ) := let L' : List (Γ' K Γ) := L.reverse.map fun a ↦ (false, update (fun _ ↦ none) k (some a)) (true, L'.headI.2) :: L'.tail theorem step_run {k : K} (q : TM2.Stmt Γ Λ σ) (v : σ) (S : ∀ k, List (Γ k)) : ∀ s : StAct K Γ σ k, TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s)) | StAct.push _ => rfl | StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl | StAct.pop _ => rfl end /-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents, but stack actions are deferred by going to the corresponding `go` state, so that we can find the appropriate stack top. -/ def trNormal : TM2.Stmt Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ | TM2.Stmt.push k f q => goto fun _ _ ↦ go k (StAct.push f) q | TM2.Stmt.peek k f q => goto fun _ _ ↦ go k (StAct.peek f) q | TM2.Stmt.pop k f q => goto fun _ _ ↦ go k (StAct.pop f) q | TM2.Stmt.load a q => load (fun _ ↦ a) (trNormal q) | TM2.Stmt.branch f q₁ q₂ => branch (fun _ ↦ f) (trNormal q₁) (trNormal q₂) | TM2.Stmt.goto l => goto fun _ s ↦ normal (l s) | TM2.Stmt.halt => halt theorem trNormal_run {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) : trNormal (stRun s q) = goto fun _ _ ↦ go k s q := by cases s <;> rfl section open scoped Classical in /-- The set of machine states accessible from an initial TM2 statement. -/ noncomputable def trStmts₁ : TM2.Stmt Γ Λ σ → Finset (Λ' K Γ Λ σ) | TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} ∪ trStmts₁ q | TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} ∪ trStmts₁ q | TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} ∪ trStmts₁ q | TM2.Stmt.load _ q => trStmts₁ q | TM2.Stmt.branch _ q₁ q₂ => trStmts₁ q₁ ∪ trStmts₁ q₂ | _ => ∅ theorem trStmts₁_run {k : K} {s : StAct K Γ σ k} {q : TM2.Stmt Γ Λ σ} : open scoped Classical in trStmts₁ (stRun s q) = {go k s q, ret q} ∪ trStmts₁ q := by cases s <;> simp only [trStmts₁, stRun] theorem tr_respects_aux₂ [DecidableEq K] {k : K} {q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ} {v : σ} {S : ∀ k, List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))} (hL : ∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) : let v' := stVar v (S k) o let Sk' := stWrite v (S k) o let S' := update S k Sk' ∃ L' : ListBlank (∀ k, Option (Γ k)), (∀ k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) ∧ TM1.stepAux (trStAct q o) v ((Tape.move Dir.right)^[(S k).length] (Tape.mk' ∅ (addBottom L))) = TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' ∅ (addBottom L'))) := by simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux] | push f => have := Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k (some (f v))) refine ⟨_, fun k' ↦ ?_, by -- Porting note: `rw [...]` to `erw [...]; rfl`. -- https://github.com/leanprover-community/mathlib4/issues/5164 rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this] erw [addBottom_modifyNth fun a ↦ update a k (some (f v))] rw [Nat.add_one, iterate_succ'] rfl⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val] by_cases h' : k' = k · subst k' split_ifs with h <;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map] · rw [List.getI_eq_getElem _, List.getElem_append_right] <;> simp only [List.length_append, List.length_reverse, List.length_map, ← h, Nat.sub_self, List.length_singleton, List.getElem_singleton, le_refl, Nat.lt_succ_self] rw [← proj_map_nth, hL, ListBlank.nth_mk] rcases lt_or_gt_of_ne h with h | h · rw [List.getI_append] simpa only [List.length_map, List.length_reverse] using h · rw [List.getI_eq_default, List.getI_eq_default] <;> simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse, List.length_append, List.length_map] · split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL] rw [Function.update_of_ne h'] | peek f => rw [Function.update_eq_self] use L, hL; rw [Tape.move_left_right]; congr cases e : S k; · rfl rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e, List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length] rfl | pop f => rcases e : S k with - | ⟨hd, tl⟩ · simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length, Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil] rw [← e, Function.update_eq_self] exact ⟨L, hL, by rw [addBottom_head_fst, cond]⟩ · refine ⟨_, fun k' ↦ ?_, by erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst, cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head, Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k none), addBottom_modifyNth fun a ↦ update a k none, addBottom_nth_snd, stk_nth_val _ (hL k), e, show (List.cons hd tl).reverse[tl.length]? = some hd by rw [List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length], List.head?, List.tail]⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val] by_cases h' : k' = k · subst k' split_ifs with h <;> simp only [Function.update_self, ListBlank.nth_mk, List.tail] · rw [List.getI_eq_default] · rfl rw [h, List.length_reverse, List.length_map] rw [← proj_map_nth, hL, ListBlank.nth_mk, e, List.map, List.reverse_cons] rcases lt_or_gt_of_ne h with h | h · rw [List.getI_append] simpa only [List.length_map, List.length_reverse] using h · rw [List.getI_eq_default, List.getI_eq_default] <;> simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse, List.length_append, List.length_map] · split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL] rw [Function.update_of_ne h'] end variable [DecidableEq K] variable (M : Λ → TM2.Stmt Γ Λ σ) /-- The TM2 emulator machine states written as a TM1 program. This handles the `go` and `ret` states, which shuttle to and from a stack top. -/ def tr : Λ' K Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ | normal q => trNormal (M q) | go k s q => branch (fun a _ ↦ (a.2 k).isNone) (trStAct (goto fun _ _ ↦ ret q) s) (move Dir.right <| goto fun _ _ ↦ go k s q) | ret q => branch (fun a _ ↦ a.1) (trNormal q) (move Dir.left <| goto fun _ _ ↦ ret q) /-- The relation between TM2 configurations and TM1 configurations of the TM2 emulator. -/ inductive TrCfg : TM2.Cfg Γ Λ σ → TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ → Prop | mk {q : Option Λ} {v : σ} {S : ∀ k, List (Γ k)} (L : ListBlank (∀ k, Option (Γ k))) : (∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) → TrCfg ⟨q, v, S⟩ ⟨q.map normal, v, Tape.mk' ∅ (addBottom L)⟩ theorem tr_respects_aux₁ {k} (o q v) {S : List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))} (hL : L.map (proj k) = ListBlank.mk (S.map some).reverse) (n) (H : n ≤ S.length) : Reaches₀ (TM1.step (tr M)) ⟨some (go k o q), v, Tape.mk' ∅ (addBottom L)⟩ ⟨some (go k o q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩ := by induction n with | zero => rfl | succ n IH => apply (IH (le_of_lt H)).tail rw [iterate_succ_apply'] simp only [TM1.step, TM1.stepAux, tr, Tape.mk'_nth_nat, Tape.move_right_n_head, addBottom_nth_snd, Option.mem_def] rw [stk_nth_val _ hL, List.getElem?_eq_getElem] · rfl · rwa [List.length_reverse] theorem tr_respects_aux₃ {q v} {L : ListBlank (∀ k, Option (Γ k))} (n) : Reaches₀ (TM1.step (tr M)) ⟨some (ret q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩ ⟨some (ret q), v, Tape.mk' ∅ (addBottom L)⟩ := by induction n with | zero => rfl | succ n IH => refine Reaches₀.head ?_ IH simp only [Option.mem_def, TM1.step] rw [Option.some_inj, tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst, TM1.stepAux, iterate_succ', Function.comp_apply, Tape.move_right_left] rfl theorem tr_respects_aux {q v T k} {S : ∀ k, List (Γ k)} (hT : ∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) (IH : ∀ {v : σ} {S : ∀ k : K, List (Γ k)} {T : ListBlank (∀ k, Option (Γ k))}, (∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) → ∃ b, TrCfg (TM2.stepAux q v S) b ∧ Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal q) v (Tape.mk' ∅ (addBottom T))) b) : ∃ b, TrCfg (TM2.stepAux (stRun o q) v S) b ∧ Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal (stRun o q)) v (Tape.mk' ∅ (addBottom T))) b := by simp only [trNormal_run, step_run] have hgo := tr_respects_aux₁ M o q v (hT k) _ le_rfl obtain ⟨T', hT', hrun⟩ := tr_respects_aux₂ (Λ := Λ) hT o have := hgo.tail' rfl rw [tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hT k), List.getElem?_eq_none (le_of_eq List.length_reverse), Option.isNone, cond, hrun, TM1.stepAux] at this obtain ⟨c, gc, rc⟩ := IH hT' refine ⟨c, gc, (this.to₀.trans (tr_respects_aux₃ M _) c (TransGen.head' rfl ?_)).to_reflTransGen⟩ rw [tr, TM1.stepAux, Tape.mk'_head, addBottom_head_fst] exact rc attribute [local simp] Respects TM2.step TM2.stepAux trNormal theorem tr_respects : Respects (TM2.step M) (TM1.step (tr M)) TrCfg := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed intro c₁ c₂ h obtain @⟨- | l, v, S, L, hT⟩ := h; · constructor rsuffices ⟨b, c, r⟩ : ∃ b, _ ∧ Reaches (TM1.step (tr M)) _ _ · exact ⟨b, c, TransGen.head' rfl r⟩ simp only [tr] generalize M l = N induction N using stmtStRec generalizing v S L hT with | run k s q IH => exact tr_respects_aux M hT s @IH | load a _ IH => exact IH _ hT | branch p q₁ q₂ IH₁ IH₂ => unfold TM2.stepAux trNormal TM1.stepAux beta_reduce cases p v <;> [exact IH₂ _ hT; exact IH₁ _ hT] | goto => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩ | halt => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩ section variable [Inhabited Λ] [Inhabited σ] theorem trCfg_init (k) (L : List (Γ k)) : TrCfg (TM2.init k L) (TM1.init (trInit k L) : TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ) := by rw [(_ : TM1.init _ = _)] · refine ⟨ListBlank.mk (L.reverse.map fun a ↦ update default k (some a)), fun k' ↦ ?_⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map_map] have : ((proj k').f ∘ fun a => update (β := fun k => Option (Γ k)) default k (some a)) = fun a => (proj k').f (update (β := fun k => Option (Γ k)) default k (some a)) := rfl rw [this, List.getElem?_map, proj, PointedMap.mk_val] simp only [] by_cases h : k' = k · subst k' simp only [Function.update_self] rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, ← List.map_reverse, List.getElem?_map] · simp only [Function.update_of_ne h] rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map, List.reverse_nil] cases L.reverse[i]? <;> rfl · rw [trInit, TM1.init] congr <;> cases L.reverse <;> try rfl simp only [List.map_map, List.tail_cons, List.map] rfl theorem tr_eval_dom (k) (L : List (Γ k)) : (TM1.eval (tr M) (trInit k L)).Dom ↔ (TM2.eval M k L).Dom := Turing.tr_eval_dom (tr_respects M) (trCfg_init k L) theorem tr_eval (k) (L : List (Γ k)) {L₁ L₂} (H₁ : L₁ ∈ TM1.eval (tr M) (trInit k L)) (H₂ : L₂ ∈ TM2.eval M k L) : ∃ (S : ∀ k, List (Γ k)) (L' : ListBlank (∀ k, Option (Γ k))), addBottom L' = L₁ ∧ (∀ k, L'.map (proj k) = ListBlank.mk ((S k).map some).reverse) ∧ S k = L₂ := by obtain ⟨c₁, h₁, rfl⟩ := (Part.mem_map_iff _).1 H₁ obtain ⟨c₂, h₂, rfl⟩ := (Part.mem_map_iff _).1 H₂ obtain ⟨_, ⟨L', hT⟩, h₃⟩ := Turing.tr_eval (tr_respects M) (trCfg_init k L) h₂ cases Part.mem_unique h₁ h₃ exact ⟨_, L', by simp only [Tape.mk'_right₀], hT, rfl⟩ end section variable [Inhabited Λ] open scoped Classical in /-- The support of a set of TM2 states in the TM2 emulator. -/ noncomputable def trSupp (S : Finset Λ) : Finset (Λ' K Γ Λ σ) := S.biUnion fun l ↦ insert (normal l) (trStmts₁ (M l)) open scoped Classical in theorem tr_supports {S} (ss : TM2.Supports M S) : TM1.Supports (tr M) (trSupp M S) := ⟨Finset.mem_biUnion.2 ⟨_, ss.1, Finset.mem_insert.2 <| Or.inl rfl⟩, fun l' h ↦ by suffices ∀ (q) (_ : TM2.SupportsStmt S q) (_ : ∀ x ∈ trStmts₁ q, x ∈ trSupp M S), TM1.SupportsStmt (trSupp M S) (trNormal q) ∧ ∀ l' ∈ trStmts₁ q, TM1.SupportsStmt (trSupp M S) (tr M l') by rcases Finset.mem_biUnion.1 h with ⟨l, lS, h⟩ have := this _ (ss.2 l lS) fun x hx ↦ Finset.mem_biUnion.2 ⟨_, lS, Finset.mem_insert_of_mem hx⟩ rcases Finset.mem_insert.1 h with (rfl | h) <;> [exact this.1; exact this.2 _ h] clear h l' refine stmtStRec ?_ ?_ ?_ ?_ ?_ · intro _ s _ IH ss' sub -- stack op rw [TM2to1.supports_run] at ss' simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton] at sub have hgo := sub _ (Or.inl <| Or.inl rfl) have hret := sub _ (Or.inl <| Or.inr rfl) obtain ⟨IH₁, IH₂⟩ := IH ss' fun x hx ↦ sub x <| Or.inr hx refine ⟨by simp only [trNormal_run, TM1.SupportsStmt]; intros; exact hgo, fun l h ↦ ?_⟩ rw [trStmts₁_run] at h simp only [Finset.mem_union, Finset.mem_insert, Finset.mem_singleton] at h rcases h with (⟨rfl | rfl⟩ | h) · cases s · exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩ · exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩ · exact ⟨⟨fun _ _ ↦ hret, fun _ _ ↦ hret⟩, fun _ _ ↦ hgo⟩ · unfold TM1.SupportsStmt TM2to1.tr exact ⟨IH₁, fun _ _ ↦ hret⟩ · exact IH₂ _ h · intro _ _ IH ss' sub -- load unfold TM2to1.trStmts₁ at sub ⊢ exact IH ss' sub · intro _ _ _ IH₁ IH₂ ss' sub -- branch unfold TM2to1.trStmts₁ at sub obtain ⟨IH₁₁, IH₁₂⟩ := IH₁ ss'.1 fun x hx ↦ sub x <| Finset.mem_union_left _ hx obtain ⟨IH₂₁, IH₂₂⟩ := IH₂ ss'.2 fun x hx ↦ sub x <| Finset.mem_union_right _ hx refine ⟨⟨IH₁₁, IH₂₁⟩, fun l h ↦ ?_⟩ rw [trStmts₁] at h rcases Finset.mem_union.1 h with (h | h) <;> [exact IH₁₂ _ h; exact IH₂₂ _ h] · intro _ ss' _ -- goto simp only [trStmts₁, Finset.notMem_empty]; refine ⟨?_, fun _ ↦ False.elim⟩ exact fun _ v ↦ Finset.mem_biUnion.2 ⟨_, ss' v, Finset.mem_insert_self _ _⟩ · intro _ _ -- halt simp only [trStmts₁, Finset.notMem_empty] exact ⟨trivial, fun _ ↦ False.elim⟩⟩ end end TM2to1 end Turing
qfpoly.v
From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype tuple div bigop binomial finset finfun. From mathcomp Require Import ssralg countalg finalg poly polydiv qpoly perm. From mathcomp Require Import fingroup falgebra fieldext finfield galois. From mathcomp Require Import finalg zmodp matrix vector. (******************************************************************************) (* This file extends the algebras R[X]/<p> defined in qpoly with the field *) (* when p is irreducible *) (* It defines the new field on top of {qpoly p}. As irreducible is in general *) (* decidable in general, this is done by giving a proof explicitly. *) (* monic_irreducible_poly p == proof that p is monic and irreducible *) (* {poly %/ p with mi} == defined as {poly %/ p} where mi is proof of *) (* monic_irreducible_poly p *) (* It also defines the discrete logarithm with a primitive polynomial on a *) (* finite field *) (* primitive_poly p == p is a primitive polynomial *) (* qlogp q == is the discrete log of q where q is an element of *) (* the quotient field with respect to a primitive *) (* polynomial p *) (* plogp p q == is the discrete log of q with respect to p in {poly F} *) (* this makes only sense if p is a primitive polynomial of *) (* size > 2 *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Pdiv.CommonRing. Import Pdiv.RingMonic. Import Pdiv.Field. Import FinRing.Theory. Local Open Scope ring_scope. Reserved Notation "{ 'poly' '%/' p 'with' mi }" (p at level 2, mi at level 10, format "{ 'poly' '%/' p 'with' mi }"). Section DomainDef. Variable R : idomainType. Variable h : {poly R}. Definition monic_irreducible_poly (p : {poly R}) := ((irreducible_poly p) * (p \is monic))%type. Hypothesis hI : monic_irreducible_poly h. Definition qfpoly : monic_irreducible_poly h -> predArgType := fun=> {poly %/ h}. End DomainDef. Notation "{ 'poly' '%/' p 'with' hi }" := (@qfpoly _ p hi). Section iDomain. Variable R : idomainType. Variable h : {poly R}. Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := GRing.NzRing.on {poly %/ h with hI}. End iDomain. Section finIDomain. Variable R : finIdomainType. Variable h : {poly R}. Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := Finite.on {poly %/ h with hI}. End finIDomain. Section Field. Variable R : fieldType. Variable h : {poly R}. Local Notation hQ := (mk_monic h). Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := GRing.ComUnitRing.on {poly %/ h with hI}. Lemma mk_monicE : mk_monic h = h. Proof. by rewrite /mk_monic !hI. Qed. Lemma coprimep_unit (p : {poly %/ h}) : p != 0%R -> coprimep hQ p. Proof. move=> pNZ. rewrite irreducible_poly_coprime //; last first. by case: hI; rewrite mk_monicE. apply: contra pNZ => H; case: eqP => // /eqP /dvdp_leq /(_ H). by rewrite leqNgt size_mk_monic. Qed. Lemma qpoly_mulVp (p : {poly %/ h}) : p != 0%R -> (qpoly_inv p * p = 1)%R. Proof. by move=> pNZ; apply/qpoly_mulVz/coprimep_unit. Qed. Lemma qpoly_inv0 : qpoly_inv 0%R = 0%R :> {poly %/ h}. Proof. rewrite /qpoly_inv /= coprimep0 -size_poly_eq1. rewrite [in X in X == _]mk_monicE. by have [[]] := hI; case: size => [|[]]. Qed. HB.instance Definition _ := GRing.ComUnitRing_isField.Build {poly %/ h with hI} coprimep_unit. HB.instance Definition _ := GRing.UnitAlgebra.on {poly %/ h with hI}. HB.instance Definition _ := Vector.on {poly %/ h with hI}. End Field. Section FinField. Variable R : finFieldType. Variable h : {poly R}. Local Notation hQ := (mk_monic h). HB.instance Definition _ := Finite.on {poly %/ h}. Hypothesis hI : monic_irreducible_poly h. HB.instance Definition _ := Finite.on {poly %/ h with hI}. Lemma card_qfpoly : #|{poly %/ h with hI}| = #|R| ^ (size h).-1. Proof. by rewrite card_monic_qpoly ?hI. Qed. Lemma card_qfpoly_gt1 : 1 < #|{poly %/ h with hI}|. Proof. by have := card_finNzRing_gt1 {poly %/ h with hI}. Qed. End FinField. Section inPoly. Variable R : comNzRingType. Variable h : {poly R}. Lemma in_qpoly_comp_horner (p q : {poly R}) : in_qpoly h (p \Po q) = (map_poly (qpolyC h) p).[in_qpoly h q]. Proof. have hQM := monic_mk_monic h. rewrite comp_polyE /map_poly poly_def horner_sum /=. apply: val_inj. rewrite /= rmodp_sum // poly_of_qpoly_sum. apply: eq_bigr => i _. rewrite !hornerE /in_qpoly /=. rewrite mul_polyC // !rmodpZ //=. by rewrite poly_of_qpolyX /= rmodp_id // rmodpX // rmodp_id. Qed. Lemma map_poly_div_inj : injective (map_poly (qpolyC h)). Proof. apply: map_inj_poly => [x y /val_eqP /eqP /polyC_inj //|]. by rewrite qpolyC0. Qed. End inPoly. Section finPoly. (* Unfortunately we need some duplications so inference propagates qfpoly :-( )*) Definition qfpoly_const (R : idomainType) (h : {poly R}) (hMI : monic_irreducible_poly h) : R -> {poly %/ h with hMI} := qpolyC h. Lemma map_fpoly_div_inj (R : idomainType) (h : {poly R}) (hMI : monic_irreducible_poly h) : injective (map_poly (qfpoly_const hMI)). Proof. by apply: (@map_poly_div_inj R h). Qed. End finPoly. Section Splitting. Variable F : finFieldType. Variable h : {poly F}. Hypothesis hI : monic_irreducible_poly h. Definition qfpoly_splitting_field_type := FinSplittingFieldType F {poly %/ h with hI}. End Splitting. Section PrimitivePoly. Variable F : finFieldType. Variable h : {poly F}. Hypothesis sh_gt2 : 2 < size h. Let sh_gt1 : 1 < size h. Proof. by apply: leq_ltn_trans sh_gt2. Qed. Definition primitive_poly (p: {poly F}) := let v := #|{poly %/ p}|.-1 in [&& p \is monic, irreducibleb p, p %| 'X^v - 1 & [forall n : 'I_v, (p %| 'X^n - 1) ==> (n == 0%N :> nat)]]. Lemma primitive_polyP (p : {poly F}) : reflect (let v := #|{poly %/ p}|.-1 in [/\ monic_irreducible_poly p, p %| 'X^v - 1 & forall n, 0 < n < v -> ~~ (p %| 'X^n - 1)]) (primitive_poly p). Proof. apply: (iffP and4P) => [[H1 H2 H3 /forallP H4] v|[[H1 H2] H3 H4]]; split => //. - by split => //; apply/irreducibleP. - move=> n /andP[n_gt0 nLv]; apply/negP => /(implyP (H4 (Ordinal nLv))) /=. by rewrite eqn0Ngt n_gt0. - by apply/irreducibleP. apply/forallP=> [] [[|n] Hn] /=; apply/implyP => pDX //. by case/negP: (H4 n.+1 Hn). Qed. Hypothesis Hh : primitive_poly h. Lemma primitive_mi : monic_irreducible_poly h. Proof. by case/primitive_polyP: Hh. Qed. Lemma primitive_poly_in_qpoly_eq0 p : (in_qpoly h p == 0) = (h %| p). Proof. have hM : h \is monic by case/and4P:Hh. have hMi : monic_irreducible_poly h by apply: primitive_mi. apply/eqP/idP => [/val_eqP /= | hDp]. by rewrite -Pdiv.IdomainMonic.modpE mk_monicE. by apply/val_eqP; rewrite /= -Pdiv.IdomainMonic.modpE mk_monicE. Qed. Local Notation qT := {poly %/ h with primitive_mi}. Lemma card_primitive_qpoly : #|{poly %/ h}|= #|F| ^ (size h).-1. Proof. by rewrite card_monic_qpoly ?primitive_mi. Qed. Lemma qX_neq0 : 'qX != 0 :> qT. Proof. apply/eqP => /val_eqP/=. by rewrite [rmodp _ _]qpolyXE ?polyX_eq0 //; case: primitive_mi. Qed. Lemma qX_in_unit : ('qX : qT) \in GRing.unit. Proof. by rewrite unitfE /= qX_neq0. Qed. Definition gX : {unit qT} := FinRing.unit _ qX_in_unit. Lemma dvdp_order n : (h %| 'X^n - 1) = (gX ^+ n == 1)%g. Proof. have [hM hI] := primitive_mi. have eqr_add2r (r : nzRingType) (a b c : r) : (a + c == b + c) = (a == b). by apply/eqP/eqP => [H|->//]; rewrite -(addrK c a) H addrK. rewrite -val_eqE /= val_unitX /= -val_eqE /=. rewrite (poly_of_qpolyX) qpolyXE // mk_monicE //. rewrite -[in RHS](subrK 1 'X^n) rmodpD //. rewrite [rmodp 1 h]rmodp_small ?size_poly1 //. rewrite -[1%:P]add0r polyC1 /= eqr_add2r. by rewrite dvdpE /=; apply/rmodp_eq0P/eqP. Qed. Lemma gX_order : #[gX]%g = (#|qT|).-1. Proof. have /primitive_polyP[Hp1 Hp2 Hp3] := Hh. set n := _.-1 in Hp2 Hp3 *. have n_gt0 : 0 < n by rewrite ltn_predRL card_qfpoly_gt1. have [hM hI] := primitive_mi. have gX_neq1 : gX != 1%g. apply/eqP/val_eqP/eqP/val_eqP=> /=. rewrite [X in X != _]qpolyXE /= //. by apply/eqP=> Hx1; have := @size_polyX F; rewrite Hx1 size_poly1. have Hx : (gX ^+ n)%g = 1%g by apply/eqP; rewrite -dvdp_order. have Hf i : 0 < i < n -> (gX ^+ i != 1)%g by rewrite -dvdp_order => /Hp3. have o_gt0 : 0 < #[gX]%g by rewrite order_gt0. have : n <= #[gX]%g. rewrite leqNgt; apply/negP=> oLx. have /Hf/eqP[] : 0 < #[gX]%g < n by rewrite o_gt0. by rewrite expg_order. case: ltngtP => nLo _ //. have: uniq (path.traject (mulg gX) 1%g #[gX]%g). by apply/card_uniqP; rewrite path.size_traject -(eq_card (cycle_traject gX)). case: #[gX]%g o_gt0 nLo => //= n1 _ nLn1 /andP[/negP[]]. apply/path.trajectP; exists n.-1; first by rewrite prednK. rewrite -iterSr prednK // -[LHS]Hx. by elim: (n) => //= n2 <-; rewrite expgS. Qed. Lemma gX_all : <[gX]>%g = [set: {unit qT}]%G. Proof. apply/eqP; rewrite eqEcard; apply/andP; split. by apply/subsetP=> i; rewrite inE. rewrite leq_eqVlt; apply/orP; left; apply/eqP. rewrite -orderE gX_order card_qfpoly -[in RHS](mk_monicE primitive_mi). rewrite -card_qpoly -(cardC1 (0 : {poly %/ h with primitive_mi})). rewrite cardsT card_sub. by apply: eq_card => x; rewrite [LHS]unitfE. Qed. Let pred_card_qT_gt0 : 0 < #|qT|.-1. Proof. by rewrite ltn_predRL card_qfpoly_gt1. Qed. Definition qlogp (p : qT) : nat := odflt (Ordinal pred_card_qT_gt0) (pick [pred i in 'I_ _ | ('qX ^+ i == p)]). Lemma qlogp_lt p : qlogp p < #|qT|.-1. Proof. by rewrite /qlogp; case: pickP. Qed. Lemma qlogp_qX (p : qT) : p != 0 -> 'qX ^+ (qlogp p) = p. Proof. move=> p_neq0. have Up : p \in GRing.unit by rewrite unitfE. pose gp : {unit qT}:= FinRing.unit _ Up. have /cyclePmin[i iLc iX] : gp \in <[gX]>%g by rewrite gX_all inE. rewrite gX_order in iLc. rewrite /qlogp; case: pickP => [j /eqP//|/(_ (Ordinal iLc))] /eqP[]. by have /val_eqP/eqP/= := iX; rewrite FinRing.val_unitX. Qed. Lemma qX_order_card : 'qX ^+ (#|qT|).-1 = 1 :> qT. Proof. have /primitive_polyP [_ Hd _] := Hh. rewrite dvdp_order in Hd. have -> : 1 = val (1%g : {unit qT}) by []. by rewrite -(eqP Hd) val_unitX. Qed. Lemma qX_order_dvd (i : nat) : 'qX ^+ i = 1 :> qT -> (#|qT|.-1 %| i)%N. Proof. rewrite -gX_order cyclic.order_dvdn => Hd. by apply/eqP/val_inj; rewrite /= -Hd val_unitX. Qed. Lemma qlogp0 : qlogp 0 = 0%N. Proof. rewrite /qlogp; case: pickP => //= x. by rewrite (expf_eq0 ('qX : qT)) (negPf qX_neq0) andbF. Qed. Lemma qlogp1 : qlogp 1 = 0%N. Proof. case: (qlogp 1 =P 0%N) => // /eqP log1_neq0. have := qlogp_lt 1; rewrite ltnNge => /negP[]. apply: dvdn_leq; first by rewrite lt0n. by rewrite qX_order_dvd // qlogp_qX ?oner_eq0. Qed. Lemma qlogp_eq0 (q : qT) : (qlogp q == 0%N) = (q == 0) || (q == 1). Proof. case: (q =P 0) => [->|/eqP q_neq0]/=; first by rewrite qlogp0. case: (q =P 1) => [->|/eqP q_neq1]/=; first by rewrite qlogp1. rewrite /qlogp; case: pickP => [x|/(_ (Ordinal (qlogp_lt q)))] /=. by case: ((x : nat) =P 0%N) => // ->; rewrite expr0 eq_sym (negPf q_neq1). by rewrite qlogp_qX // eqxx. Qed. Lemma qX_exp_neq0 i : 'qX ^+ i != 0 :> qT. Proof. by rewrite expf_eq0 negb_and qX_neq0 orbT. Qed. Lemma qX_exp_inj i j : i < #|qT|.-1 -> j < #|qT|.-1 -> 'qX ^+ i = 'qX ^+ j :> qT -> i = j. Proof. wlog iLj : i j / (i <= j)%N => [Hw|] iL jL Hqx. case: (ltngtP i j)=> // /ltnW iLj; first by apply: Hw. by apply/sym_equal/Hw. suff ji_eq0 : (j - i = 0)%N by rewrite -(subnK iLj) ji_eq0. case: ((j - i)%N =P 0%N) => // /eqP ji_neq0. have : j - i < #|qT|.-1 by apply: leq_ltn_trans (leq_subr _ _) jL. rewrite ltnNge => /negP[]. apply: dvdn_leq; first by rewrite lt0n. have HqXi : 'qX ^+ i != 0 :> qT by rewrite expf_eq0 (negPf qX_neq0) andbF. by apply/qX_order_dvd/(mulIf HqXi); rewrite mul1r -exprD subnK. Qed. Lemma powX_eq_mod i j : i = j %[mod #|qT|.-1] -> 'qX ^+ i = 'qX ^+ j :> qT. Proof. set n := _.-1 => iEj. rewrite [i](divn_eq i n) [j](divn_eq j n) !exprD ![(_ * n)%N]mulnC. by rewrite !exprM !qX_order_card !expr1n !mul1r iEj. Qed. Lemma qX_expK i : i < #|qT|.-1 -> qlogp ('qX ^+ i) = i. Proof. move=> iLF; apply: qX_exp_inj => //; first by apply: qlogp_lt. by rewrite qlogp_qX // expf_eq0 (negPf qX_neq0) andbF. Qed. Lemma qlogpD (q1 q2 : qT) : q1 != 0 -> q2 != 0 ->qlogp (q1 * q2) = ((qlogp q1 + qlogp q2) %% #|qT|.-1)%N. Proof. move=> q1_neq0 q2_neq0. apply: qX_exp_inj; [apply: qlogp_lt => // | rewrite ltn_mod // |]. rewrite -[RHS]mul1r -(expr1n _ ((qlogp q1 + qlogp q2) %/ #|qT|.-1)). rewrite -qX_order_card -exprM mulnC -exprD -divn_eq exprD !qlogp_qX //. by rewrite mulf_eq0 negb_or q1_neq0. Qed. End PrimitivePoly. Section Plogp. Variable F : finFieldType. Definition plogp (p q : {poly F}) := if boolP (primitive_poly p) is AltTrue Hh then qlogp ((in_qpoly p q) : {poly %/ p with primitive_mi Hh}) else 0%N. Lemma plogp_lt (p q : {poly F}) : 2 < size p -> plogp p q < #|{poly %/ p}|.-1. Proof. move=> /ltnW size_gt1. rewrite /plogp. case (boolP (primitive_poly p)) => // Hh; first by apply: qlogp_lt. by rewrite ltn_predRL (card_finNzRing_gt1 {poly %/ p}). Qed. Lemma plogp_X (p q : {poly F}) : 2 < size p -> primitive_poly p -> ~~ (p %| q) -> p %| q - 'X ^+ plogp p q. Proof. move=> sp_gt2 Hh pNDq. rewrite /plogp. case (boolP (primitive_poly p)) => // Hh'; last by case/negP: Hh'. have pM : p \is monic by case/and4P: Hh'. have pMi : monic_irreducible_poly p by apply: primitive_mi. set q' : {poly %/ p with primitive_mi Hh'} := in_qpoly p q. apply/modp_eq0P; rewrite modpD modpN; apply/eqP; rewrite subr_eq0; apply/eqP. rewrite !Pdiv.IdomainMonic.modpE //=. suff /val_eqP/eqP/= : 'qX ^+ qlogp q' = q'. rewrite /= [X in rmodp _ X]mk_monicE // => <-. by rewrite poly_of_qpolyX /= mk_monicE // [rmodp 'X p]rmodp_small ?size_polyX. apply: qlogp_qX => //. apply/eqP=> /val_eqP/eqP. rewrite /= mk_monicE // => /rmodp_eq0P; rewrite -dvdpE => pDq. by case/negP: pNDq. Qed. Lemma plogp0 (p : {poly F}) : 2 < size p -> plogp p 0 = 0%N. Proof. move=> sp_gt2; rewrite /plogp; case (boolP (primitive_poly p)) => // i. by rewrite in_qpoly0 qlogp0. Qed. Lemma plogp1 (p : {poly F}) : 2 < size p -> plogp p 1 = 0%N. Proof. move=> sp_gt2; rewrite /plogp; case (boolP (primitive_poly p)) => // i. suff->: in_qpoly p 1 = 1 by apply: qlogp1. apply/val_eqP/eqP; apply: in_qpoly_small. rewrite mk_monicE ?size_poly1 ?(leq_trans _ sp_gt2) //. by apply: primitive_mi. Qed. Lemma plogp_div_eq0 (p q : {poly F}) : 2 < size p -> (p %| q) -> plogp p q = 0%N. Proof. move=> sp_gt2; rewrite /plogp; case (boolP (primitive_poly p)) => // i pDq. suff-> : in_qpoly p q = 0 by apply: qlogp0. by apply/eqP; rewrite primitive_poly_in_qpoly_eq0. Qed. Lemma plogpD (p q1 q2 : {poly F}) : 2 < size p -> primitive_poly p -> ~~ (p %| q1) -> ~~ (p %| q2) -> plogp p (q1 * q2) = ((plogp p q1 + plogp p q2) %% #|{poly %/ p}|.-1)%N. Proof. move=> sp_gt2 Pp pNDq1 pNDq2. rewrite /plogp; case (boolP (primitive_poly p)) => [|/negP//] i /=. have pmi := primitive_mi i. by rewrite rmorphM qlogpD //= primitive_poly_in_qpoly_eq0. Qed. End Plogp.
Complemented.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Normed.Operator.Banach import Mathlib.Topology.Algebra.Module.FiniteDimension /-! # Complemented subspaces of normed vector spaces A submodule `p` of a topological module `E` over `R` is called *complemented* if there exists a continuous linear projection `f : E →ₗ[R] p`, `∀ x : p, f x = x`. We prove that for a closed subspace of a normed space this condition is equivalent to existence of a closed subspace `q` such that `p ⊓ q = ⊥`, `p ⊔ q = ⊤`. We also prove that a subspace of finite codimension is always a complemented subspace. ## Tags complemented subspace, normed vector space -/ variable {𝕜 E F G : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] noncomputable section open LinearMap (ker range) namespace ContinuousLinearMap section variable [CompleteSpace 𝕜] theorem ker_closedComplemented_of_finiteDimensional_range (f : E →L[𝕜] F) [FiniteDimensional 𝕜 (range f)] : (ker f).ClosedComplemented := by set f' : E →L[𝕜] range f := f.codRestrict _ (LinearMap.mem_range_self (f : E →ₗ[𝕜] F)) rcases f'.exists_right_inverse_of_surjective (f : E →ₗ[𝕜] F).range_rangeRestrict with ⟨g, hg⟩ simpa only [f', ker_codRestrict] using f'.closedComplemented_ker_of_rightInverse g (ContinuousLinearMap.ext_iff.1 hg) end variable [CompleteSpace E] [CompleteSpace (F × G)] /-- If `f : E →L[R] F` and `g : E →L[R] G` are two surjective linear maps and their kernels are complement of each other, then `x ↦ (f x, g x)` defines a linear equivalence `E ≃L[R] F × G`. -/ nonrec def equivProdOfSurjectiveOfIsCompl (f : E →L[𝕜] F) (g : E →L[𝕜] G) (hf : range f = ⊤) (hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) : E ≃L[𝕜] F × G := (f.equivProdOfSurjectiveOfIsCompl (g : E →ₗ[𝕜] G) hf hg hfg).toContinuousLinearEquivOfContinuous (f.continuous.prodMk g.continuous) @[simp] theorem coe_equivProdOfSurjectiveOfIsCompl {f : E →L[𝕜] F} {g : E →L[𝕜] G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) : (equivProdOfSurjectiveOfIsCompl f g hf hg hfg : E →ₗ[𝕜] F × G) = f.prod g := rfl @[simp] theorem equivProdOfSurjectiveOfIsCompl_toLinearEquiv {f : E →L[𝕜] F} {g : E →L[𝕜] G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) : (equivProdOfSurjectiveOfIsCompl f g hf hg hfg).toLinearEquiv = LinearMap.equivProdOfSurjectiveOfIsCompl f g hf hg hfg := rfl @[simp] theorem equivProdOfSurjectiveOfIsCompl_apply {f : E →L[𝕜] F} {g : E →L[𝕜] G} (hf : range f = ⊤) (hg : range g = ⊤) (hfg : IsCompl (ker f) (ker g)) (x : E) : equivProdOfSurjectiveOfIsCompl f g hf hg hfg x = (f x, g x) := rfl end ContinuousLinearMap namespace Submodule variable [CompleteSpace E] (p q : Subspace 𝕜 E) /-- If `q` is a closed complement of a closed subspace `p`, then `p × q` is continuously isomorphic to `E`. -/ def prodEquivOfClosedCompl (h : IsCompl p q) (hp : IsClosed (p : Set E)) (hq : IsClosed (q : Set E)) : (p × q) ≃L[𝕜] E := by haveI := hp.completeSpace_coe; haveI := hq.completeSpace_coe refine (p.prodEquivOfIsCompl q h).toContinuousLinearEquivOfContinuous ?_ exact (p.subtypeL.coprod q.subtypeL).continuous /-- Projection to a closed submodule along a closed complement. -/ def linearProjOfClosedCompl (h : IsCompl p q) (hp : IsClosed (p : Set E)) (hq : IsClosed (q : Set E)) : E →L[𝕜] p := ContinuousLinearMap.fst 𝕜 p q ∘L ↑(prodEquivOfClosedCompl p q h hp hq).symm variable {p q} @[simp] theorem coe_prodEquivOfClosedCompl (h : IsCompl p q) (hp : IsClosed (p : Set E)) (hq : IsClosed (q : Set E)) : ⇑(p.prodEquivOfClosedCompl q h hp hq) = p.prodEquivOfIsCompl q h := rfl @[simp] theorem coe_prodEquivOfClosedCompl_symm (h : IsCompl p q) (hp : IsClosed (p : Set E)) (hq : IsClosed (q : Set E)) : ⇑(p.prodEquivOfClosedCompl q h hp hq).symm = (p.prodEquivOfIsCompl q h).symm := rfl @[simp] theorem coe_continuous_linearProjOfClosedCompl (h : IsCompl p q) (hp : IsClosed (p : Set E)) (hq : IsClosed (q : Set E)) : (p.linearProjOfClosedCompl q h hp hq : E →ₗ[𝕜] p) = p.linearProjOfIsCompl q h := rfl @[simp] theorem coe_continuous_linearProjOfClosedCompl' (h : IsCompl p q) (hp : IsClosed (p : Set E)) (hq : IsClosed (q : Set E)) : ⇑(p.linearProjOfClosedCompl q h hp hq) = p.linearProjOfIsCompl q h := rfl theorem ClosedComplemented.of_isCompl_isClosed (h : IsCompl p q) (hp : IsClosed (p : Set E)) (hq : IsClosed (q : Set E)) : p.ClosedComplemented := ⟨p.linearProjOfClosedCompl q h hp hq, Submodule.linearProjOfIsCompl_apply_left h⟩ alias IsCompl.closedComplemented_of_isClosed := ClosedComplemented.of_isCompl_isClosed theorem closedComplemented_iff_isClosed_exists_isClosed_isCompl : p.ClosedComplemented ↔ IsClosed (p : Set E) ∧ ∃ q : Submodule 𝕜 E, IsClosed (q : Set E) ∧ IsCompl p q := ⟨fun h => ⟨h.isClosed, h.exists_isClosed_isCompl⟩, fun ⟨hp, ⟨_, hq, hpq⟩⟩ => .of_isCompl_isClosed hpq hp hq⟩ theorem ClosedComplemented.of_quotient_finiteDimensional [CompleteSpace 𝕜] [FiniteDimensional 𝕜 (E ⧸ p)] (hp : IsClosed (p : Set E)) : p.ClosedComplemented := by obtain ⟨q, hq⟩ : ∃ q, IsCompl p q := p.exists_isCompl haveI : FiniteDimensional 𝕜 q := (p.quotientEquivOfIsCompl q hq).finiteDimensional exact .of_isCompl_isClosed hq hp q.closed_of_finiteDimensional end Submodule
Composition.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johan Commelin -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Combinatorics.Enumerative.Composition /-! # Composition of analytic functions In this file we prove that the composition of analytic functions is analytic. The argument is the following. Assume `g z = ∑' qₙ (z, ..., z)` and `f y = ∑' pₖ (y, ..., y)`. Then `g (f y) = ∑' qₙ (∑' pₖ (y, ..., y), ..., ∑' pₖ (y, ..., y)) = ∑' qₙ (p_{i₁} (y, ..., y), ..., p_{iₙ} (y, ..., y))`. For each `n` and `i₁, ..., iₙ`, define a `i₁ + ... + iₙ` multilinear function mapping `(y₀, ..., y_{i₁ + ... + iₙ - 1})` to `qₙ (p_{i₁} (y₀, ..., y_{i₁-1}), p_{i₂} (y_{i₁}, ..., y_{i₁ + i₂ - 1}), ..., p_{iₙ} (....)))`. Then `g ∘ f` is obtained by summing all these multilinear functions. To formalize this, we use compositions of an integer `N`, i.e., its decompositions into a sum `i₁ + ... + iₙ` of positive integers. Given such a composition `c` and two formal multilinear series `q` and `p`, let `q.compAlongComposition p c` be the above multilinear function. Then the `N`-th coefficient in the power series expansion of `g ∘ f` is the sum of these terms over all `c : Composition N`. To complete the proof, we need to show that this power series has a positive radius of convergence. This follows from the fact that `Composition N` has cardinality `2^(N-1)` and estimates on the norm of `qₙ` and `pₖ`, which give summability. We also need to show that it indeed converges to `g ∘ f`. For this, we note that the composition of partial sums converges to `g ∘ f`, and that it corresponds to a part of the whole sum, on a subset that increases to the whole space. By summability of the norms, this implies the overall convergence. ## Main results * `q.comp p` is the formal composition of the formal multilinear series `q` and `p`. * `HasFPowerSeriesAt.comp` states that if two functions `g` and `f` admit power series expansions `q` and `p`, then `g ∘ f` admits a power series expansion given by `q.comp p`. * `AnalyticAt.comp` states that the composition of analytic functions is analytic. * `FormalMultilinearSeries.comp_assoc` states that composition is associative on formal multilinear series. ## Implementation details The main technical difficulty is to write down things. In particular, we need to define precisely `q.compAlongComposition p c` and to show that it is indeed a continuous multilinear function. This requires a whole interface built on the class `Composition`. Once this is set, the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum over some subset of `Σ n, Composition n`. We need to check that the reordering is a bijection, running over difficulties due to the dependent nature of the types under consideration, that are controlled thanks to the interface for `Composition`. The associativity of composition on formal multilinear series is a nontrivial result: it does not follow from the associativity of composition of analytic functions, as there is no uniqueness for the formal multilinear series representing a function (and also, it holds even when the radius of convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering double sums in a careful way. The change of variables is a canonical (combinatorial) bijection `Composition.sigmaEquivSigmaPi` between `(Σ (a : Composition n), Composition a.length)` and `(Σ (c : Composition n), Π (i : Fin c.length), Composition (c.blocksFun i))`, and is described in more details below in the paragraph on associativity. -/ noncomputable section variable {𝕜 : Type*} {E F G H : Type*} open Filter List open scoped Topology NNReal ENNReal section Topological variable [CommRing 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] variable [Module 𝕜 E] [Module 𝕜 F] [Module 𝕜 G] variable [TopologicalSpace E] [TopologicalSpace F] [TopologicalSpace G] /-! ### Composing formal multilinear series -/ namespace FormalMultilinearSeries variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] variable [IsTopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] /-! In this paragraph, we define the composition of formal multilinear series, by summing over all possible compositions of `n`. -/ /-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a block of `c`, we may define a function on `Fin n → E` by picking the variables in the `i`-th block of `n`, and applying the corresponding coefficient of `p` to these variables. This function is called `p.applyComposition c v i` for `v : Fin n → E` and `i : Fin c.length`. -/ def applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) : (Fin n → E) → Fin c.length → F := fun v i => p (c.blocksFun i) (v ∘ c.embedding i) theorem applyComposition_ones (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : p.applyComposition (Composition.ones n) = fun v i => p 1 fun _ => v (Fin.castLE (Composition.length_le _) i) := by funext v i apply p.congr (Composition.ones_blocksFun _ _) intro j hjn hj1 obtain rfl : j = 0 := by omega refine congr_arg v ?_ rw [Fin.ext_iff, Fin.coe_castLE, Composition.ones_embedding, Fin.val_mk] theorem applyComposition_single (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n) (v : Fin n → E) : p.applyComposition (Composition.single n hn) v = fun _j => p n v := by ext j refine p.congr (by simp) fun i hi1 hi2 => ?_ dsimp congr 1 convert Composition.single_embedding hn ⟨i, hi2⟩ using 1 obtain ⟨j_val, j_property⟩ := j have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property) congr! simp @[simp] theorem removeZero_applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) : p.removeZero.applyComposition c = p.applyComposition c := by ext v i simp [applyComposition, zero_lt_one.trans_le (c.one_le_blocksFun i), removeZero_of_pos] /-- Technical lemma stating how `p.applyComposition` commutes with updating variables. This will be the key point to show that functions constructed from `applyComposition` retain multilinearity. -/ theorem applyComposition_update (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) (j : Fin n) (v : Fin n → E) (z : E) : p.applyComposition c (Function.update v j z) = Function.update (p.applyComposition c v) (c.index j) (p (c.blocksFun (c.index j)) (Function.update (v ∘ c.embedding (c.index j)) (c.invEmbedding j) z)) := by ext k by_cases h : k = c.index j · rw [h] let r : Fin (c.blocksFun (c.index j)) → Fin n := c.embedding (c.index j) simp only [Function.update_self] change p (c.blocksFun (c.index j)) (Function.update v j z ∘ r) = _ let j' := c.invEmbedding j suffices B : Function.update v j z ∘ r = Function.update (v ∘ r) j' z by rw [B] suffices C : Function.update v (r j') z ∘ r = Function.update (v ∘ r) j' z by convert C; exact (c.embedding_comp_inv j).symm exact Function.update_comp_eq_of_injective _ (c.embedding _).injective _ _ · simp only [h, Function.update_of_ne, Ne, not_false_iff] let r : Fin (c.blocksFun k) → Fin n := c.embedding k change p (c.blocksFun k) (Function.update v j z ∘ r) = p (c.blocksFun k) (v ∘ r) suffices B : Function.update v j z ∘ r = v ∘ r by rw [B] apply Function.update_comp_eq_of_notMem_range rwa [c.mem_range_embedding_iff'] @[simp] theorem compContinuousLinearMap_applyComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 F G) (f : E →L[𝕜] F) (c : Composition n) (v : Fin n → E) : (p.compContinuousLinearMap f).applyComposition c v = p.applyComposition c (f ∘ v) := by ext simp [applyComposition, Function.comp_def] end FormalMultilinearSeries namespace ContinuousMultilinearMap open FormalMultilinearSeries variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] /-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear map `f` in `c.length` variables, one may form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each block of the composition, and then applying `f` to the resulting vector. It is called `f.compAlongComposition p c`. -/ def compAlongComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (f : F [×c.length]→L[𝕜] G) : E [×n]→L[𝕜] G where toMultilinearMap := MultilinearMap.mk' (fun v ↦ f (p.applyComposition c v)) (fun v i x y ↦ by simp only [applyComposition_update, map_update_add]) (fun v i c x ↦ by simp only [applyComposition_update, map_update_smul]) cont := f.cont.comp <| continuous_pi fun _ => (coe_continuous _).comp <| continuous_pi fun _ => continuous_apply _ @[simp] theorem compAlongComposition_apply {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (f : F [×c.length]→L[𝕜] G) (v : Fin n → E) : (f.compAlongComposition p c) v = f (p.applyComposition c v) := rfl end ContinuousMultilinearMap namespace FormalMultilinearSeries variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] variable [IsTopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] /-- Given two formal multilinear series `q` and `p` and a composition `c` of `n`, one may form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each block of the composition, and then applying `q c.length` to the resulting vector. It is called `q.compAlongComposition p c`. -/ def compAlongComposition {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : (E [×n]→L[𝕜] G) := (q c.length).compAlongComposition p c @[simp] theorem compAlongComposition_apply {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (v : Fin n → E) : (q.compAlongComposition p c) v = q c.length (p.applyComposition c v) := rfl /-- Formal composition of two formal multilinear series. The `n`-th coefficient in the composition is defined to be the sum of `q.compAlongComposition p c` over all compositions of `n`. In other words, this term (as a multilinear function applied to `v_0, ..., v_{n-1}`) is `∑'_{k} ∑'_{i₁ + ... + iₖ = n} qₖ (p_{i_1} (...), ..., p_{i_k} (...))`, where one puts all variables `v_0, ..., v_{n-1}` in increasing order in the dots. In general, the composition `q ∘ p` only makes sense when the constant coefficient of `p` vanishes. We give a general formula but which ignores the value of `p 0` instead. -/ protected def comp (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) : FormalMultilinearSeries 𝕜 E G := fun n => ∑ c : Composition n, q.compAlongComposition p c /-- The `0`-th coefficient of `q.comp p` is `q 0`. Since these maps are multilinear maps in zero variables, but on different spaces, we can not state this directly, so we state it when applied to arbitrary vectors (which have to be the zero vector). -/ theorem comp_coeff_zero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (v : Fin 0 → E) (v' : Fin 0 → F) : (q.comp p) 0 v = q 0 v' := by let c : Composition 0 := Composition.ones 0 dsimp [FormalMultilinearSeries.comp] have : {c} = (Finset.univ : Finset (Composition 0)) := by apply Finset.eq_of_subset_of_card_le <;> simp [Finset.card_univ, composition_card 0] rw [← this, Finset.sum_singleton, compAlongComposition_apply] symm; congr! -- Porting note: needed the stronger `congr!`! @[simp] theorem comp_coeff_zero' (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (v : Fin 0 → E) : (q.comp p) 0 v = q 0 fun _i => 0 := q.comp_coeff_zero p v _ /-- The `0`-th coefficient of `q.comp p` is `q 0`. When `p` goes from `E` to `E`, this can be expressed as a direct equality -/ theorem comp_coeff_zero'' (q : FormalMultilinearSeries 𝕜 E F) (p : FormalMultilinearSeries 𝕜 E E) : (q.comp p) 0 = q 0 := by ext v; exact q.comp_coeff_zero p _ _ /-- The first coefficient of a composition of formal multilinear series is the composition of the first coefficients seen as continuous linear maps. -/ theorem comp_coeff_one (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (v : Fin 1 → E) : (q.comp p) 1 v = q 1 fun _i => p 1 v := by have : {Composition.ones 1} = (Finset.univ : Finset (Composition 1)) := Finset.eq_univ_of_card _ (by simp [composition_card]) simp only [FormalMultilinearSeries.comp, compAlongComposition_apply, ← this, Finset.sum_singleton] refine q.congr (by simp) fun i hi1 hi2 => ?_ simp only [applyComposition_ones] exact p.congr rfl fun j _hj1 hj2 => by congr! -- Porting note: needed the stronger `congr!` /-- Only `0`-th coefficient of `q.comp p` depends on `q 0`. -/ theorem removeZero_comp_of_pos (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n) : q.removeZero.comp p n = q.comp p n := by ext v simp only [FormalMultilinearSeries.comp, compAlongComposition, ContinuousMultilinearMap.compAlongComposition_apply, ContinuousMultilinearMap.sum_apply] refine Finset.sum_congr rfl fun c _hc => ?_ rw [removeZero_of_pos _ (c.length_pos_of_pos hn)] @[simp] theorem comp_removeZero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) : q.comp p.removeZero = q.comp p := by ext n; simp [FormalMultilinearSeries.comp] end FormalMultilinearSeries end Topological variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup H] [NormedSpace 𝕜 H] namespace FormalMultilinearSeries /-- The norm of `f.compAlongComposition p c` is controlled by the product of the norms of the relevant bits of `f` and `p`. -/ theorem compAlongComposition_bound {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (f : F [×c.length]→L[𝕜] G) (v : Fin n → E) : ‖f.compAlongComposition p c v‖ ≤ (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ := calc ‖f.compAlongComposition p c v‖ = ‖f (p.applyComposition c v)‖ := rfl _ ≤ ‖f‖ * ∏ i, ‖p.applyComposition c v i‖ := ContinuousMultilinearMap.le_opNorm _ _ _ ≤ ‖f‖ * ∏ i, ‖p (c.blocksFun i)‖ * ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by gcongr with i apply ContinuousMultilinearMap.le_opNorm _ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i, ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by rw [Finset.prod_mul_distrib, mul_assoc] _ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ := by rw [← c.blocksFinEquiv.prod_comp, ← Finset.univ_sigma_univ, Finset.prod_sigma] congr /-- The norm of `q.compAlongComposition p c` is controlled by the product of the norms of the relevant bits of `q` and `p`. -/ theorem compAlongComposition_norm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : ‖q.compAlongComposition p c‖ ≤ ‖q c.length‖ * ∏ i, ‖p (c.blocksFun i)‖ := ContinuousMultilinearMap.opNorm_le_bound (by positivity) (compAlongComposition_bound _ _ _) theorem compAlongComposition_nnnorm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : ‖q.compAlongComposition p c‖₊ ≤ ‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊ := by rw [← NNReal.coe_le_coe]; push_cast; exact q.compAlongComposition_norm p c /-! ### The identity formal power series We will now define the identity power series, and show that it is a neutral element for left and right composition. -/ section variable (𝕜 E) /-- The identity formal multilinear series, with all coefficients equal to `0` except for `n = 1` where it is (the continuous multilinear version of) the identity. We allow an arbitrary constant coefficient `x`. -/ def id (x : E) : FormalMultilinearSeries 𝕜 E E | 0 => ContinuousMultilinearMap.uncurry0 𝕜 _ x | 1 => (continuousMultilinearCurryFin1 𝕜 E E).symm (ContinuousLinearMap.id 𝕜 E) | _ => 0 @[simp] theorem id_apply_zero (x : E) (v : Fin 0 → E) : (FormalMultilinearSeries.id 𝕜 E x) 0 v = x := rfl /-- The first coefficient of `id 𝕜 E` is the identity. -/ @[simp] theorem id_apply_one (x : E) (v : Fin 1 → E) : (FormalMultilinearSeries.id 𝕜 E x) 1 v = v 0 := rfl /-- The `n`th coefficient of `id 𝕜 E` is the identity when `n = 1`. We state this in a dependent way, as it will often appear in this form. -/ theorem id_apply_one' (x : E) {n : ℕ} (h : n = 1) (v : Fin n → E) : (id 𝕜 E x) n v = v ⟨0, h.symm ▸ zero_lt_one⟩ := by subst n apply id_apply_one /-- For `n ≠ 1`, the `n`-th coefficient of `id 𝕜 E` is zero, by definition. -/ @[simp] theorem id_apply_of_one_lt (x : E) {n : ℕ} (h : 1 < n) : (FormalMultilinearSeries.id 𝕜 E x) n = 0 := by match n with | 0 => contradiction | 1 => contradiction | n + 2 => rfl end @[simp] theorem comp_id (p : FormalMultilinearSeries 𝕜 E F) (x : E) : p.comp (id 𝕜 E x) = p := by ext1 n dsimp [FormalMultilinearSeries.comp] rw [Finset.sum_eq_single (Composition.ones n)] · show compAlongComposition p (id 𝕜 E x) (Composition.ones n) = p n ext v rw [compAlongComposition_apply] apply p.congr (Composition.ones_length n) intros rw [applyComposition_ones] refine congr_arg v ?_ rw [Fin.ext_iff, Fin.coe_castLE, Fin.val_mk] · change ∀ b : Composition n, b ∈ Finset.univ → b ≠ Composition.ones n → compAlongComposition p (id 𝕜 E x) b = 0 intro b _ hb obtain ⟨k, hk, lt_k⟩ : ∃ (k : ℕ), k ∈ Composition.blocks b ∧ 1 < k := Composition.ne_ones_iff.1 hb obtain ⟨i, hi⟩ : ∃ (i : Fin b.blocks.length), b.blocks[i] = k := List.get_of_mem hk let j : Fin b.length := ⟨i.val, b.blocks_length ▸ i.prop⟩ have A : 1 < b.blocksFun j := by convert lt_k ext v rw [compAlongComposition_apply, ContinuousMultilinearMap.zero_apply] apply ContinuousMultilinearMap.map_coord_zero _ j dsimp [applyComposition] rw [id_apply_of_one_lt _ _ _ A, ContinuousMultilinearMap.zero_apply] · simp @[simp] theorem id_comp (p : FormalMultilinearSeries 𝕜 E F) (v0 : Fin 0 → E) : (id 𝕜 F (p 0 v0)).comp p = p := by ext1 n obtain rfl | n_pos := n.eq_zero_or_pos · ext v simp only [comp_coeff_zero', id_apply_zero] congr with i exact i.elim0 · dsimp [FormalMultilinearSeries.comp] rw [Finset.sum_eq_single (Composition.single n n_pos)] · show compAlongComposition (id 𝕜 F (p 0 v0)) p (Composition.single n n_pos) = p n ext v rw [compAlongComposition_apply, id_apply_one' _ _ _ (Composition.single_length n_pos)] dsimp [applyComposition] refine p.congr rfl fun i him hin => congr_arg v <| ?_ ext; simp · change ∀ b : Composition n, b ∈ Finset.univ → b ≠ Composition.single n n_pos → compAlongComposition (id 𝕜 F (p 0 v0)) p b = 0 intro b _ hb have A : 1 < b.length := by have : b.length ≠ 1 := by simpa [Composition.eq_single_iff_length] using hb have : 0 < b.length := Composition.length_pos_of_pos b n_pos omega ext v rw [compAlongComposition_apply, id_apply_of_one_lt _ _ _ A, ContinuousMultilinearMap.zero_apply, ContinuousMultilinearMap.zero_apply] · simp /-- Variant of `id_comp` in which the zero coefficient is given by an equality hypothesis instead of a definitional equality. Useful for rewriting or simplifying out in some situations. -/ theorem id_comp' (p : FormalMultilinearSeries 𝕜 E F) (x : F) (v0 : Fin 0 → E) (h : x = p 0 v0) : (id 𝕜 F x).comp p = p := by simp [h] /-! ### Summability properties of the composition of formal power series -/ section /-- If two formal multilinear series have positive radius of convergence, then the terms appearing in the definition of their composition are also summable (when multiplied by a suitable positive geometric term). -/ theorem comp_summable_nnreal (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (hq : 0 < q.radius) (hp : 0 < p.radius) : ∃ r > (0 : ℝ≥0), Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 := by /- This follows from the fact that the growth rate of `‖qₙ‖` and `‖pₙ‖` is at most geometric, giving a geometric bound on each `‖q.compAlongComposition p op‖`, together with the fact that there are `2^(n-1)` compositions of `n`, giving at most a geometric loss. -/ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hq) with ⟨rq, rq_pos, hrq⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hp) with ⟨rp, rp_pos, hrp⟩ simp only [lt_min_iff, ENNReal.coe_lt_one_iff, ENNReal.coe_pos] at hrp hrq rp_pos rq_pos obtain ⟨Cq, _hCq0, hCq⟩ : ∃ Cq > 0, ∀ n, ‖q n‖₊ * rq ^ n ≤ Cq := q.nnnorm_mul_pow_le_of_lt_radius hrq.2 obtain ⟨Cp, hCp1, hCp⟩ : ∃ Cp ≥ 1, ∀ n, ‖p n‖₊ * rp ^ n ≤ Cp := by rcases p.nnnorm_mul_pow_le_of_lt_radius hrp.2 with ⟨Cp, -, hCp⟩ exact ⟨max Cp 1, le_max_right _ _, fun n => (hCp n).trans (le_max_left _ _)⟩ let r0 : ℝ≥0 := (4 * Cp)⁻¹ have r0_pos : 0 < r0 := inv_pos.2 (mul_pos zero_lt_four (zero_lt_one.trans_le hCp1)) set r : ℝ≥0 := rp * rq * r0 have r_pos : 0 < r := mul_pos (mul_pos rp_pos rq_pos) r0_pos have I : ∀ i : Σ n : ℕ, Composition n, ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 ≤ Cq / 4 ^ i.1 := by rintro ⟨n, c⟩ have A := calc ‖q c.length‖₊ * rq ^ n ≤ ‖q c.length‖₊ * rq ^ c.length := mul_le_mul' le_rfl (pow_le_pow_of_le_one rq.2 hrq.1.le c.length_le) _ ≤ Cq := hCq _ have B := calc (∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n = ∏ i, ‖p (c.blocksFun i)‖₊ * rp ^ c.blocksFun i := by simp only [Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum, c.sum_blocksFun] _ ≤ ∏ _i : Fin c.length, Cp := Finset.prod_le_prod' fun i _ => hCp _ _ = Cp ^ c.length := by simp _ ≤ Cp ^ n := pow_right_mono₀ hCp1 c.length_le calc ‖q.compAlongComposition p c‖₊ * r ^ n ≤ (‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊) * r ^ n := mul_le_mul' (q.compAlongComposition_nnnorm p c) le_rfl _ = ‖q c.length‖₊ * rq ^ n * ((∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n) * r0 ^ n := by ring _ ≤ Cq * Cp ^ n * r0 ^ n := mul_le_mul' (mul_le_mul' A B) le_rfl _ = Cq / 4 ^ n := by simp only [r0] field_simp [mul_pow, (zero_lt_one.trans_le hCp1).ne'] ring refine ⟨r, r_pos, NNReal.summable_of_le I ?_⟩ simp_rw [div_eq_mul_inv] refine Summable.mul_left _ ?_ have : ∀ n : ℕ, HasSum (fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹) (2 ^ (n - 1) / 4 ^ n) := by intro n convert hasSum_fintype fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹ simp [Finset.card_univ, composition_card, div_eq_mul_inv] refine NNReal.summable_sigma.2 ⟨fun n => (this n).summable, (NNReal.summable_nat_add_iff 1).1 ?_⟩ convert (NNReal.summable_geometric (NNReal.div_lt_one_of_lt one_lt_two)).mul_left (1 / 4) using 1 ext1 n rw [(this _).tsum_eq, add_tsub_cancel_right] field_simp [← mul_assoc, pow_succ, mul_pow, show (4 : ℝ≥0) = 2 * 2 by norm_num, mul_right_comm] end /-- Bounding below the radius of the composition of two formal multilinear series assuming summability over all compositions. -/ theorem le_comp_radius_of_summable (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (r : ℝ≥0) (hr : Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1) : (r : ℝ≥0∞) ≤ (q.comp p).radius := by refine le_radius_of_bound_nnreal _ (∑' i : Σ n, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst) fun n => ?_ calc ‖FormalMultilinearSeries.comp q p n‖₊ * r ^ n ≤ ∑' c : Composition n, ‖compAlongComposition q p c‖₊ * r ^ n := by rw [tsum_fintype, ← Finset.sum_mul] exact mul_le_mul' (nnnorm_sum_le _ _) le_rfl _ ≤ ∑' i : Σ n : ℕ, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst := NNReal.tsum_comp_le_tsum_of_inj hr sigma_mk_injective /-! ### Composing analytic functions Now, we will prove that the composition of the partial sums of `q` and `p` up to order `N` is given by a sum over some large subset of `Σ n, Composition n` of `q.compAlongComposition p`, to deduce that the series for `q.comp p` indeed converges to `g ∘ f` when `q` is a power series for `g` and `p` is a power series for `f`. This proof is a big reindexing argument of a sum. Since it is a bit involved, we define first the source of the change of variables (`compPartialSumSource`), its target (`compPartialSumTarget`) and the change of variables itself (`compChangeOfVariables`) before giving the main statement in `comp_partialSum`. -/ /-- Source set in the change of variables to compute the composition of partial sums of formal power series. See also `comp_partialSum`. -/ def compPartialSumSource (m M N : ℕ) : Finset (Σ n, Fin n → ℕ) := Finset.sigma (Finset.Ico m M) (fun n : ℕ => Fintype.piFinset fun _i : Fin n => Finset.Ico 1 N :) @[simp] theorem mem_compPartialSumSource_iff (m M N : ℕ) (i : Σ n, Fin n → ℕ) : i ∈ compPartialSumSource m M N ↔ (m ≤ i.1 ∧ i.1 < M) ∧ ∀ a : Fin i.1, 1 ≤ i.2 a ∧ i.2 a < N := by simp only [compPartialSumSource, Finset.mem_Ico, Fintype.mem_piFinset, Finset.mem_sigma] /-- Change of variables appearing to compute the composition of partial sums of formal power series -/ def compChangeOfVariables (m M N : ℕ) (i : Σ n, Fin n → ℕ) (hi : i ∈ compPartialSumSource m M N) : Σ n, Composition n := by rcases i with ⟨n, f⟩ rw [mem_compPartialSumSource_iff] at hi refine ⟨∑ j, f j, ofFn fun a => f a, fun {i} hi' => ?_, by simp [sum_ofFn]⟩ obtain ⟨j, rfl⟩ : ∃ j : Fin n, f j = i := by rwa [mem_ofFn', Set.mem_range] at hi' exact (hi.2 j).1 @[simp] theorem compChangeOfVariables_length (m M N : ℕ) {i : Σ n, Fin n → ℕ} (hi : i ∈ compPartialSumSource m M N) : Composition.length (compChangeOfVariables m M N i hi).2 = i.1 := by rcases i with ⟨k, blocks_fun⟩ dsimp [compChangeOfVariables] simp only [Composition.length, length_ofFn] theorem compChangeOfVariables_blocksFun (m M N : ℕ) {i : Σ n, Fin n → ℕ} (hi : i ∈ compPartialSumSource m M N) (j : Fin i.1) : (compChangeOfVariables m M N i hi).2.blocksFun ⟨j, (compChangeOfVariables_length m M N hi).symm ▸ j.2⟩ = i.2 j := by rcases i with ⟨n, f⟩ dsimp [Composition.blocksFun, Composition.blocks, compChangeOfVariables] simp only [List.getElem_ofFn] /-- Target set in the change of variables to compute the composition of partial sums of formal power series, here given a a set. -/ def compPartialSumTargetSet (m M N : ℕ) : Set (Σ n, Composition n) := {i | m ≤ i.2.length ∧ i.2.length < M ∧ ∀ j : Fin i.2.length, i.2.blocksFun j < N} theorem compPartialSumTargetSet_image_compPartialSumSource (m M N : ℕ) (i : Σ n, Composition n) (hi : i ∈ compPartialSumTargetSet m M N) : ∃ (j : _) (hj : j ∈ compPartialSumSource m M N), compChangeOfVariables m M N j hj = i := by rcases i with ⟨n, c⟩ refine ⟨⟨c.length, c.blocksFun⟩, ?_, ?_⟩ · simp only [compPartialSumTargetSet, Set.mem_setOf_eq] at hi simp only [mem_compPartialSumSource_iff, hi.left, hi.right, true_and, and_true] exact fun a => c.one_le_blocks' _ · dsimp [compChangeOfVariables] rw [Composition.sigma_eq_iff_blocks_eq] simp only [Composition.blocksFun] conv_rhs => rw [← List.ofFn_get c.blocks] /-- Target set in the change of variables to compute the composition of partial sums of formal power series, here given a a finset. See also `comp_partialSum`. -/ def compPartialSumTarget (m M N : ℕ) : Finset (Σ n, Composition n) := Set.Finite.toFinset <| ((Finset.finite_toSet _).dependent_image _).subset <| compPartialSumTargetSet_image_compPartialSumSource m M N @[simp] theorem mem_compPartialSumTarget_iff {m M N : ℕ} {a : Σ n, Composition n} : a ∈ compPartialSumTarget m M N ↔ m ≤ a.2.length ∧ a.2.length < M ∧ ∀ j : Fin a.2.length, a.2.blocksFun j < N := by simp [compPartialSumTarget, compPartialSumTargetSet] /-- `compChangeOfVariables m M N` is a bijection between `compPartialSumSource m M N` and `compPartialSumTarget m M N`, yielding equal sums for functions that correspond to each other under the bijection. As `compChangeOfVariables m M N` is a dependent function, stating that it is a bijection is not directly possible, but the consequence on sums can be stated more easily. -/ theorem compChangeOfVariables_sum {α : Type*} [AddCommMonoid α] (m M N : ℕ) (f : (Σ n : ℕ, Fin n → ℕ) → α) (g : (Σ n, Composition n) → α) (h : ∀ (e) (he : e ∈ compPartialSumSource m M N), f e = g (compChangeOfVariables m M N e he)) : ∑ e ∈ compPartialSumSource m M N, f e = ∑ e ∈ compPartialSumTarget m M N, g e := by apply Finset.sum_bij (compChangeOfVariables m M N) -- We should show that the correspondence we have set up is indeed a bijection -- between the index sets of the two sums. -- 1 - show that the image belongs to `compPartialSumTarget m N N` · rintro ⟨k, blocks_fun⟩ H rw [mem_compPartialSumSource_iff] at H simp only [mem_compPartialSumTarget_iff, Composition.length, H.left, length_ofFn, true_and, compChangeOfVariables] intro j simp only [Composition.blocksFun, (H.right _).right, List.get_ofFn] -- 2 - show that the map is injective · rintro ⟨k, blocks_fun⟩ H ⟨k', blocks_fun'⟩ H' heq obtain rfl : k = k' := by have := (compChangeOfVariables_length m M N H).symm rwa [heq, compChangeOfVariables_length] at this congr funext i calc blocks_fun i = (compChangeOfVariables m M N _ H).2.blocksFun _ := (compChangeOfVariables_blocksFun m M N H i).symm _ = (compChangeOfVariables m M N _ H').2.blocksFun _ := by grind _ = blocks_fun' i := compChangeOfVariables_blocksFun m M N H' i -- 3 - show that the map is surjective · intro i hi apply compPartialSumTargetSet_image_compPartialSumSource m M N i simpa [compPartialSumTarget] using hi -- 4 - show that the composition gives the `compAlongComposition` application · assumption /-- The auxiliary set corresponding to the composition of partial sums asymptotically contains all possible compositions. -/ theorem compPartialSumTarget_tendsto_prod_atTop : Tendsto (fun (p : ℕ × ℕ) => compPartialSumTarget 0 p.1 p.2) atTop atTop := by apply Monotone.tendsto_atTop_finset · intro m n hmn a ha have : ∀ i, i < m.1 → i < n.1 := fun i hi => lt_of_lt_of_le hi hmn.1 have : ∀ i, i < m.2 → i < n.2 := fun i hi => lt_of_lt_of_le hi hmn.2 aesop · rintro ⟨n, c⟩ simp only [mem_compPartialSumTarget_iff] obtain ⟨n, hn⟩ : BddAbove ((Finset.univ.image fun i : Fin c.length => c.blocksFun i) : Set ℕ) := Finset.bddAbove _ refine ⟨max n c.length + 1, bot_le, lt_of_le_of_lt (le_max_right n c.length) (lt_add_one _), fun j => lt_of_le_of_lt (le_trans ?_ (le_max_left _ _)) (lt_add_one _)⟩ apply hn simp only [Finset.mem_image_of_mem, Finset.mem_coe, Finset.mem_univ] /-- The auxiliary set corresponding to the composition of partial sums asymptotically contains all possible compositions. -/ theorem compPartialSumTarget_tendsto_atTop : Tendsto (fun N => compPartialSumTarget 0 N N) atTop atTop := by apply Tendsto.comp compPartialSumTarget_tendsto_prod_atTop tendsto_atTop_diagonal /-- Composing the partial sums of two multilinear series coincides with the sum over all compositions in `compPartialSumTarget 0 N N`. This is precisely the motivation for the definition of `compPartialSumTarget`. -/ theorem comp_partialSum (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) (M N : ℕ) (z : E) : q.partialSum M (∑ i ∈ Finset.Ico 1 N, p i fun _j => z) = ∑ i ∈ compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z := by -- we expand the composition, using the multilinearity of `q` to expand along each coordinate. suffices H : (∑ n ∈ Finset.range M, ∑ r ∈ Fintype.piFinset fun i : Fin n => Finset.Ico 1 N, q n fun i : Fin n => p (r i) fun _j => z) = ∑ i ∈ compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z by simpa only [FormalMultilinearSeries.partialSum, ContinuousMultilinearMap.map_sum_finset] using H -- rewrite the first sum as a big sum over a sigma type, in the finset -- `compPartialSumTarget 0 N N` rw [Finset.range_eq_Ico, Finset.sum_sigma'] -- use `compChangeOfVariables_sum`, saying that this change of variables respects sums apply compChangeOfVariables_sum 0 M N rintro ⟨k, blocks_fun⟩ H apply congr _ (compChangeOfVariables_length 0 M N H).symm intros rw [← compChangeOfVariables_blocksFun 0 M N H, applyComposition, Function.comp_def] end FormalMultilinearSeries open FormalMultilinearSeries /-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, within two sets `s` and `t` such that `f` maps `s` to `t`, then `g ∘ f` admits the power series `q.comp p` at `x` within `s`. -/ theorem HasFPowerSeriesWithinAt.comp {g : F → G} {f : E → F} {q : FormalMultilinearSeries 𝕜 F G} {p : FormalMultilinearSeries 𝕜 E F} {x : E} {t : Set F} {s : Set E} (hg : HasFPowerSeriesWithinAt g q t (f x)) (hf : HasFPowerSeriesWithinAt f p s x) (hs : Set.MapsTo f s t) : HasFPowerSeriesWithinAt (g ∘ f) (q.comp p) s x := by /- Consider `rf` and `rg` such that `f` and `g` have power series expansion on the disks of radius `rf` and `rg`. -/ rcases hg with ⟨rg, Hg⟩ rcases hf with ⟨rf, Hf⟩ -- The terms defining `q.comp p` are geometrically summable in a disk of some radius `r`. rcases q.comp_summable_nnreal p Hg.radius_pos Hf.radius_pos with ⟨r, r_pos : 0 < r, hr⟩ /- We will consider `y` which is smaller than `r` and `rf`, and also small enough that `f (x + y)` is close enough to `f x` to be in the disk where `g` is well behaved. Let `min (r, rf, δ)` be this new radius. -/ obtain ⟨δ, δpos, hδ⟩ : ∃ δ : ℝ≥0∞, 0 < δ ∧ ∀ {z : E}, z ∈ insert x s ∩ EMetric.ball x δ → f z ∈ insert (f x) t ∩ EMetric.ball (f x) rg := by have : insert (f x) t ∩ EMetric.ball (f x) rg ∈ 𝓝[insert (f x) t] (f x) := by apply inter_mem_nhdsWithin exact EMetric.ball_mem_nhds _ Hg.r_pos have := Hf.analyticWithinAt.continuousWithinAt_insert.tendsto_nhdsWithin (hs.insert x) this rcases EMetric.mem_nhdsWithin_iff.1 this with ⟨δ, δpos, Hδ⟩ exact ⟨δ, δpos, fun {z} hz => Hδ (by rwa [Set.inter_comm])⟩ let rf' := min rf δ have min_pos : 0 < min rf' r := by simp only [rf', r_pos, Hf.r_pos, δpos, lt_min_iff, ENNReal.coe_pos, and_self_iff] /- We will show that `g ∘ f` admits the power series `q.comp p` in the disk of radius `min (r, rf', δ)`. -/ refine ⟨min rf' r, ?_⟩ refine ⟨le_trans (min_le_right rf' r) (FormalMultilinearSeries.le_comp_radius_of_summable q p r hr), min_pos, fun {y} h'y hy ↦ ?_⟩ /- Let `y` satisfy `‖y‖ < min (r, rf', δ)`. We want to show that `g (f (x + y))` is the sum of `q.comp p` applied to `y`. -/ -- First, check that `y` is small enough so that estimates for `f` and `g` apply. have y_mem : y ∈ EMetric.ball (0 : E) rf := (EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_left _ _))) hy have fy_mem : f (x + y) ∈ insert (f x) t ∩ EMetric.ball (f x) rg := by apply hδ have : y ∈ EMetric.ball (0 : E) δ := (EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_right _ _))) hy simpa [-Set.mem_insert_iff, edist_eq_enorm_sub, h'y] /- Now the proof starts. To show that the sum of `q.comp p` at `y` is `g (f (x + y))`, we will write `q.comp p` applied to `y` as a big sum over all compositions. Since the sum is summable, to get its convergence it suffices to get the convergence along some increasing sequence of sets. We will use the sequence of sets `compPartialSumTarget 0 n n`, along which the sum is exactly the composition of the partial sums of `q` and `p`, by design. To show that it converges to `g (f (x + y))`, pointwise convergence would not be enough, but we have uniform convergence to save the day. -/ -- First step: the partial sum of `p` converges to `f (x + y)`. have A : Tendsto (fun n ↦ (n, ∑ a ∈ Finset.Ico 1 n, p a fun _ ↦ y)) atTop (atTop ×ˢ 𝓝 (f (x + y) - f x)) := by apply Tendsto.prodMk tendsto_id have L : ∀ᶠ n in atTop, (∑ a ∈ Finset.range n, p a fun _b ↦ y) - f x = ∑ a ∈ Finset.Ico 1 n, p a fun _b ↦ y := by rw [eventually_atTop] refine ⟨1, fun n hn => ?_⟩ symm rw [eq_sub_iff_add_eq', Finset.range_eq_Ico, ← Hf.coeff_zero fun _i => y, Finset.sum_eq_sum_Ico_succ_bot hn] have : Tendsto (fun n => (∑ a ∈ Finset.range n, p a fun _b => y) - f x) atTop (𝓝 (f (x + y) - f x)) := (Hf.hasSum h'y y_mem).tendsto_sum_nat.sub tendsto_const_nhds exact Tendsto.congr' L this -- Second step: the composition of the partial sums of `q` and `p` converges to `g (f (x + y))`. have B : Tendsto (fun n => q.partialSum n (∑ a ∈ Finset.Ico 1 n, p a fun _b ↦ y)) atTop (𝓝 (g (f (x + y)))) := by -- we use the fact that the partial sums of `q` converge to `g (f (x + y))`, uniformly on a -- neighborhood of `f (x + y)`. have : Tendsto (fun (z : ℕ × F) ↦ q.partialSum z.1 z.2) (atTop ×ˢ 𝓝 (f (x + y) - f x)) (𝓝 (g (f x + (f (x + y) - f x)))) := by apply Hg.tendsto_partialSum_prod (y := f (x + y) - f x) · simpa [edist_eq_enorm_sub] using fy_mem.2 · simpa using fy_mem.1 simpa using this.comp A -- Third step: the sum over all compositions in `compPartialSumTarget 0 n n` converges to -- `g (f (x + y))`. As this sum is exactly the composition of the partial sum, this is a direct -- consequence of the second step have C : Tendsto (fun n => ∑ i ∈ compPartialSumTarget 0 n n, q.compAlongComposition p i.2 fun _j => y) atTop (𝓝 (g (f (x + y)))) := by simpa [comp_partialSum] using B -- Fourth step: the sum over all compositions is `g (f (x + y))`. This follows from the -- convergence along a subsequence proved in the third step, and the fact that the sum is Cauchy -- thanks to the summability properties. have D : HasSum (fun i : Σ n, Composition n => q.compAlongComposition p i.2 fun _j => y) (g (f (x + y))) := haveI cau : CauchySeq fun s : Finset (Σ n, Composition n) => ∑ i ∈ s, q.compAlongComposition p i.2 fun _j => y := by apply cauchySeq_finset_of_norm_bounded (NNReal.summable_coe.2 hr) _ simp only [coe_nnnorm, NNReal.coe_mul, NNReal.coe_pow] rintro ⟨n, c⟩ calc ‖(compAlongComposition q p c) fun _j : Fin n => y‖ ≤ ‖compAlongComposition q p c‖ * ∏ _j : Fin n, ‖y‖ := by apply ContinuousMultilinearMap.le_opNorm _ ≤ ‖compAlongComposition q p c‖ * (r : ℝ) ^ n := by rw [Finset.prod_const, Finset.card_fin] gcongr rw [EMetric.mem_ball, edist_zero_eq_enorm] at hy have := le_trans (le_of_lt hy) (min_le_right _ _) rwa [enorm_le_coe, ← NNReal.coe_le_coe, coe_nnnorm] at this tendsto_nhds_of_cauchySeq_of_subseq cau compPartialSumTarget_tendsto_atTop C -- Fifth step: the sum over `n` of `q.comp p n` can be expressed as a particular resummation of -- the sum over all compositions, by grouping together the compositions of the same -- integer `n`. The convergence of the whole sum therefore implies the converence of the sum -- of `q.comp p n` have E : HasSum (fun n => (q.comp p) n fun _j => y) (g (f (x + y))) := by apply D.sigma intro n simp only [compAlongComposition_apply, FormalMultilinearSeries.comp, ContinuousMultilinearMap.sum_apply] exact hasSum_fintype _ rw [Function.comp_apply] exact E /-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, then `g ∘ f` admits the power series `q.comp p` at `x` within `s`. -/ theorem HasFPowerSeriesAt.comp {g : F → G} {f : E → F} {q : FormalMultilinearSeries 𝕜 F G} {p : FormalMultilinearSeries 𝕜 E F} {x : E} (hg : HasFPowerSeriesAt g q (f x)) (hf : HasFPowerSeriesAt f p x) : HasFPowerSeriesAt (g ∘ f) (q.comp p) x := by rw [← hasFPowerSeriesWithinAt_univ] at hf hg ⊢ apply hg.comp hf (by simp) /-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, within two sets `s` and `t` such that `f` maps `s` to `t`, then `g ∘ f` is analytic at `x` within `s`. -/ theorem AnalyticWithinAt.comp {g : F → G} {f : E → F} {x : E} {t : Set F} {s : Set E} (hg : AnalyticWithinAt 𝕜 g t (f x)) (hf : AnalyticWithinAt 𝕜 f s x) (h : Set.MapsTo f s t) : AnalyticWithinAt 𝕜 (g ∘ f) s x := by let ⟨_q, hq⟩ := hg let ⟨_p, hp⟩ := hf exact (hq.comp hp h).analyticWithinAt /-- Version of `AnalyticWithinAt.comp` where point equality is a separate hypothesis. -/ theorem AnalyticWithinAt.comp_of_eq {g : F → G} {f : E → F} {y : F} {x : E} {t : Set F} {s : Set E} (hg : AnalyticWithinAt 𝕜 g t y) (hf : AnalyticWithinAt 𝕜 f s x) (h : Set.MapsTo f s t) (hy : f x = y) : AnalyticWithinAt 𝕜 (g ∘ f) s x := by rw [← hy] at hg exact hg.comp hf h lemma AnalyticOn.comp {f : F → G} {g : E → F} {s : Set F} {t : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g t) (h : Set.MapsTo g t s) : AnalyticOn 𝕜 (f ∘ g) t := fun x m ↦ (hf _ (h m)).comp (hg x m) h /-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is analytic at `x`. -/ @[fun_prop] theorem AnalyticAt.comp {g : F → G} {f : E → F} {x : E} (hg : AnalyticAt 𝕜 g (f x)) (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (g ∘ f) x := by rw [← analyticWithinAt_univ] at hg hf ⊢ apply hg.comp hf (by simp) /-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is analytic at `x`. -/ @[fun_prop] theorem AnalyticAt.comp' {g : F → G} {f : E → F} {x : E} (hg : AnalyticAt 𝕜 g (f x)) (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (fun z ↦ g (f z)) x := hg.comp hf /-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/ theorem AnalyticAt.comp_of_eq {g : F → G} {f : E → F} {y : F} {x : E} (hg : AnalyticAt 𝕜 g y) (hf : AnalyticAt 𝕜 f x) (hy : f x = y) : AnalyticAt 𝕜 (g ∘ f) x := by rw [← hy] at hg exact hg.comp hf /-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/ theorem AnalyticAt.comp_of_eq' {g : F → G} {f : E → F} {y : F} {x : E} (hg : AnalyticAt 𝕜 g y) (hf : AnalyticAt 𝕜 f x) (hy : f x = y) : AnalyticAt 𝕜 (fun z ↦ g (f z)) x := by apply hg.comp_of_eq hf hy theorem AnalyticAt.comp_analyticWithinAt {g : F → G} {f : E → F} {x : E} {s : Set E} (hg : AnalyticAt 𝕜 g (f x)) (hf : AnalyticWithinAt 𝕜 f s x) : AnalyticWithinAt 𝕜 (g ∘ f) s x := by rw [← analyticWithinAt_univ] at hg exact hg.comp hf (Set.mapsTo_univ _ _) theorem AnalyticAt.comp_analyticWithinAt_of_eq {g : F → G} {f : E → F} {x : E} {y : F} {s : Set E} (hg : AnalyticAt 𝕜 g y) (hf : AnalyticWithinAt 𝕜 f s x) (h : f x = y) : AnalyticWithinAt 𝕜 (g ∘ f) s x := by rw [← h] at hg exact hg.comp_analyticWithinAt hf /-- If two functions `g` and `f` are analytic respectively on `s.image f` and `s`, then `g ∘ f` is analytic on `s`. -/ theorem AnalyticOnNhd.comp' {s : Set E} {g : F → G} {f : E → F} (hg : AnalyticOnNhd 𝕜 g (s.image f)) (hf : AnalyticOnNhd 𝕜 f s) : AnalyticOnNhd 𝕜 (g ∘ f) s := fun z hz => (hg (f z) (Set.mem_image_of_mem f hz)).comp (hf z hz) theorem AnalyticOnNhd.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : AnalyticOnNhd 𝕜 g t) (hf : AnalyticOnNhd 𝕜 f s) (st : Set.MapsTo f s t) : AnalyticOnNhd 𝕜 (g ∘ f) s := comp' (mono hg (Set.mapsTo'.mp st)) hf lemma AnalyticOnNhd.comp_analyticOn {f : F → G} {g : E → F} {s : Set F} {t : Set E} (hf : AnalyticOnNhd 𝕜 f s) (hg : AnalyticOn 𝕜 g t) (h : Set.MapsTo g t s) : AnalyticOn 𝕜 (f ∘ g) t := fun x m ↦ (hf _ (h m)).comp_analyticWithinAt (hg x m) /-! ### Associativity of the composition of formal multilinear series In this paragraph, we prove the associativity of the composition of formal power series. By definition, ``` (r.comp q).comp p n v = ∑_{i₁ + ... + iₖ = n} (r.comp q)ₖ (p_{i₁} (v₀, ..., v_{i₁ -1}), p_{i₂} (...), ..., p_{iₖ}(...)) = ∑_{a : Composition n} (r.comp q) a.length (applyComposition p a v) ``` decomposing `r.comp q` in the same way, we get ``` (r.comp q).comp p n v = ∑_{a : Composition n} ∑_{b : Composition a.length} r b.length (applyComposition q b (applyComposition p a v)) ``` On the other hand, ``` r.comp (q.comp p) n v = ∑_{c : Composition n} r c.length (applyComposition (q.comp p) c v) ``` Here, `applyComposition (q.comp p) c v` is a vector of length `c.length`, whose `i`-th term is given by `(q.comp p) (c.blocksFun i) (v_l, v_{l+1}, ..., v_{m-1})` where `{l, ..., m-1}` is the `i`-th block in the composition `c`, of length `c.blocksFun i` by definition. To compute this term, we expand it as `∑_{dᵢ : Composition (c.blocksFun i)} q dᵢ.length (applyComposition p dᵢ v')`, where `v' = (v_l, v_{l+1}, ..., v_{m-1})`. Therefore, we get ``` r.comp (q.comp p) n v = ∑_{c : Composition n} ∑_{d₀ : Composition (c.blocksFun 0), ..., d_{c.length - 1} : Composition (c.blocksFun (c.length - 1))} r c.length (fun i ↦ q dᵢ.length (applyComposition p dᵢ v'ᵢ)) ``` To show that these terms coincide, we need to explain how to reindex the sums to put them in bijection (and then the terms we are summing will correspond to each other). Suppose we have a composition `a` of `n`, and a composition `b` of `a.length`. Then `b` indicates how to group together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of blocks can be called `d₀, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by saying that each `dᵢ` is one single block. Conversely, if one starts from `c` and the `dᵢ`s, one can concatenate the `dᵢ`s to obtain a composition `a` of `n`, and register the lengths of the `dᵢ`s in a composition `b` of `a.length`. An example might be enlightening. Suppose `a = [2, 2, 3, 4, 2]`. It is a composition of length 5 of 13. The content of the blocks may be represented as `0011222333344`. Now take `b = [2, 3]` as a composition of `a.length = 5`. It says that the first 2 blocks of `a` should be merged, and the last 3 blocks of `a` should be merged, giving a new composition of `13` made of two blocks of length `4` and `9`, i.e., `c = [4, 9]`. But one can also remember that the new first block was initially made of two blocks of size `2`, so `d₀ = [2, 2]`, and the new second block was initially made of three blocks of size `3`, `4` and `2`, so `d₁ = [3, 4, 2]`. This equivalence is called `Composition.sigmaEquivSigmaPi n` below. We start with preliminary results on compositions, of a very specialized nature, then define the equivalence `Composition.sigmaEquivSigmaPi n`, and we deduce finally the associativity of composition of formal multilinear series in `FormalMultilinearSeries.comp_assoc`. -/ namespace Composition variable {n : ℕ} /-- Rewriting equality in the dependent type `Σ (a : Composition n), Composition a.length)` in non-dependent terms with lists, requiring that the blocks coincide. -/ theorem sigma_composition_eq_iff (i j : Σ a : Composition n, Composition a.length) : i = j ↔ i.1.blocks = j.1.blocks ∧ i.2.blocks = j.2.blocks := by refine ⟨by rintro rfl; exact ⟨rfl, rfl⟩, ?_⟩ rcases i with ⟨a, b⟩ rcases j with ⟨a', b'⟩ rintro ⟨h, h'⟩ obtain rfl : a = a' := by ext1; exact h obtain rfl : b = b' := by ext1; exact h' rfl /-- Rewriting equality in the dependent type `Σ (c : Composition n), Π (i : Fin c.length), Composition (c.blocksFun i)` in non-dependent terms with lists, requiring that the lists of blocks coincide. -/ theorem sigma_pi_composition_eq_iff (u v : Σ c : Composition n, ∀ i : Fin c.length, Composition (c.blocksFun i)) : u = v ↔ (ofFn fun i => (u.2 i).blocks) = ofFn fun i => (v.2 i).blocks := by refine ⟨fun H => by rw [H], fun H => ?_⟩ rcases u with ⟨a, b⟩ rcases v with ⟨a', b'⟩ dsimp at H obtain rfl : a = a' := by ext1 have : map List.sum (ofFn fun i : Fin (Composition.length a) => (b i).blocks) = map List.sum (ofFn fun i : Fin (Composition.length a') => (b' i).blocks) := by rw [H] simp only [map_ofFn] at this change (ofFn fun i : Fin (Composition.length a) => (b i).blocks.sum) = ofFn fun i : Fin (Composition.length a') => (b' i).blocks.sum at this simpa [Composition.blocks_sum, Composition.ofFn_blocksFun] using this ext1 · rfl · simp only [heq_eq_eq, ofFn_inj] at H ⊢ ext1 i ext1 exact congrFun H i /-- When `a` is a composition of `n` and `b` is a composition of `a.length`, `a.gather b` is the composition of `n` obtained by gathering all the blocks of `a` corresponding to a block of `b`. For instance, if `a = [6, 5, 3, 5, 2]` and `b = [2, 3]`, one should gather together the first two blocks of `a` and its last three blocks, giving `a.gather b = [11, 10]`. -/ def gather (a : Composition n) (b : Composition a.length) : Composition n where blocks := (a.blocks.splitWrtComposition b).map sum blocks_pos := by rw [forall_mem_map] intro j hj suffices H : ∀ i ∈ j, 1 ≤ i from calc 0 < j.length := length_pos_of_mem_splitWrtComposition hj _ ≤ j.sum := length_le_sum_of_one_le _ H intro i hi apply a.one_le_blocks rw [← a.blocks.flatten_splitWrtComposition b] exact mem_flatten_of_mem hj hi blocks_sum := by rw [← sum_flatten, flatten_splitWrtComposition, a.blocks_sum] theorem length_gather (a : Composition n) (b : Composition a.length) : length (a.gather b) = b.length := show (map List.sum (a.blocks.splitWrtComposition b)).length = b.blocks.length by rw [length_map, length_splitWrtComposition] /-- An auxiliary function used in the definition of `sigmaEquivSigmaPi` below, associating to two compositions `a` of `n` and `b` of `a.length`, and an index `i` bounded by the length of `a.gather b`, the subcomposition of `a` made of those blocks belonging to the `i`-th block of `a.gather b`. -/ def sigmaCompositionAux (a : Composition n) (b : Composition a.length) (i : Fin (a.gather b).length) : Composition ((a.gather b).blocksFun i) where blocks := (a.blocks.splitWrtComposition b)[i.val]'(by rw [length_splitWrtComposition, ← length_gather]; exact i.2) blocks_pos {i} hi := a.blocks_pos (by rw [← a.blocks.flatten_splitWrtComposition b] exact mem_flatten_of_mem (List.getElem_mem _) hi) blocks_sum := by simp [Composition.blocksFun, getElem_map, Composition.gather] theorem length_sigmaCompositionAux (a : Composition n) (b : Composition a.length) (i : Fin b.length) : Composition.length (Composition.sigmaCompositionAux a b ⟨i, (length_gather a b).symm ▸ i.2⟩) = Composition.blocksFun b i := show List.length ((splitWrtComposition a.blocks b)[i.1]) = blocksFun b i by rw [getElem_map_rev List.length, getElem_of_eq (map_length_splitWrtComposition _ _), blocksFun, get_eq_getElem] theorem blocksFun_sigmaCompositionAux (a : Composition n) (b : Composition a.length) (i : Fin b.length) (j : Fin (blocksFun b i)) : blocksFun (sigmaCompositionAux a b ⟨i, (length_gather a b).symm ▸ i.2⟩) ⟨j, (length_sigmaCompositionAux a b i).symm ▸ j.2⟩ = blocksFun a (embedding b i j) := by unfold sigmaCompositionAux rw [blocksFun, get_eq_getElem, getElem_of_eq (getElem_splitWrtComposition _ _ _ _), getElem_drop, getElem_take]; rfl /-- Auxiliary lemma to prove that the composition of formal multilinear series is associative. Consider a composition `a` of `n` and a composition `b` of `a.length`. Grouping together some blocks of `a` according to `b` as in `a.gather b`, one can compute the total size of the blocks of `a` up to an index `sizeUpTo b i + j` (where the `j` corresponds to a set of blocks of `a` that do not fill a whole block of `a.gather b`). The first part corresponds to a sum of blocks in `a.gather b`, and the second one to a sum of blocks in the next block of `sigmaCompositionAux a b`. This is the content of this lemma. -/ theorem sizeUpTo_sizeUpTo_add (a : Composition n) (b : Composition a.length) {i j : ℕ} (hi : i < b.length) (hj : j < blocksFun b ⟨i, hi⟩) : sizeUpTo a (sizeUpTo b i + j) = sizeUpTo (a.gather b) i + sizeUpTo (sigmaCompositionAux a b ⟨i, (length_gather a b).symm ▸ hi⟩) j := by induction j with | zero => change sum (take (b.blocks.take i).sum a.blocks) = sum (take i (map sum (splitWrtComposition a.blocks b))) induction' i with i IH · rfl · have A : i < b.length := Nat.lt_of_succ_lt hi have B : i < List.length (map List.sum (splitWrtComposition a.blocks b)) := by simp [A] have C : 0 < blocksFun b ⟨i, A⟩ := Composition.blocks_pos' _ _ _ rw [sum_take_succ _ _ B, ← IH A C] have : take (sum (take i b.blocks)) a.blocks = take (sum (take i b.blocks)) (take (sum (take (i + 1) b.blocks)) a.blocks) := by rw [take_take, min_eq_left] apply monotone_sum_take _ (Nat.le_succ _) rw [this, getElem_map, getElem_splitWrtComposition, ← take_append_drop (sum (take i b.blocks)) (take (sum (take (Nat.succ i) b.blocks)) a.blocks), sum_append] congr rw [take_append_drop] | succ j IHj => have A : j < blocksFun b ⟨i, hi⟩ := lt_trans (lt_add_one j) hj have B : j < length (sigmaCompositionAux a b ⟨i, (length_gather a b).symm ▸ hi⟩) := by convert A; rw [← length_sigmaCompositionAux] have C : sizeUpTo b i + j < sizeUpTo b (i + 1) := by simp only [sizeUpTo_succ b hi, add_lt_add_iff_left] exact A have D : sizeUpTo b i + j < length a := lt_of_lt_of_le C (b.sizeUpTo_le _) have : sizeUpTo b i + Nat.succ j = (sizeUpTo b i + j).succ := rfl rw [this, sizeUpTo_succ _ D, IHj A, sizeUpTo_succ _ B] simp only [sigmaCompositionAux, add_assoc] rw [getElem_of_eq (getElem_splitWrtComposition _ _ _ _), getElem_drop, getElem_take] /-- Natural equivalence between `(Σ (a : Composition n), Composition a.length)` and `(Σ (c : Composition n), Π (i : Fin c.length), Composition (c.blocksFun i))`, that shows up as a change of variables in the proof that composition of formal multilinear series is associative. Consider a composition `a` of `n` and a composition `b` of `a.length`. Then `b` indicates how to group together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of blocks can be called `d₀, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by saying that each `dᵢ` is one single block. The map `⟨a, b⟩ → ⟨c, (d₀, ..., d_{a.length - 1})⟩` is the direct map in the equiv. Conversely, if one starts from `c` and the `dᵢ`s, one can join the `dᵢ`s to obtain a composition `a` of `n`, and register the lengths of the `dᵢ`s in a composition `b` of `a.length`. This is the inverse map of the equiv. -/ def sigmaEquivSigmaPi (n : ℕ) : (Σ a : Composition n, Composition a.length) ≃ Σ c : Composition n, ∀ i : Fin c.length, Composition (c.blocksFun i) where toFun i := ⟨i.1.gather i.2, i.1.sigmaCompositionAux i.2⟩ invFun i := ⟨{ blocks := (ofFn fun j => (i.2 j).blocks).flatten blocks_pos := by simp only [and_imp, List.mem_flatten, exists_imp, forall_mem_ofFn_iff] exact fun {i} j hj => Composition.blocks_pos _ hj blocks_sum := by simp [sum_ofFn, Composition.blocks_sum, Composition.sum_blocksFun] }, { blocks := ofFn fun j => (i.2 j).length blocks_pos := by intro k hk refine ((forall_mem_ofFn_iff (P := fun i => 0 < i)).2 fun j => ?_) k hk exact Composition.length_pos_of_pos _ (Composition.blocks_pos' _ _ _) blocks_sum := by dsimp only [Composition.length]; simp [sum_ofFn] }⟩ left_inv := by -- the fact that we have a left inverse is essentially `join_splitWrtComposition`, -- but we need to massage it to take care of the dependent setting. rintro ⟨a, b⟩ rw [sigma_composition_eq_iff] dsimp constructor · conv_rhs => rw [← flatten_splitWrtComposition a.blocks b, ← ofFn_get (splitWrtComposition a.blocks b)] have A : length (gather a b) = List.length (splitWrtComposition a.blocks b) := by simp only [length, gather, length_map, length_splitWrtComposition] congr! 2 exact (Fin.heq_fun_iff A (α := List ℕ)).2 fun i => rfl · have B : Composition.length (Composition.gather a b) = List.length b.blocks := Composition.length_gather _ _ conv_rhs => rw [← ofFn_getElem b.blocks] congr 1 refine (Fin.heq_fun_iff B).2 fun i => ?_ rw [sigmaCompositionAux, Composition.length, List.getElem_map_rev List.length, List.getElem_of_eq (map_length_splitWrtComposition _ _)] right_inv := by -- the fact that we have a right inverse is essentially `splitWrtComposition_join`, -- but we need to massage it to take care of the dependent setting. rintro ⟨c, d⟩ have : map List.sum (ofFn fun i : Fin (Composition.length c) => (d i).blocks) = c.blocks := by simp [map_ofFn, Function.comp_def, Composition.blocks_sum, Composition.ofFn_blocksFun] rw [sigma_pi_composition_eq_iff] dsimp congr! 1 · congr ext1 dsimp [Composition.gather] rwa [splitWrtComposition_flatten] simp only [map_ofFn, Function.comp_def] · rw [Fin.heq_fun_iff] · intro i dsimp [Composition.sigmaCompositionAux] rw [getElem_of_eq (splitWrtComposition_flatten _ _ _)] · simp only [List.getElem_ofFn] · simp only [map_ofFn, Function.comp_def] · congr end Composition namespace FormalMultilinearSeries open Composition theorem comp_assoc (r : FormalMultilinearSeries 𝕜 G H) (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) : (r.comp q).comp p = r.comp (q.comp p) := by ext n v /- First, rewrite the two compositions appearing in the theorem as two sums over complicated sigma types, as in the description of the proof above. -/ let f : (Σ a : Composition n, Composition a.length) → H := fun c => r c.2.length (applyComposition q c.2 (applyComposition p c.1 v)) let g : (Σ c : Composition n, ∀ i : Fin c.length, Composition (c.blocksFun i)) → H := fun c => r c.1.length fun i : Fin c.1.length => q (c.2 i).length (applyComposition p (c.2 i) (v ∘ c.1.embedding i)) suffices ∑ c, f c = ∑ c, g c by simpa +unfoldPartialApp only [FormalMultilinearSeries.comp, ContinuousMultilinearMap.sum_apply, compAlongComposition_apply, Finset.sum_sigma', applyComposition, ContinuousMultilinearMap.map_sum] /- Now, we use `Composition.sigmaEquivSigmaPi n` to change variables in the second sum, and check that we get exactly the same sums. -/ rw [← (sigmaEquivSigmaPi n).sum_comp] /- To check that we have the same terms, we should check that we apply the same component of `r`, and the same component of `q`, and the same component of `p`, to the same coordinate of `v`. This is true by definition, but at each step one needs to convince Lean that the types one considers are the same, using a suitable congruence lemma to avoid dependent type issues. This dance has to be done three times, one for `r`, one for `q` and one for `p`. -/ apply Finset.sum_congr rfl rintro ⟨a, b⟩ _ dsimp [sigmaEquivSigmaPi] -- check that the `r` components are the same. Based on `Composition.length_gather` apply r.congr (Composition.length_gather a b).symm intro i hi1 hi2 -- check that the `q` components are the same. Based on `length_sigmaCompositionAux` apply q.congr (length_sigmaCompositionAux a b _).symm intro j hj1 hj2 -- check that the `p` components are the same. Based on `blocksFun_sigmaCompositionAux` apply p.congr (blocksFun_sigmaCompositionAux a b _ _).symm intro k hk1 hk2 -- finally, check that the coordinates of `v` one is using are the same. Based on -- `sizeUpTo_sizeUpTo_add`. refine congr_arg v (Fin.ext ?_) dsimp [Composition.embedding] rw [sizeUpTo_sizeUpTo_add _ _ hi1 hj1, add_assoc] end FormalMultilinearSeries
HalfPlane.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Topology.Instances.EReal.Lemmas /-! # Half-planes in ℂ are open We state that open left, right, upper and lower half-planes in the complex numbers are open sets, where the bounding value of the real or imaginary part is given by an `EReal` `x`. So this includes the full plane and the empty set for `x = ⊤`/`x = ⊥`. -/ namespace Complex /-- An open left half-plane (with boundary real part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_re_lt_EReal (x : EReal) : IsOpen {z : ℂ | z.re < x} := isOpen_lt (EReal.continuous_coe_iff.mpr continuous_re) continuous_const /-- An open right half-plane (with boundary real part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_re_gt_EReal (x : EReal) : IsOpen {z : ℂ | x < z.re} := isOpen_lt continuous_const <| EReal.continuous_coe_iff.mpr continuous_re /-- An open lower half-plane (with boundary imaginary part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_im_lt_EReal (x : EReal) : IsOpen {z : ℂ | z.im < x} := isOpen_lt (EReal.continuous_coe_iff.mpr continuous_im) continuous_const /-- An open upper half-plane (with boundary imaginary part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_im_gt_EReal (x : EReal) : IsOpen {z : ℂ | x < z.im} := isOpen_lt continuous_const <| EReal.continuous_coe_iff.mpr continuous_im end Complex
DeprecatedSyntaxLinter.lean
/- Copyright (c) 2024 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa, Jeremy Tan, Adomas Baliuka -/ import Lean.Elab.Command -- Import this linter explicitly to ensure that -- this file has a valid copyright header and module docstring. import Mathlib.Tactic.Linter.Header /-! # Linter against deprecated syntax `refine'` and `cases'` provide backward-compatible implementations of their unprimed equivalents in Lean 3, `refine` and `cases`. They have been superseded by Lean 4 tactics: * `refine` and `apply` replace `refine'`. While they are similar, they handle metavariables slightly differently; this means that they are not completely interchangeable, nor can one completely replace another. However, `refine` and `apply` are more readable and (heuristically) tend to be more efficient on average. * `obtain`, `rcases` and `cases` replace `cases'`. Unlike the replacement tactics, `cases'` does not require the variables it introduces to be separated by case, which hinders readability. The `admit` tactic is a synonym for the much more common `sorry`, so the latter should be preferred. The `native_decide` tactic is not allowed in mathlib, as it trusts the entire Lean compiler (and not just the Lean kernel). Because the latter is large and complicated, at present it is probably possible to prove `False` using `native_decide`. This linter is an incentive to discourage uses of such deprecated syntax, without being a ban. It is not inherently limited to tactics. -/ open Lean Elab Linter namespace Mathlib.Linter.Style /-- The option `linter.style.refine` of the deprecated syntax linter flags usages of the `refine'` tactic. The tactics `refine`, `apply` and `refine'` are similar, but they handle metavariables slightly differently. This means that they are not completely interchangeable, nor can one completely replace another. However, `refine` and `apply` are more readable and (heuristically) tend to be more efficient on average. -/ register_option linter.style.refine : Bool := { defValue := false descr := "enable the refine linter" } /-- The option `linter.style.cases` of the deprecated syntax linter flags usages of the `cases'` tactic, which is a backward-compatible version of Lean 3's `cases` tactic. Unlike `obtain`, `rcases` and Lean 4's `cases`, variables introduced by `cases'` are not required to be separated by case, which hinders readability. -/ register_option linter.style.cases : Bool := { defValue := false descr := "enable the cases linter" } /-- The option `linter.style.admit` of the deprecated syntax linter flags usages of the `admit` tactic, which is a synonym for the much more common `sorry`. -/ register_option linter.style.admit : Bool := { defValue := false descr := "enable the admit linter" } /-- The option `linter.style.nativeDecide` of the deprecated syntax linter flags usages of the `native_decide` tactic, which is disallowed in mathlib. -/ -- Note: this linter is purely for user information. Running `lean4checker` in CI catches *any* -- additional axioms that are introduced (not just `ofReduceBool`): the point of this check is to -- alert the user quickly, not to be airtight. register_option linter.style.nativeDecide : Bool := { defValue := false descr := "enable the nativeDecide linter" } /-- The option `linter.style.maxHeartbeats` of the deprecated syntax linter flags usages of `set_option <name-containing-maxHeartbeats> n in cmd` that do not add a comment explaining the reason for the modification of the `maxHeartbeats`. This includes `set_option maxHeartbeats n in` and `set_option synthInstance.maxHeartbeats n in`. -/ register_option linter.style.maxHeartbeats : Bool := { defValue := false descr := "enable the maxHeartbeats linter" } /-- If the input syntax is of the form `set_option <option> num in <string> cmd`, where `<option>` contains `maxHeartbeats`, then it returns * the `<option>`, as a name (typically, `maxHeartbeats` or `synthInstance.maxHeartbeats`); * the number `num` and * whatever is in `<string>`. Note that `<string>` can only consist of whitespace and comments. Otherwise, it returns `none`. -/ def getSetOptionMaxHeartbeatsComment : Syntax → Option (Name × Nat × Substring) | stx@`(command|set_option $mh $n:num in $_) => let opt := mh.getId if !opt.components.contains `maxHeartbeats then none else if let some inAtom := stx.find? (·.getAtomVal == "in") then inAtom.getTrailing?.map (opt, n.getNat, ·) else -- This branch should be unreachable. some default | _ => none /-- Whether a given piece of syntax represents a `decide` tactic call with the `native` option enabled. This may have false negatives for `decide (config := {<options>})` syntax). -/ def isDecideNative (stx : Syntax ) : Bool := match stx with | .node _ ``Lean.Parser.Tactic.decide args => -- The configuration passed to the tactic call. let config := args[1]![0] -- Check all configuration arguments in order to determine the final -- toggling of the native decide option. if let (.node _ _ config_args) := config then let natives := config_args.filterMap (match ·[0] with | `(Parser.Tactic.posConfigItem| +native) => some true | `(Parser.Tactic.negConfigItem| -native) => some false | `(Parser.Tactic.valConfigItem| (config := {native := true})) => some true | `(Parser.Tactic.valConfigItem| (config := {native := false})) => some false | _ => none) natives.back? == some true else false | _ => false /-- `getDeprecatedSyntax t` returns all usages of deprecated syntax in the input syntax `t`. -/ partial def getDeprecatedSyntax : Syntax → Array (SyntaxNodeKind × Syntax × MessageData) | stx@(.node _ kind args) => let rargs := args.flatMap getDeprecatedSyntax match kind with | ``Lean.Parser.Tactic.refine' => rargs.push (kind, stx, "The `refine'` tactic is discouraged: \ please strongly consider using `refine` or `apply` instead.") | `Mathlib.Tactic.cases' => rargs.push (kind, stx, "The `cases'` tactic is discouraged: \ please strongly consider using `obtain`, `rcases` or `cases` instead.") | ``Lean.Parser.Tactic.tacticAdmit => rargs.push (kind, stx, "The `admit` tactic is discouraged: \ please strongly consider using the synonymous `sorry` instead.") | ``Lean.Parser.Tactic.decide => if isDecideNative stx then rargs.push (kind, stx, "Using `decide +native` is not allowed in mathlib: \ because it trusts the entire Lean compiler (not just the Lean kernel), \ it could quite possibly be used to prove false.") else rargs | ``Lean.Parser.Tactic.nativeDecide => rargs.push (kind, stx, "Using `native_decide` is not allowed in mathlib: \ because it trusts the entire Lean compiler (not just the Lean kernel), \ it could quite possibly be used to prove false.") | ``Lean.Parser.Command.in => match getSetOptionMaxHeartbeatsComment stx with | none => rargs | some (opt, n, trailing) => -- Since we are now seeing the currently outermost `maxHeartbeats` option, -- we remove all subsequent potential flags and only decide whether to lint or not -- based on whether the current option has a comment. let rargs := rargs.filter (·.1 != `MaxHeartbeats) if trailing.toString.trimLeft.isEmpty then rargs.push (`MaxHeartbeats, stx, s!"Please, add a comment explaining the need for modifying the maxHeartbeat limit, \ as in\nset_option {opt} {n} in\n-- reason for change\n...") else rargs | _ => rargs | _ => default /-- The deprecated syntax linter flags usages of deprecated syntax and suggests replacement syntax. For each individual case, linting can be turned on or off separately. * `refine'`, superseded by `refine` and `apply` (controlled by `linter.style.refine`) * `cases'`, superseded by `obtain`, `rcases` and `cases` (controlled by `linter.style.cases`) * `admit`, superseded by `sorry` (controlled by `linter.style.admit`) * `set_option maxHeartbeats`, should contain an explanatory comment (controlled by `linter.style.maxHeartbeats`) -/ def deprecatedSyntaxLinter : Linter where run stx := do unless getLinterValue linter.style.refine (← getLinterOptions) || getLinterValue linter.style.cases (← getLinterOptions) || getLinterValue linter.style.admit (← getLinterOptions) || getLinterValue linter.style.maxHeartbeats (← getLinterOptions) || getLinterValue linter.style.nativeDecide (← getLinterOptions) do return if (← MonadState.get).messages.hasErrors then return let deprecations := getDeprecatedSyntax stx -- Using `withSetOptionIn` here, allows the linter to parse also the "leading" `set_option`s -- but then flagging them only if the corresponding option is still set after elaborating the -- leading `set_option`s. -- In particular, this means that the linter "sees" `set_option maxHeartbeats 10 in ...`, -- records it in `deprecations` and then acts on it, according to the correct options. (withSetOptionIn fun _ ↦ do for (kind, stx', msg) in deprecations do match kind with | ``Lean.Parser.Tactic.refine' => Linter.logLintIf linter.style.refine stx' msg | `Mathlib.Tactic.cases' => Linter.logLintIf linter.style.cases stx' msg | ``Lean.Parser.Tactic.tacticAdmit => Linter.logLintIf linter.style.admit stx' msg | ``Lean.Parser.Tactic.nativeDecide | ``Lean.Parser.Tactic.decide => Linter.logLintIf linter.style.nativeDecide stx' msg | `MaxHeartbeats => Linter.logLintIf linter.style.maxHeartbeats stx' msg | _ => continue) stx initialize addLinter deprecatedSyntaxLinter end Mathlib.Linter.Style
GramSchmidtOrtho.lean
/- Copyright (c) 2022 Jiale Miao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jiale Miao, Kevin Buzzard, Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.Block /-! # Gram-Schmidt Orthogonalization and Orthonormalization In this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization. The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. ## Main results - `gramSchmidt`: the Gram-Schmidt process - `gramSchmidt_orthogonal`: `gramSchmidt` produces an orthogonal system of vectors. - `span_gramSchmidt`: `gramSchmidt` preserves span of vectors. - `gramSchmidt_linearIndependent`: if the input vectors of `gramSchmidt` are linearly independent, then so are the output vectors. - `gramSchmidt_ne_zero`: if the input vectors of `gramSchmidt` are linearly independent, then the output vectors are non-zero. - `gramSchmidtBasis`: the basis produced by the Gram-Schmidt process when given a basis as input - `gramSchmidtNormed`: the normalized `gramSchmidt` process, i.e each vector in `gramSchmidtNormed` has unit length - `gramSchmidt_orthonormal`: `gramSchmidtNormed` produces an orthornormal system of vectors. - `gramSchmidtOrthonormalBasis`: orthonormal basis constructed by the Gram-Schmidt process from an indexed set of vectors of the right size -/ open Finset Submodule Module variable (𝕜 : Type*) {E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrderBot ι] [WellFoundedLT ι] attribute [local instance] IsWellOrder.toHasWellFounded local notation "⟪" x ", " y "⟫" => inner 𝕜 x y namespace InnerProductSpace /-- The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. -/ noncomputable def gramSchmidt [WellFoundedLT ι] (f : ι → E) (n : ι) : E := f n - ∑ i : Iio n, (𝕜 ∙ gramSchmidt f i).starProjection (f n) termination_by n decreasing_by exact mem_Iio.1 i.2 /-- This lemma uses `∑ i in` instead of `∑ i :`. -/ theorem gramSchmidt_def (f : ι → E) (n : ι) : gramSchmidt 𝕜 f n = f n - ∑ i ∈ Iio n, (𝕜 ∙ gramSchmidt 𝕜 f i).starProjection (f n) := by rw [← sum_attach, attach_eq_univ, gramSchmidt] theorem gramSchmidt_def' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, (𝕜 ∙ gramSchmidt 𝕜 f i).starProjection (f n) := by rw [gramSchmidt_def, sub_add_cancel] theorem gramSchmidt_def'' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, (⟪gramSchmidt 𝕜 f i, f n⟫ / (‖gramSchmidt 𝕜 f i‖ : 𝕜) ^ 2) • gramSchmidt 𝕜 f i := by simp only [← map_pow, ← starProjection_singleton, ← gramSchmidt_def' 𝕜 f n] @[simp] theorem gramSchmidt_bot {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι] [WellFoundedLT ι] (f : ι → E) : gramSchmidt 𝕜 f ⊥ = f ⊥ := by rw [gramSchmidt_def, Iio_eq_Ico, Finset.Ico_self, Finset.sum_empty, sub_zero] @[simp] theorem gramSchmidt_zero (n : ι) : gramSchmidt 𝕜 (0 : ι → E) n = 0 := by rw [gramSchmidt_def]; simp /-- **Gram-Schmidt Orthogonalisation**: `gramSchmidt` produces an orthogonal system of vectors. -/ theorem gramSchmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) : ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := by suffices ∀ a b : ι, a < b → ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 by rcases h₀.lt_or_gt with ha | hb · exact this _ _ ha · rw [inner_eq_zero_symm] exact this _ _ hb clear h₀ a b intro a b h₀ revert a apply wellFounded_lt.induction b intro b ih a h₀ simp only [gramSchmidt_def 𝕜 f b, inner_sub_right, inner_sum, starProjection_singleton, inner_smul_right] rw [Finset.sum_eq_single_of_mem a (Finset.mem_Iio.mpr h₀)] · by_cases h : gramSchmidt 𝕜 f a = 0 · simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero] · rw [RCLike.ofReal_pow, ← inner_self_eq_norm_sq_to_K, div_mul_cancel₀, sub_self] rwa [inner_self_ne_zero] intro i hi hia simp only [mul_eq_zero, div_eq_zero_iff] right rcases hia.lt_or_gt with hia₁ | hia₂ · rw [inner_eq_zero_symm] exact ih a h₀ i hia₁ · exact ih i (mem_Iio.1 hi) a hia₂ /-- This is another version of `gramSchmidt_orthogonal` using `Pairwise` instead. -/ theorem gramSchmidt_pairwise_orthogonal (f : ι → E) : Pairwise fun a b => ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := fun _ _ => gramSchmidt_orthogonal 𝕜 f theorem gramSchmidt_inv_triangular (v : ι → E) {i j : ι} (hij : i < j) : ⟪gramSchmidt 𝕜 v j, v i⟫ = 0 := by rw [gramSchmidt_def'' 𝕜 v] simp only [inner_add_right, inner_sum, inner_smul_right] set b : ι → E := gramSchmidt 𝕜 v convert zero_add (0 : 𝕜) · exact gramSchmidt_orthogonal 𝕜 v hij.ne' apply Finset.sum_eq_zero rintro k hki' have hki : k < i := by simpa using hki' have : ⟪b j, b k⟫ = 0 := gramSchmidt_orthogonal 𝕜 v (hki.trans hij).ne' simp [this] open Submodule Set Order theorem mem_span_gramSchmidt (f : ι → E) {i j : ι} (hij : i ≤ j) : f i ∈ span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j) := by rw [gramSchmidt_def' 𝕜 f i] simp_rw [starProjection_singleton] exact Submodule.add_mem _ (subset_span <| mem_image_of_mem _ hij) (Submodule.sum_mem _ fun k hk => smul_mem (span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j)) _ <| subset_span <| mem_image_of_mem (gramSchmidt 𝕜 f) <| (Finset.mem_Iio.1 hk).le.trans hij) theorem gramSchmidt_mem_span (f : ι → E) : ∀ {j i}, i ≤ j → gramSchmidt 𝕜 f i ∈ span 𝕜 (f '' Set.Iic j) := by intro j i hij rw [gramSchmidt_def 𝕜 f i] simp_rw [starProjection_singleton] refine Submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij)) (Submodule.sum_mem _ fun k hk => ?_) let hkj : k < j := (Finset.mem_Iio.1 hk).trans_le hij exact smul_mem _ _ (span_mono (image_mono <| Set.Iic_subset_Iic.2 hkj.le) <| gramSchmidt_mem_span _ le_rfl) termination_by j => j theorem span_gramSchmidt_Iic (f : ι → E) (c : ι) : span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic c) = span 𝕜 (f '' Set.Iic c) := span_eq_span (Set.image_subset_iff.2 fun _ => gramSchmidt_mem_span _ _) <| Set.image_subset_iff.2 fun _ => mem_span_gramSchmidt _ _ theorem span_gramSchmidt_Iio (f : ι → E) (c : ι) : span 𝕜 (gramSchmidt 𝕜 f '' Set.Iio c) = span 𝕜 (f '' Set.Iio c) := span_eq_span (Set.image_subset_iff.2 fun _ hi => span_mono (image_mono <| Iic_subset_Iio.2 hi) <| gramSchmidt_mem_span _ _ le_rfl) <| Set.image_subset_iff.2 fun _ hi => span_mono (image_mono <| Iic_subset_Iio.2 hi) <| mem_span_gramSchmidt _ _ le_rfl /-- `gramSchmidt` preserves span of vectors. -/ theorem span_gramSchmidt (f : ι → E) : span 𝕜 (range (gramSchmidt 𝕜 f)) = span 𝕜 (range f) := span_eq_span (range_subset_iff.2 fun _ => span_mono (image_subset_range _ _) <| gramSchmidt_mem_span _ _ le_rfl) <| range_subset_iff.2 fun _ => span_mono (image_subset_range _ _) <| mem_span_gramSchmidt _ _ le_rfl /-- If given an orthogonal set of vectors, `gramSchmidt` fixes its input. -/ theorem gramSchmidt_of_orthogonal {f : ι → E} (hf : Pairwise (⟪f ·, f ·⟫ = 0)) : gramSchmidt 𝕜 f = f := by ext i rw [gramSchmidt_def] trans f i - 0 · congr apply Finset.sum_eq_zero intro j hj rw [Submodule.starProjection_apply, Submodule.coe_eq_zero] suffices span 𝕜 (f '' Set.Iic j) ⟂ 𝕜 ∙ f i by apply orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero rw [mem_orthogonal_singleton_iff_inner_left, ← mem_orthogonal_singleton_iff_inner_right] exact this (gramSchmidt_mem_span 𝕜 f (le_refl j)) rw [isOrtho_span] rintro u ⟨k, hk, rfl⟩ v (rfl : v = f i) apply hf exact (lt_of_le_of_lt hk (Finset.mem_Iio.mp hj)).ne · simp variable {𝕜} theorem gramSchmidt_ne_zero_coe {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 (f ∘ ((↑) : Set.Iic n → ι))) : gramSchmidt 𝕜 f n ≠ 0 := by by_contra h have h₁ : f n ∈ span 𝕜 (f '' Set.Iio n) := by rw [← span_gramSchmidt_Iio 𝕜 f n, gramSchmidt_def' 𝕜 f, h, zero_add] apply Submodule.sum_mem _ _ intro a ha simp only [starProjection_singleton] apply Submodule.smul_mem _ _ _ rw [Finset.mem_Iio] at ha exact subset_span ⟨a, ha, by rfl⟩ have h₂ : (f ∘ ((↑) : Set.Iic n → ι)) ⟨n, le_refl n⟩ ∈ span 𝕜 (f ∘ ((↑) : Set.Iic n → ι) '' Set.Iio ⟨n, le_refl n⟩) := by rw [image_comp] simpa using h₁ apply LinearIndependent.notMem_span_image h₀ _ h₂ simp only [Set.mem_Iio, lt_self_iff_false, not_false_iff] /-- If the input vectors of `gramSchmidt` are linearly independent, then the output vectors are non-zero. -/ theorem gramSchmidt_ne_zero {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 f) : gramSchmidt 𝕜 f n ≠ 0 := gramSchmidt_ne_zero_coe _ (LinearIndependent.comp h₀ _ Subtype.coe_injective) /-- `gramSchmidt` produces a triangular matrix of vectors when given a basis. -/ theorem gramSchmidt_triangular {i j : ι} (hij : i < j) (b : Basis ι 𝕜 E) : b.repr (gramSchmidt 𝕜 b i) j = 0 := by have : gramSchmidt 𝕜 b i ∈ span 𝕜 (gramSchmidt 𝕜 b '' Set.Iio j) := subset_span ((Set.mem_image _ _ _).2 ⟨i, hij, rfl⟩) have : gramSchmidt 𝕜 b i ∈ span 𝕜 (b '' Set.Iio j) := by rwa [← span_gramSchmidt_Iio 𝕜 b j] have : ↑(b.repr (gramSchmidt 𝕜 b i)).support ⊆ Set.Iio j := Basis.repr_support_subset_of_mem_span b (Set.Iio j) this exact (Finsupp.mem_supported' _ _).1 ((Finsupp.mem_supported 𝕜 _).2 this) j Set.notMem_Iio_self /-- `gramSchmidt` produces linearly independent vectors when given linearly independent vectors. -/ theorem gramSchmidt_linearIndependent {f : ι → E} (h₀ : LinearIndependent 𝕜 f) : LinearIndependent 𝕜 (gramSchmidt 𝕜 f) := linearIndependent_of_ne_zero_of_inner_eq_zero (fun _ => gramSchmidt_ne_zero _ h₀) fun _ _ => gramSchmidt_orthogonal 𝕜 f /-- When given a basis, `gramSchmidt` produces a basis. -/ noncomputable def gramSchmidtBasis (b : Basis ι 𝕜 E) : Basis ι 𝕜 E := Basis.mk (gramSchmidt_linearIndependent b.linearIndependent) ((span_gramSchmidt 𝕜 b).trans b.span_eq).ge theorem coe_gramSchmidtBasis (b : Basis ι 𝕜 E) : (gramSchmidtBasis b : ι → E) = gramSchmidt 𝕜 b := Basis.coe_mk _ _ variable (𝕜) in /-- the normalized `gramSchmidt` (i.e each vector in `gramSchmidtNormed` has unit length.) -/ noncomputable def gramSchmidtNormed (f : ι → E) (n : ι) : E := (‖gramSchmidt 𝕜 f n‖ : 𝕜)⁻¹ • gramSchmidt 𝕜 f n theorem gramSchmidtNormed_unit_length_coe {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 (f ∘ ((↑) : Set.Iic n → ι))) : ‖gramSchmidtNormed 𝕜 f n‖ = 1 := by simp only [gramSchmidt_ne_zero_coe n h₀, gramSchmidtNormed, norm_smul_inv_norm, Ne, not_false_iff] theorem gramSchmidtNormed_unit_length {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 f) : ‖gramSchmidtNormed 𝕜 f n‖ = 1 := gramSchmidtNormed_unit_length_coe _ (LinearIndependent.comp h₀ _ Subtype.coe_injective) theorem gramSchmidtNormed_unit_length' {f : ι → E} {n : ι} (hn : gramSchmidtNormed 𝕜 f n ≠ 0) : ‖gramSchmidtNormed 𝕜 f n‖ = 1 := by rw [gramSchmidtNormed] at * rw [norm_smul_inv_norm] simpa using hn /-- **Gram-Schmidt Orthonormalization**: `gramSchmidtNormed` applied to a linearly independent set of vectors produces an orthornormal system of vectors. -/ theorem gramSchmidtNormed_orthonormal {f : ι → E} (h₀ : LinearIndependent 𝕜 f) : Orthonormal 𝕜 (gramSchmidtNormed 𝕜 f) := by unfold Orthonormal constructor · simp only [gramSchmidtNormed_unit_length, h₀, imp_true_iff] · intro i j hij simp only [gramSchmidtNormed, inner_smul_left, inner_smul_right, RCLike.conj_inv, RCLike.conj_ofReal, mul_eq_zero, inv_eq_zero, RCLike.ofReal_eq_zero, norm_eq_zero] repeat' right exact gramSchmidt_orthogonal 𝕜 f hij @[deprecated (since := "2025-07-10")] alias gramSchmidt_orthonormal := gramSchmidtNormed_orthonormal /-- **Gram-Schmidt Orthonormalization**: `gramSchmidtNormed` produces an orthornormal system of vectors after removing the vectors which become zero in the process. -/ theorem gramSchmidtNormed_orthonormal' (f : ι → E) : Orthonormal 𝕜 fun i : { i | gramSchmidtNormed 𝕜 f i ≠ 0 } => gramSchmidtNormed 𝕜 f i := by refine ⟨fun i => gramSchmidtNormed_unit_length' i.prop, ?_⟩ rintro i j (hij : ¬_) rw [Subtype.ext_iff] at hij simp [gramSchmidtNormed, inner_smul_left, inner_smul_right, gramSchmidt_orthogonal 𝕜 f hij] @[deprecated (since := "2025-07-10")] alias gramSchmidt_orthonormal' := gramSchmidtNormed_orthonormal' open Submodule Set Order theorem span_gramSchmidtNormed (f : ι → E) (s : Set ι) : span 𝕜 (gramSchmidtNormed 𝕜 f '' s) = span 𝕜 (gramSchmidt 𝕜 f '' s) := by refine span_eq_span (Set.image_subset_iff.2 fun i hi => smul_mem _ _ <| subset_span <| mem_image_of_mem _ hi) (Set.image_subset_iff.2 fun i hi => span_mono (image_mono <| singleton_subset_set_iff.2 hi) ?_) simp only [coe_singleton, Set.image_singleton] by_cases h : gramSchmidt 𝕜 f i = 0 · simp [h] · refine mem_span_singleton.2 ⟨‖gramSchmidt 𝕜 f i‖, smul_inv_smul₀ ?_ _⟩ exact mod_cast norm_ne_zero_iff.2 h theorem span_gramSchmidtNormed_range (f : ι → E) : span 𝕜 (range (gramSchmidtNormed 𝕜 f)) = span 𝕜 (range (gramSchmidt 𝕜 f)) := by simpa only [image_univ.symm] using span_gramSchmidtNormed f univ /-- `gramSchmidtNormed` produces linearly independent vectors when given linearly independent vectors. -/ theorem gramSchmidtNormed_linearIndependent {f : ι → E} (h₀ : LinearIndependent 𝕜 f) : LinearIndependent 𝕜 (gramSchmidtNormed 𝕜 f) := by unfold gramSchmidtNormed have (i : ι) : IsUnit (‖gramSchmidt 𝕜 f i‖⁻¹ : 𝕜) := isUnit_iff_ne_zero.mpr (by simp [gramSchmidt_ne_zero i h₀]) let w : ι → 𝕜ˣ := fun i ↦ (this i).unit apply (gramSchmidt_linearIndependent h₀).units_smul (w := fun i ↦ (this i).unit) section OrthonormalBasis variable [Fintype ι] [FiniteDimensional 𝕜 E] (h : finrank 𝕜 E = Fintype.card ι) (f : ι → E) /-- Given an indexed family `f : ι → E` of vectors in an inner product space `E`, for which the size of the index set is the dimension of `E`, produce an orthonormal basis for `E` which agrees with the orthonormal set produced by the Gram-Schmidt orthonormalization process on the elements of `ι` for which this process gives a nonzero number. -/ noncomputable def gramSchmidtOrthonormalBasis : OrthonormalBasis ι 𝕜 E := ((gramSchmidtNormed_orthonormal' f).exists_orthonormalBasis_extension_of_card_eq (v := gramSchmidtNormed 𝕜 f) h).choose theorem gramSchmidtOrthonormalBasis_apply {f : ι → E} {i : ι} (hi : gramSchmidtNormed 𝕜 f i ≠ 0) : gramSchmidtOrthonormalBasis h f i = gramSchmidtNormed 𝕜 f i := ((gramSchmidtNormed_orthonormal' f).exists_orthonormalBasis_extension_of_card_eq (v := gramSchmidtNormed 𝕜 f) h).choose_spec i hi theorem gramSchmidtOrthonormalBasis_apply_of_orthogonal {f : ι → E} (hf : Pairwise fun i j => ⟪f i, f j⟫ = 0) {i : ι} (hi : f i ≠ 0) : gramSchmidtOrthonormalBasis h f i = (‖f i‖⁻¹ : 𝕜) • f i := by have H : gramSchmidtNormed 𝕜 f i = (‖f i‖⁻¹ : 𝕜) • f i := by rw [gramSchmidtNormed, gramSchmidt_of_orthogonal 𝕜 hf] rw [gramSchmidtOrthonormalBasis_apply h, H] simpa [H] using hi theorem inner_gramSchmidtOrthonormalBasis_eq_zero {f : ι → E} {i : ι} (hi : gramSchmidtNormed 𝕜 f i = 0) (j : ι) : ⟪gramSchmidtOrthonormalBasis h f i, f j⟫ = 0 := by rw [← mem_orthogonal_singleton_iff_inner_right] suffices span 𝕜 (gramSchmidtNormed 𝕜 f '' Set.Iic j) ⟂ 𝕜 ∙ gramSchmidtOrthonormalBasis h f i by apply this rw [span_gramSchmidtNormed] exact mem_span_gramSchmidt 𝕜 f le_rfl rw [isOrtho_span] rintro u ⟨k, _, rfl⟩ v (rfl : v = _) by_cases hk : gramSchmidtNormed 𝕜 f k = 0 · rw [hk, inner_zero_left] rw [← gramSchmidtOrthonormalBasis_apply h hk] have : k ≠ i := by rintro rfl exact hk hi exact (gramSchmidtOrthonormalBasis h f).orthonormal.2 this theorem gramSchmidtOrthonormalBasis_inv_triangular {i j : ι} (hij : i < j) : ⟪gramSchmidtOrthonormalBasis h f j, f i⟫ = 0 := by by_cases hi : gramSchmidtNormed 𝕜 f j = 0 · rw [inner_gramSchmidtOrthonormalBasis_eq_zero h hi] · simp [gramSchmidtOrthonormalBasis_apply h hi, gramSchmidtNormed, inner_smul_left, gramSchmidt_inv_triangular 𝕜 f hij] theorem gramSchmidtOrthonormalBasis_inv_triangular' {i j : ι} (hij : i < j) : (gramSchmidtOrthonormalBasis h f).repr (f i) j = 0 := by simpa [OrthonormalBasis.repr_apply_apply] using gramSchmidtOrthonormalBasis_inv_triangular h f hij /-- Given an indexed family `f : ι → E` of vectors in an inner product space `E`, for which the size of the index set is the dimension of `E`, the matrix of coefficients of `f` with respect to the orthonormal basis `gramSchmidtOrthonormalBasis` constructed from `f` is upper-triangular. -/ theorem gramSchmidtOrthonormalBasis_inv_blockTriangular : ((gramSchmidtOrthonormalBasis h f).toBasis.toMatrix f).BlockTriangular id := fun _ _ => gramSchmidtOrthonormalBasis_inv_triangular' h f theorem gramSchmidtOrthonormalBasis_det [DecidableEq ι] : (gramSchmidtOrthonormalBasis h f).toBasis.det f = ∏ i, ⟪gramSchmidtOrthonormalBasis h f i, f i⟫ := by convert Matrix.det_of_upperTriangular (gramSchmidtOrthonormalBasis_inv_blockTriangular h f) exact ((gramSchmidtOrthonormalBasis h f).repr_apply_apply (f _) _).symm end OrthonormalBasis end InnerProductSpace
Monoidal.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Jack McKoen -/ import Mathlib.AlgebraicTopology.SimplicialSet.StdSimplex import Mathlib.CategoryTheory.Monoidal.Cartesian.FunctorCategory import Mathlib.CategoryTheory.Monoidal.Types.Basic /-! # The monoidal category structure on simplicial sets This file defines an instance of chosen finite products for the category `SSet`. It follows from the fact the `SSet` if a category of functors to the category of types and that the category of types have chosen finite products. As a result, we obtain a monoidal category structure on `SSet`. -/ universe u open Simplicial CategoryTheory MonoidalCategory Limits namespace SSet instance : CartesianMonoidalCategory SSet.{u} := (inferInstance : CartesianMonoidalCategory (SimplexCategoryᵒᵖ ⥤ Type u)) @[simp] lemma leftUnitor_hom_app_apply (K : SSet.{u}) {Δ : SimplexCategoryᵒᵖ} (x : (𝟙_ _ ⊗ K).obj Δ) : (λ_ K).hom.app Δ x = x.2 := rfl @[simp] lemma leftUnitor_inv_app_apply (K : SSet.{u}) {Δ : SimplexCategoryᵒᵖ} (x : K.obj Δ) : (λ_ K).inv.app Δ x = ⟨PUnit.unit, x⟩ := rfl @[simp] lemma rightUnitor_hom_app_apply (K : SSet.{u}) {Δ : SimplexCategoryᵒᵖ} (x : (K ⊗ 𝟙_ _).obj Δ) : (ρ_ K).hom.app Δ x = x.1 := rfl @[simp] lemma rightUnitor_inv_app_apply (K : SSet.{u}) {Δ : SimplexCategoryᵒᵖ} (x : K.obj Δ) : (ρ_ K).inv.app Δ x = ⟨x, PUnit.unit⟩ := rfl @[simp] lemma tensorHom_app_apply {K K' L L' : SSet.{u}} (f : K ⟶ K') (g : L ⟶ L') {Δ : SimplexCategoryᵒᵖ} (x : (K ⊗ L).obj Δ) : (f ⊗ₘ g).app Δ x = ⟨f.app Δ x.1, g.app Δ x.2⟩ := rfl @[simp] lemma whiskerLeft_app_apply (K : SSet.{u}) {L L' : SSet.{u}} (g : L ⟶ L') {Δ : SimplexCategoryᵒᵖ} (x : (K ⊗ L).obj Δ) : (K ◁ g).app Δ x = ⟨x.1, g.app Δ x.2⟩ := rfl @[simp] lemma whiskerRight_app_apply {K K' : SSet.{u}} (f : K ⟶ K') (L : SSet.{u}) {Δ : SimplexCategoryᵒᵖ} (x : (K ⊗ L).obj Δ) : (f ▷ L).app Δ x = ⟨f.app Δ x.1, x.2⟩ := rfl @[simp] lemma associator_hom_app_apply (K L M : SSet.{u}) {Δ : SimplexCategoryᵒᵖ} (x : ((K ⊗ L) ⊗ M).obj Δ) : (α_ K L M).hom.app Δ x = ⟨x.1.1, x.1.2, x.2⟩ := rfl @[simp] lemma associator_inv_app_apply (K L M : SSet.{u}) {Δ : SimplexCategoryᵒᵖ} (x : (K ⊗ L ⊗ M).obj Δ) : (α_ K L M).inv.app Δ x = ⟨⟨x.1, x.2.1⟩, x.2.2⟩ := rfl /-- The bijection `(𝟙_ SSet ⟶ K) ≃ K _⦋0⦌`. -/ def unitHomEquiv (K : SSet.{u}) : (𝟙_ _ ⟶ K) ≃ K _⦋0⦌ where toFun φ := φ.app _ PUnit.unit invFun x := { app := fun Δ _ => K.map (SimplexCategory.const Δ.unop ⦋0⦌ 0).op x naturality := fun Δ Δ' f => by ext ⟨⟩ dsimp rw [← FunctorToTypes.map_comp_apply] rfl } left_inv φ := by ext Δ ⟨⟩ dsimp rw [← FunctorToTypes.naturality] rfl right_inv x := by simp /-- The object `Δ[0]` is terminal in `SSet`. -/ def stdSimplex.isTerminalObj₀ : IsTerminal (Δ[0] : SSet.{u}) := IsTerminal.ofUniqueHom (fun _ ↦ SSet.const (obj₀Equiv.symm 0)) (fun _ _ ↦ by ext ⟨n⟩ exact objEquiv.injective (by ext; simp)) @[ext] lemma stdSimplex.ext₀ {X : SSet.{u}} {f g : X ⟶ Δ[0]} : f = g := isTerminalObj₀.hom_ext _ _ end SSet
Domain.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Degree.Operations /-! # Univariate polynomials form a domain ## Main results * `Polynomial.instNoZeroDivisors`: `R[X]` has no zero divisors if `R` does not * `Polynomial.instDomain`: `R[X]` is a domain if `R` is -/ noncomputable section open Finsupp Finset open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ} section Semiring variable [Semiring R] [NoZeroDivisors R] {p q : R[X]} lemma natDegree_mul (hp : p ≠ 0) (hq : q ≠ 0) : (p*q).natDegree = p.natDegree + q.natDegree := by rw [← Nat.cast_inj (R := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero hp hq), Nat.cast_add, ← degree_eq_natDegree hp, ← degree_eq_natDegree hq, degree_mul] omit [NoZeroDivisors R] in variable (p) in lemma natDegree_smul {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] {a : S} (ha : a ≠ 0) : (a • p).natDegree = p.natDegree := by by_cases hp : p = 0 · simp only [hp, smul_zero] · apply natDegree_eq_of_le_of_coeff_ne_zero · exact (natDegree_smul_le _ _).trans (le_refl _) · simp only [coeff_smul] apply smul_ne_zero ha simp [hp] @[simp] lemma natDegree_pow (p : R[X]) (n : ℕ) : natDegree (p ^ n) = n * natDegree p := by classical obtain rfl | hp := eq_or_ne p 0 · obtain rfl | hn := eq_or_ne n 0 <;> simp [*] exact natDegree_pow' <| by rw [← leadingCoeff_pow, Ne, leadingCoeff_eq_zero]; exact pow_ne_zero _ hp lemma natDegree_le_of_dvd (h1 : p ∣ q) (h2 : q ≠ 0) : p.natDegree ≤ q.natDegree := by obtain ⟨q, rfl⟩ := h1 rw [mul_ne_zero_iff] at h2 rw [natDegree_mul h2.1 h2.2]; exact Nat.le_add_right _ _ lemma degree_le_of_dvd (h1 : p ∣ q) (h2 : q ≠ 0) : degree p ≤ degree q := by rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2 exact degree_le_mul_left p h2.2 lemma eq_zero_of_dvd_of_degree_lt (h₁ : p ∣ q) (h₂ : degree q < degree p) : q = 0 := by by_contra hc exact lt_iff_not_ge.mp h₂ (degree_le_of_dvd h₁ hc) lemma eq_zero_of_dvd_of_natDegree_lt (h₁ : p ∣ q) (h₂ : natDegree q < natDegree p) : q = 0 := by by_contra hc exact lt_iff_not_ge.mp h₂ (natDegree_le_of_dvd h₁ hc) lemma not_dvd_of_degree_lt (h0 : q ≠ 0) (hl : q.degree < p.degree) : ¬p ∣ q := by by_contra hcontra exact h0 (eq_zero_of_dvd_of_degree_lt hcontra hl) lemma not_dvd_of_natDegree_lt (h0 : q ≠ 0) (hl : q.natDegree < p.natDegree) : ¬p ∣ q := by by_contra hcontra exact h0 (eq_zero_of_dvd_of_natDegree_lt hcontra hl) /-- This lemma is useful for working with the `intDegree` of a rational function. -/ lemma natDegree_sub_eq_of_prod_eq {p₁ p₂ q₁ q₂ : R[X]} (hp₁ : p₁ ≠ 0) (hq₁ : q₁ ≠ 0) (hp₂ : p₂ ≠ 0) (hq₂ : q₂ ≠ 0) (h_eq : p₁ * q₂ = p₂ * q₁) : (p₁.natDegree : ℤ) - q₁.natDegree = (p₂.natDegree : ℤ) - q₂.natDegree := by rw [sub_eq_sub_iff_add_eq_add] norm_cast rw [← natDegree_mul hp₁ hq₂, ← natDegree_mul hp₂ hq₁, h_eq] end Semiring end Polynomial
test_rat.v
From mathcomp Require Import all_boot all_order all_algebra. Local Open Scope ring_scope. Goal 2%:Q + 2%:Q = 4%:Q. Proof. reflexivity. Qed. Goal - 2%:Q = -1 * 2%:Q. Proof. reflexivity. Qed. Goal 2%:Q ^+ 2 = 4%:Q. Proof. reflexivity. Qed. Goal (-1)^-1 = -1 :> rat. Proof. reflexivity. Qed. Local Open Scope rat_scope. Check 12. Check 3.14. Check -3.14. Check 0.5. Check 0.2.
Symmetric.lean
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn, Antoine Labelle, Rémi Bottinelli -/ import Mathlib.Combinatorics.Quiver.Path import Mathlib.Combinatorics.Quiver.Push /-! ## Symmetric quivers and arrow reversal This file contains constructions related to symmetric quivers: * `Symmetrify V` adds formal inverses to each arrow of `V`. * `HasReverse` is the class of quivers where each arrow has an assigned formal inverse. * `HasInvolutiveReverse` extends `HasReverse` by requiring that the reverse of the reverse is equal to the original arrow. * `Prefunctor.PreserveReverse` is the class of prefunctors mapping reverses to reverses. * `Symmetrify.of`, `Symmetrify.lift`, and the associated lemmas witness the universal property of `Symmetrify`. -/ universe v u w v' namespace Quiver /-- A type synonym for the symmetrized quiver (with an arrow both ways for each original arrow). NB: this does not work for `Prop`-valued quivers. It requires `[Quiver.{v+1} V]`. -/ def Symmetrify (V : Type*) := V instance symmetrifyQuiver (V : Type u) [Quiver V] : Quiver (Symmetrify V) := ⟨fun a b : V ↦ (a ⟶ b) ⊕ (b ⟶ a)⟩ variable (U V W : Type*) [Quiver.{u + 1} U] [Quiver.{v + 1} V] [Quiver.{w + 1} W] /-- A quiver `HasReverse` if we can reverse an arrow `p` from `a` to `b` to get an arrow `p.reverse` from `b` to `a`. -/ class HasReverse where /-- the map which sends an arrow to its reverse -/ reverse' : ∀ {a b : V}, (a ⟶ b) → (b ⟶ a) /-- Reverse the direction of an arrow. -/ def reverse {V} [Quiver.{v + 1} V] [HasReverse V] {a b : V} : (a ⟶ b) → (b ⟶ a) := HasReverse.reverse' /-- A quiver `HasInvolutiveReverse` if reversing twice is the identity. -/ class HasInvolutiveReverse extends HasReverse V where /-- `reverse` is involutive -/ inv' : ∀ {a b : V} (f : a ⟶ b), reverse (reverse f) = f variable {U V W} @[simp] theorem reverse_reverse [h : HasInvolutiveReverse V] {a b : V} (f : a ⟶ b) : reverse (reverse f) = f := by apply h.inv' @[simp] theorem reverse_inj [h : HasInvolutiveReverse V] {a b : V} (f g : a ⟶ b) : reverse f = reverse g ↔ f = g := by constructor · rintro h simpa using congr_arg Quiver.reverse h · rintro h congr theorem eq_reverse_iff [h : HasInvolutiveReverse V] {a b : V} (f : a ⟶ b) (g : b ⟶ a) : f = reverse g ↔ reverse f = g := by rw [← reverse_inj, reverse_reverse] section MapReverse variable [HasReverse U] [HasReverse V] [HasReverse W] /-- A prefunctor preserving reversal of arrows -/ class _root_.Prefunctor.MapReverse (φ : U ⥤q V) : Prop where /-- The image of a reverse is the reverse of the image. -/ map_reverse' : ∀ {u v : U} (e : u ⟶ v), φ.map (reverse e) = reverse (φ.map e) @[simp] theorem _root_.Prefunctor.map_reverse (φ : U ⥤q V) [φ.MapReverse] {u v : U} (e : u ⟶ v) : φ.map (reverse e) = reverse (φ.map e) := Prefunctor.MapReverse.map_reverse' e instance _root_.Prefunctor.mapReverseComp (φ : U ⥤q V) (ψ : V ⥤q W) [φ.MapReverse] [ψ.MapReverse] : (φ ⋙q ψ).MapReverse where map_reverse' e := by simp only [Prefunctor.comp_map, Prefunctor.MapReverse.map_reverse'] instance _root_.Prefunctor.mapReverseId : (Prefunctor.id U).MapReverse where map_reverse' _ := rfl end MapReverse instance : HasReverse (Symmetrify V) := ⟨fun e => e.swap⟩ instance : HasInvolutiveReverse (Symmetrify V) where toHasReverse := ⟨fun e ↦ e.swap⟩ inv' e := congr_fun Sum.swap_swap_eq e @[simp] theorem symmetrify_reverse {a b : Symmetrify V} (e : a ⟶ b) : reverse e = e.swap := rfl section Paths /-- Shorthand for the "forward" arrow corresponding to `f` in `symmetrify V` -/ abbrev Hom.toPos {X Y : V} (f : X ⟶ Y) : (Quiver.symmetrifyQuiver V).Hom X Y := Sum.inl f /-- Shorthand for the "backward" arrow corresponding to `f` in `symmetrify V` -/ abbrev Hom.toNeg {X Y : V} (f : X ⟶ Y) : (Quiver.symmetrifyQuiver V).Hom Y X := Sum.inr f /-- Reverse the direction of a path. -/ @[simp] def Path.reverse [HasReverse V] {a : V} : ∀ {b}, Path a b → Path b a | _, Path.nil => Path.nil | _, Path.cons p e => (Quiver.reverse e).toPath.comp p.reverse @[simp] theorem Path.reverse_toPath [HasReverse V] {a b : V} (f : a ⟶ b) : f.toPath.reverse = (Quiver.reverse f).toPath := rfl @[simp] theorem Path.reverse_comp [HasReverse V] {a b c : V} (p : Path a b) (q : Path b c) : (p.comp q).reverse = q.reverse.comp p.reverse := by induction q with | nil => simp | cons _ _ h => simp [h] @[simp] theorem Path.reverse_reverse [h : HasInvolutiveReverse V] {a b : V} (p : Path a b) : p.reverse.reverse = p := by induction p with | nil => simp | cons _ _ h => rw [Path.reverse, Path.reverse_comp, h, Path.reverse_toPath, Quiver.reverse_reverse] rfl end Paths namespace Symmetrify /-- The inclusion of a quiver in its symmetrification -/ @[simps] def of : Prefunctor V (Symmetrify V) where obj := id map := Sum.inl variable {V' : Type*} [Quiver.{v' + 1} V'] /-- Given a quiver `V'` with reversible arrows, a prefunctor to `V'` can be lifted to one from `Symmetrify V` to `V'` -/ def lift [HasReverse V'] (φ : Prefunctor V V') : Prefunctor (Symmetrify V) V' where obj := φ.obj map | Sum.inl g => φ.map g | Sum.inr g => reverse (φ.map g) theorem lift_spec [HasReverse V'] (φ : Prefunctor V V') : Symmetrify.of.comp (Symmetrify.lift φ) = φ := by fapply Prefunctor.ext · rintro X rfl · rintro X Y f rfl theorem lift_reverse [h : HasInvolutiveReverse V'] (φ : Prefunctor V V') {X Y : Symmetrify V} (f : X ⟶ Y) : (Symmetrify.lift φ).map (Quiver.reverse f) = Quiver.reverse ((Symmetrify.lift φ).map f) := by dsimp [Symmetrify.lift]; cases f · simp only rfl · simp only [reverse_reverse] rfl /-- `lift φ` is the only prefunctor extending `φ` and preserving reverses. -/ theorem lift_unique [HasReverse V'] (φ : V ⥤q V') (Φ : Symmetrify V ⥤q V') (hΦ : (of ⋙q Φ) = φ) (hΦinv : ∀ {X Y : Symmetrify V} (f : X ⟶ Y), Φ.map (Quiver.reverse f) = Quiver.reverse (Φ.map f)) : Φ = Symmetrify.lift φ := by subst_vars fapply Prefunctor.ext · rintro X rfl · rintro X Y f cases f · rfl · exact hΦinv (Sum.inl _) /-- A prefunctor canonically defines a prefunctor of the symmetrifications. -/ @[simps] def _root_.Prefunctor.symmetrify (φ : U ⥤q V) : Symmetrify U ⥤q Symmetrify V where obj := φ.obj map := Sum.map φ.map φ.map instance _root_.Prefunctor.symmetrify_mapReverse (φ : U ⥤q V) : Prefunctor.MapReverse φ.symmetrify := ⟨fun e => by cases e <;> rfl⟩ end Symmetrify namespace Push variable {V' : Type*} (σ : V → V') instance [HasReverse V] : HasReverse (Quiver.Push σ) where reverse' := fun | PushQuiver.arrow f => PushQuiver.arrow (reverse f) instance [h : HasInvolutiveReverse V] : HasInvolutiveReverse (Push σ) where reverse' := fun | PushQuiver.arrow f => PushQuiver.arrow (reverse f) inv' := fun | PushQuiver.arrow f => by dsimp [reverse]; congr; apply h.inv' theorem of_reverse [HasInvolutiveReverse V] (X Y : V) (f : X ⟶ Y) : (reverse <| (Push.of σ).map f) = (Push.of σ).map (reverse f) := rfl instance ofMapReverse [h : HasInvolutiveReverse V] : (Push.of σ).MapReverse := ⟨by simp [of_reverse]⟩ end Push /-- A quiver is preconnected iff there exists a path between any pair of vertices. Note that if `V` doesn't `HasReverse`, then the definition is stronger than simply having a preconnected underlying `SimpleGraph`, since a path in one direction doesn't induce one in the other. -/ def IsPreconnected (V) [Quiver.{u + 1} V] := ∀ X Y : V, Nonempty (Path X Y) end Quiver
PerfectSpace.lean
/- Copyright (c) 2025 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Topology.Perfect /-! # Vector spaces over nontrivially normed fields are perfect spaces -/ open Filter Set open scoped Topology variable (𝕜 E : Type*) [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [Nontrivial E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul 𝕜 E] include 𝕜 in lemma perfectSpace_of_module : PerfectSpace E := by refine ⟨fun x hx ↦ ?_⟩ let ⟨r, hr₀, hr⟩ := NormedField.exists_norm_lt_one 𝕜 obtain ⟨c, hc⟩ : ∃ (c : E), c ≠ 0 := exists_ne 0 have A : Tendsto (fun (n : ℕ) ↦ x + r ^ n • c) atTop (𝓝 (x + (0 : 𝕜) • c)) := by apply Tendsto.add tendsto_const_nhds exact (tendsto_pow_atTop_nhds_zero_of_norm_lt_one hr).smul tendsto_const_nhds have B : Tendsto (fun (n : ℕ) ↦ x + r ^ n • c) atTop (𝓝[univ \ {x}] x) := by simp only [zero_smul, add_zero] at A simp [tendsto_nhdsWithin_iff, A, hc, norm_pos_iff.mp hr₀] exact accPt_principal_iff_nhdsWithin.mpr ((atTop_neBot.map _).mono B) instance : PerfectSpace 𝕜 := perfectSpace_of_module 𝕜 𝕜
Extrema.lean
/- Copyright (c) 2020 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.Convex.Function import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.Order.LocalExtr import Mathlib.Topology.MetricSpace.Pseudo.Lemmas /-! # Minima and maxima of convex functions We show that if a function `f : E → β` is convex, then a local minimum is also a global minimum, and likewise for concave functions. -/ variable {E β : Type*} [AddCommGroup E] [TopologicalSpace E] [Module ℝ E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] [AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] [Module ℝ β] [OrderedSMul ℝ β] {s : Set E} open Set Filter Function Topology /-- Helper lemma for the more general case: `IsMinOn.of_isLocalMinOn_of_convexOn`. -/ theorem IsMinOn.of_isLocalMinOn_of_convexOn_Icc {f : ℝ → β} {a b : ℝ} (a_lt_b : a < b) (h_local_min : IsLocalMinOn f (Icc a b) a) (h_conv : ConvexOn ℝ (Icc a b) f) : IsMinOn f (Icc a b) a := by rintro c hc dsimp only [mem_setOf_eq] rw [IsLocalMinOn, nhdsWithin_Icc_eq_nhdsGE a_lt_b] at h_local_min rcases hc.1.eq_or_lt with (rfl | a_lt_c) · exact le_rfl have H₁ : ∀ᶠ y in 𝓝[>] a, f a ≤ f y := h_local_min.filter_mono (nhdsWithin_mono _ Ioi_subset_Ici_self) have H₂ : ∀ᶠ y in 𝓝[>] a, y ∈ Ioc a c := Ioc_mem_nhdsGT a_lt_c rcases (H₁.and H₂).exists with ⟨y, hfy, hy_ac⟩ rcases (Convex.mem_Ioc a_lt_c).mp hy_ac with ⟨ya, yc, ya₀, yc₀, yac, rfl⟩ suffices ya • f a + yc • f a ≤ ya • f a + yc • f c from (smul_le_smul_iff_of_pos_left yc₀).1 (le_of_add_le_add_left this) calc ya • f a + yc • f a = f a := by rw [← add_smul, yac, one_smul] _ ≤ f (ya * a + yc * c) := hfy _ ≤ ya • f a + yc • f c := h_conv.2 (left_mem_Icc.2 a_lt_b.le) hc ya₀ yc₀.le yac /-- A local minimum of a convex function is a global minimum, restricted to a set `s`. -/ theorem IsMinOn.of_isLocalMinOn_of_convexOn {f : E → β} {a : E} (a_in_s : a ∈ s) (h_localmin : IsLocalMinOn f s a) (h_conv : ConvexOn ℝ s f) : IsMinOn f s a := by intro x x_in_s let g : ℝ →ᵃ[ℝ] E := AffineMap.lineMap a x have hg0 : g 0 = a := AffineMap.lineMap_apply_zero a x have hg1 : g 1 = x := AffineMap.lineMap_apply_one a x have hgc : Continuous g := AffineMap.lineMap_continuous have h_maps : MapsTo g (Icc 0 1) s := by simpa only [g, mapsTo', ← segment_eq_image_lineMap] using h_conv.1.segment_subset a_in_s x_in_s have fg_local_min_on : IsLocalMinOn (f ∘ g) (Icc 0 1) 0 := by rw [← hg0] at h_localmin exact h_localmin.comp_continuousOn h_maps hgc.continuousOn (left_mem_Icc.2 zero_le_one) have fg_min_on : IsMinOn (f ∘ g) (Icc 0 1 : Set ℝ) 0 := by refine IsMinOn.of_isLocalMinOn_of_convexOn_Icc one_pos fg_local_min_on ?_ exact (h_conv.comp_affineMap g).subset h_maps (convex_Icc 0 1) simpa only [hg0, hg1, comp_apply, mem_setOf_eq] using fg_min_on (right_mem_Icc.2 zero_le_one) /-- A local maximum of a concave function is a global maximum, restricted to a set `s`. -/ theorem IsMaxOn.of_isLocalMaxOn_of_concaveOn {f : E → β} {a : E} (a_in_s : a ∈ s) (h_localmax : IsLocalMaxOn f s a) (h_conc : ConcaveOn ℝ s f) : IsMaxOn f s a := IsMinOn.of_isLocalMinOn_of_convexOn (β := βᵒᵈ) a_in_s h_localmax h_conc /-- A local minimum of a convex function is a global minimum. -/ theorem IsMinOn.of_isLocalMin_of_convex_univ {f : E → β} {a : E} (h_local_min : IsLocalMin f a) (h_conv : ConvexOn ℝ univ f) : ∀ x, f a ≤ f x := fun x => (IsMinOn.of_isLocalMinOn_of_convexOn (mem_univ a) (h_local_min.on univ) h_conv) (mem_univ x) /-- A local maximum of a concave function is a global maximum. -/ theorem IsMaxOn.of_isLocalMax_of_convex_univ {f : E → β} {a : E} (h_local_max : IsLocalMax f a) (h_conc : ConcaveOn ℝ univ f) : ∀ x, f x ≤ f a := IsMinOn.of_isLocalMin_of_convex_univ (β := βᵒᵈ) h_local_max h_conc
format_table.lean
import Mathlib.Util.FormatTable /-- info: | first | second header | third \| header | | :-------------- | :-------------: | --------------: | | item number one | item two | item c | | the fourth item | the fourth item | escape \| this | | align left | align center | align right | -/ #guard_msgs in run_cmd Lean.logInfo ("\n" ++ formatTable #["first", "second header", "third | header"] #[#["item number one", "item two", "item c"], #["the fourth item", "the fourth item", "escape | this"], #["align left", "align center", "align right"]] (.some #[.left, .center, .right]))
Trace.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.RingTheory.Trace.Basic import Mathlib.FieldTheory.Finite.GaloisField /-! # The trace and norm maps for finite fields We state several lemmas about the trace and norm maps for finite fields. ## Main Results - `trace_to_zmod_nondegenerate`: the trace map from a finite field of characteristic `p` to `ZMod p` is nondegenerate. - `algebraMap_trace_eq_sum_pow`: an explicit formula for the trace map: `trace[L/K](x) = ∑ i < [L:K], x ^ ((#K) ^ i)`. - `algebraMap_norm_eq_prod_pow`: an explicit formula for the norm map: `norm[L/K](x) = ∏ i < [L:K], x ^ ((#K) ^ i)`. ## Tags finite field, trace, norm -/ namespace FiniteField open Fintype /-- The trace map from a finite field to its prime field is nongedenerate. -/ theorem trace_to_zmod_nondegenerate (F : Type*) [Field F] [Finite F] [Algebra (ZMod (ringChar F)) F] {a : F} (ha : a ≠ 0) : ∃ b : F, Algebra.trace (ZMod (ringChar F)) F (a * b) ≠ 0 := by haveI : Fact (ringChar F).Prime := ⟨CharP.char_is_prime F _⟩ have htr := traceForm_nondegenerate (ZMod (ringChar F)) F a simp_rw [Algebra.traceForm_apply] at htr by_contra! hf exact ha (htr hf) variable (K L : Type*) [Field K] [Field L] [Finite L] [Algebra K L] (x : L) /-- An explicit formula for the trace map: `trace[L/K](x) = ∑ i < [L:K], x ^ ((#K) ^ i)`. -/ theorem algebraMap_trace_eq_sum_pow : algebraMap K L (Algebra.trace K L x) = ∑ i ∈ Finset.range (Module.finrank K L), x ^ (Nat.card K ^ i) := by have := Finite.of_injective _ (FaithfulSMul.algebraMap_injective K L) have := ofFinite K rw [trace_eq_sum_automorphisms, Finset.sum_range] exact Eq.symm <| sum_bijective _ (bijective_frobeniusAlgEquivOfAlgebraic_pow K L) _ _ <| fun i ↦ by rw [AlgEquiv.coe_pow, coe_frobeniusAlgEquivOfAlgebraic_iterate, card_eq_nat_card] /-- An explicit formula for the norm map: `norm[L/K](x) = ∏ i < [L:K], x ^ ((#K) ^ i)`. -/ theorem algebraMap_norm_eq_prod_pow : algebraMap K L (Algebra.norm K x) = ∏ i ∈ Finset.range (Module.finrank K L), x ^ (Nat.card K ^ i) := by have := Finite.of_injective _ (FaithfulSMul.algebraMap_injective K L) have := ofFinite K rw [Algebra.norm_eq_prod_automorphisms, Finset.prod_range] exact Eq.symm <| prod_bijective _ (bijective_frobeniusAlgEquivOfAlgebraic_pow K L) _ _ <| fun i ↦ by rw [AlgEquiv.coe_pow, coe_frobeniusAlgEquivOfAlgebraic_iterate, card_eq_nat_card] /-- An explicit formula for the norm map: `norm[L/K](x) = x ^ (∑ i < [L:K], (#K) ^ i)`. -/ theorem algebraMap_norm_eq_pow_sum : algebraMap K L (Algebra.norm K x) = x ^ ∑ i ∈ Finset.range (Module.finrank K L), Nat.card K ^ i := by rw [algebraMap_norm_eq_prod_pow, Finset.prod_pow_eq_pow_sum] end FiniteField
fintype.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool ssrnotations eqtype. From mathcomp Require Import ssrnat seq choice path div. (******************************************************************************) (* Finite types *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines an interface for finite types: *) (* *) (* finType == type with finitely many inhabitants *) (* The HB class is called Finite. *) (* subFinType P == join of finType and subType P *) (* The HB class is called SubFinite. *) (* *) (* The Finite interface describes Types with finitely many elements, *) (* supplying a duplicate-free sequence of all the elements. It is a subclass *) (* of Countable and thus of Choice and Equality. *) (* *) (* Bounded integers are supported by the following type and operations: *) (* *) (* 'I_n, ordinal n == the finite subType of integers i < n, whose *) (* enumeration is {0, ..., n.-1} *) (* 'I_n coerces to nat, so all the integer arithmetic *) (* functions can be used with 'I_n. *) (* Ordinal lt_i_n == the element of 'I_n with (nat) value i, given *) (* lt_i_n : i < n *) (* nat_of_ord i == the nat value of i : 'I_n (this function is a *) (* coercion so it is not usually displayed) *) (* ord_enum n == the explicit increasing sequence of the i : 'I_n *) (* cast_ord eq_n_m i == the element j : 'I_m with the same value as i : 'I_n *) (* given eq_n_m : n = m (indeed, i : nat and j : nat *) (* are convertible) *) (* ordS n i == the successor of i : 'I_n along the cyclic structure *) (* of 'I_n, reduces in nat to i.+1 %% n *) (* ord_pred n i == the predecessor of i : 'I_n along the cyclic *) (* structure of 'I_n, reduces in nat to (i + n).-1 %% n *) (* widen_ord le_n_m i == a j : 'I_m with the same value as i : 'I_n, given *) (* le_n_m : n <= m *) (* rev_ord i == the complement to n.-1 of i : 'I_n, such that *) (* i + rev_ord i = n.-1 *) (* inord k == the i : 'I_n.+1 with value k (n is inferred from the *) (* context) *) (* sub_ord k == the i : 'I_n.+1 with value n - k (n is inferred from *) (* the context) *) (* ord0 == the i : 'I_n.+1 with value 0 (n is inferred from the *) (* context) *) (* ord_max == the i : 'I_n.+1 with value n (n is inferred from the *) (* context) *) (* bump h k == k.+1 if k >= h, else k (this is a nat function) *) (* unbump h k == k.-1 if k > h, else k (this is a nat function) *) (* lift i j == the j' : 'I_n with value bump i j, where i : 'I_n *) (* and j : 'I_n.-1 *) (* unlift i j == None if i = j, else Some j', where j' : 'I_n.-1 has *) (* value unbump i j, given i, j : 'I_n *) (* lshift n j == the i : 'I_(m + n) with value j : 'I_m *) (* rshift m k == the i : 'I_(m + n) with value m + k, k : 'I_n *) (* unsplit u == either lshift n j or rshift m k, depending on *) (* whether if u : 'I_m + 'I_n is inl j or inr k *) (* split i == the u : 'I_m + 'I_n such that i = unsplit u; the *) (* type 'I_(m + n) of i determines the split *) (* *) (* Finally, every type T with a finType structure supports the following *) (* operations: *) (* *) (* enum A == a duplicate-free list of all the x \in A, where A is a *) (* collective predicate over T *) (* #|A| == the cardinal of A, i.e., the number of x \in A *) (* enum_val i == the i'th item of enum A, where i : 'I_(#|A|) *) (* enum_rank x == the i : 'I_(#|T|) such that enum_val i = x *) (* enum_rank_in Ax0 x == some i : 'I_(#|A|) such that enum_val i = x if *) (* x \in A, given Ax0 : x0 \in A *) (* A \subset B <=> all x \in A satisfy x \in B *) (* A \proper B <=> all x \in A satisfy x \in B but not the converse *) (* [disjoint A & B] <=> no x \in A satisfies x \in B *) (* image f A == the sequence of f x for all x : T such that x \in A *) (* (where A is an applicative predicate), of length #|A|. *) (* The codomain of F can be any type, but image f A can *) (* only be used as a collective predicate if it is an *) (* eqType *) (* codom f == a sequence spanning the codomain of f (:= image f T) *) (* [seq F | x : T in A] := image (fun x : T => F) A *) (* [seq F | x : T] := [seq F | x <- {: T}] *) (* [seq F | x in A], [seq F | x] == variants without casts *) (* iinv im_y == some x such that P x holds and f x = y, given *) (* im_y : y \in image f P *) (* invF inj_f y == the x such that f x = y, for inj_j : injective f with *) (* f : T -> T *) (* dinjectiveb A f <=> the restriction of f : T -> R to A is injective *) (* (this is a boolean predicate, R must be an eqType) *) (* injectiveb f <=> f : T -> R is injective (boolean predicate) *) (* pred0b A <=> no x : T satisfies x \in A *) (* [forall x, P] <=> P (in which x can appear) is true for all values of x *) (* x must range over a finType *) (* [exists x, P] <=> P is true for some value of x *) (* [forall (x | C), P] := [forall x, C ==> P] *) (* [forall x in A, P] := [forall (x | x \in A), P] *) (* [exists (x | C), P] := [exists x, C && P] *) (* [exists x in A, P] := [exists (x | x \in A), P] *) (* and typed variants [forall x : T, P], [forall (x : T | C), P], *) (* [exists x : T, P], [exists x : T in A, P], etc *) (* -> The outer brackets can be omitted when nesting finitary quantifiers, *) (* e.g., [forall i in I, forall j in J, exists a, f i j == a]. *) (* 'forall_pP <-> view for [forall x, p _], for pP : reflect .. (p _) *) (* 'exists_pP <-> view for [exists x, p _], for pP : reflect .. (p _) *) (* 'forall_in_pP <-> view for [forall x in .., p _], for pP as above *) (* 'exists_in_pP <-> view for [exists x in .., p _], for pP as above *) (* [pick x | P] == Some x, for an x such that P holds, or None if there *) (* is no such x *) (* [pick x : T] == Some x with x : T, provided T is nonempty, else None *) (* [pick x in A] == Some x, with x \in A, or None if A is empty *) (* [pick x in A | P] == Some x, with x \in A such that P holds, else None *) (* [pick x | P & Q] := [pick x | P & Q] *) (* [pick x in A | P & Q] := [pick x | P & Q] *) (* and (un)typed variants [pick x : T | P], [pick x : T in A], [pick x], etc *) (* [arg min_(i < i0 | P) M] == a value i : T minimizing M : nat, subject *) (* to the condition P (i may appear in P and M), and *) (* provided P holds for i0 *) (* [arg max_(i > i0 | P) M] == a value i maximizing M subject to P and *) (* provided P holds for i0 *) (* [arg min_(i < i0 in A) M] == an i \in A minimizing M if i0 \in A *) (* [arg max_(i > i0 in A) M] == an i \in A maximizing M if i0 \in A *) (* [arg min_(i < i0) M] == an i : T minimizing M, given i0 : T *) (* [arg max_(i > i0) M] == an i : T maximizing M, given i0 : T *) (* These are special instances of *) (* [arg[ord]_(i < i0 | P) F] == a value i : I, minimizing F wrt ord : rel T *) (* such that for all j : T, ord (F i) (F j) *) (* subject to the condition P, and provided P i0 *) (* where I : finType, T : eqType and F : I -> T *) (* [arg[ord]_(i < i0 in A) F] == an i \in A minimizing F wrt ord, if i0 \in A *) (* [arg[ord]_(i < i0) F] == an i : T minimizing F wrt ord, given i0 : T *) (* *) (* We define the following interfaces and structures: *) (* Finite.axiom e <-> every x : T occurs exactly once in e : seq T. *) (* [Finite of T by <:] == a finType structure for T, when T has a subType *) (* structure over an existing finType. *) (* We define or propagate the finType structure appropriately for all basic *) (* types : unit, bool, void, option, prod, sum, sig and sigT. We also define *) (* a generic type constructor for finite subtypes based on an explicit *) (* enumeration: *) (* seq_sub s == the subType of all x \in s, where s : seq T for some *) (* eqType T; seq_sub s has a canonical finType instance *) (* when T is a choiceType *) (* adhoc_seq_sub_choiceType s, adhoc_seq_sub_finType s == *) (* non-canonical instances for seq_sub s, s : seq T, *) (* which can be used when T is not a choiceType *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope fin_quant_scope. Definition finite_axiom (T : eqType) e := forall x : T, count_mem x e = 1. HB.mixin Record isFinite T of Equality T := { enum_subdef : seq T; enumP_subdef : finite_axiom enum_subdef }. (* Finiteness could be stated more simply by bounding the range of the pickle *) (* function supplied by the Countable interface, but this would yield *) (* a useless computational interpretation due to the wasteful Peano integer *) (* encodings. *) #[short(type="finType")] HB.structure Definition Finite := {T of isFinite T & Countable T }. (* As with Countable, the interface explicitly includes the somewhat redundant*) (* Equality, Choice and Countable superclasses to ensure the forgetful *) (* inheritance criterion is met. *) Module Export FiniteNES. Module Finite. HB.lock Definition enum T := isFinite.enum_subdef (Finite.class T). Notation axiom := finite_axiom. Lemma uniq_enumP (T : eqType) e : uniq e -> e =i T -> axiom e. Proof. by move=> Ue sT x; rewrite count_uniq_mem ?sT. Qed. Section WithCountType. Variable (T : countType) (n : nat). Definition count_enum := pmap (@pickle_inv T) (iota 0 n). Hypothesis ubT : forall x : T, pickle x < n. Lemma count_enumP : axiom count_enum. Proof. apply: uniq_enumP (pmap_uniq (@pickle_invK T) (iota_uniq _ _)) _ => x. by rewrite mem_pmap -pickleK_inv map_f // mem_iota ubT. Qed. End WithCountType. End Finite. Canonical finEnum_unlock := Unlockable Finite.enum.unlock. End FiniteNES. Section CanonicalFinType. Variable (T : eqType) (s : seq T). Definition fin_type of finite_axiom s : Type := T. Variable (f : finite_axiom s). Notation fT := (fin_type f). Definition fin_pickle (x : fT) : nat := index x s. Definition fin_unpickle (n : nat) : option fT := nth None (map some s) n. Lemma fin_pickleK : pcancel fin_pickle fin_unpickle. Proof. move=> x; rewrite /fin_pickle/fin_unpickle. rewrite -(index_map Some_inj) nth_index ?map_f//. by apply/count_memPn=> /eqP; rewrite f. Qed. HB.instance Definition _ := Equality.on fT. HB.instance Definition _ := isCountable.Build fT fin_pickleK. HB.instance Definition _ := isFinite.Build fT f. End CanonicalFinType. (* Workaround for the silly syntactic uniformity restriction on coercions; *) (* this avoids a cross-dependency between finset.v and prime.v for the *) (* definition of the \pi(A) notation. *) Definition fin_pred_sort (T : finType) (pT : predType T) := pred_sort pT. Identity Coercion pred_sort_of_fin : fin_pred_sort >-> pred_sort. Definition enum_mem T (mA : mem_pred _) := filter mA (Finite.enum T). Notation enum A := (enum_mem (mem A)). Definition pick (T : finType) (P : pred T) := ohead (enum P). Notation "[ 'pick' x | P ]" := (pick (fun x => P%B)) (x name, format "[ 'pick' x | P ]") : form_scope. Notation "[ 'pick' x : T | P ]" := (pick (fun x : T => P%B)) (x name, only parsing) : form_scope. Definition pick_true T (x : T) := true. Reserved Notation "[ 'pick' x : T ]" (x name, format "[ 'pick' x : T ]"). Notation "[ 'pick' x : T ]" := [pick x : T | pick_true x] (only parsing) : form_scope. Notation "[ 'pick' x : T ]" := [pick x : T | pick_true _] (only printing) : form_scope. Notation "[ 'pick' x ]" := [pick x : _] (x name, only parsing) : form_scope. Notation "[ 'pick' x | P & Q ]" := [pick x | P && Q ] (x name, format "[ '[hv ' 'pick' x | P '/ ' & Q ] ']'") : form_scope. Notation "[ 'pick' x : T | P & Q ]" := [pick x : T | P && Q ] (x name, only parsing) : form_scope. Notation "[ 'pick' x 'in' A ]" := [pick x | x \in A] (x name, format "[ 'pick' x 'in' A ]") : form_scope. Notation "[ 'pick' x : T 'in' A ]" := [pick x : T | x \in A] (x name, only parsing) : form_scope. Notation "[ 'pick' x 'in' A | P ]" := [pick x | x \in A & P ] (x name, format "[ '[hv ' 'pick' x 'in' A '/ ' | P ] ']'") : form_scope. Notation "[ 'pick' x : T 'in' A | P ]" := [pick x : T | x \in A & P ] (x name, only parsing) : form_scope. Notation "[ 'pick' x 'in' A | P & Q ]" := [pick x in A | P && Q] (x name, format "[ '[hv ' 'pick' x 'in' A '/ ' | P '/ ' & Q ] ']'") : form_scope. Notation "[ 'pick' x : T 'in' A | P & Q ]" := [pick x : T in A | P && Q] (x name, only parsing) : form_scope. (* We lock the definitions of card and subset to mitigate divergence of the *) (* Coq term comparison algorithm. *) HB.lock Definition card (T : finType) (mA : mem_pred T) := size (enum_mem mA). Canonical card_unlock := Unlockable card.unlock. (* A is at level 99 to allow the notation #|G : H| in groups. *) Notation "#| A |" := (card (mem A)) (A at level 99, format "#| A |") : nat_scope. Definition pred0b (T : finType) (P : pred T) := #|P| == 0. Prenex Implicits pred0b. Module FiniteQuant. Variant quantified := Quantified of bool. Delimit Scope fin_quant_scope with Q. (* Bogus, only used to declare scope. *) Bind Scope fin_quant_scope with quantified. Notation "F ^*" := (Quantified F). Section Definitions. Variable T : finType. Implicit Types (B : quantified) (x y : T). Definition quant0b Bp := pred0b [pred x : T | let: F^* := Bp x x in F]. (* The first redundant argument protects the notation from Coq's K-term *) (* display kludge; the second protects it from simpl and /=. *) Definition ex B x y := B. (* Binding the predicate value rather than projecting it prevents spurious *) (* unfolding of the boolean connectives by unification. *) Definition all B x y := let: F^* := B in (~~ F)^*. Definition all_in C B x y := let: F^* := B in (~~ (C ==> F))^*. Definition ex_in C B x y := let: F^* := B in (C && F)^*. End Definitions. Notation "[ x | B ]" := (quant0b (fun x => B x)) (x name). Notation "[ x : T | B ]" := (quant0b (fun x : T => B x)) (x name). Module Exports. Notation ", F" := F^* (at level 200, format ", '/ ' F") : fin_quant_scope. Notation "[ 'forall' x B ]" := [x | all B] (x at level 99, format "[ '[hv' 'forall' x B ] ']'") : bool_scope. Notation "[ 'forall' x : T B ]" := [x : T | all B] (only parsing) : bool_scope. Notation "[ 'forall' ( x | C ) B ]" := [x | all_in C B] (x at level 99, format "[ '[hv' '[' 'forall' ( x '/ ' | C ) ']' B ] ']'") : bool_scope. Notation "[ 'forall' ( x : T | C ) B ]" := [x : T | all_in C B] (x at level 99, only parsing) : bool_scope. Notation "[ 'forall' x 'in' A B ]" := [x | all_in (x \in A) B] (format "[ '[hv' '[' 'forall' x '/ ' 'in' A ']' B ] ']'") : bool_scope. Notation "[ 'forall' x : T 'in' A B ]" := [x : T | all_in (x \in A) B] (only parsing) : bool_scope. Notation ", 'forall' x B" := [x | all B]^* (at level 200, x at level 99, format ", '/ ' 'forall' x B") : fin_quant_scope. Notation ", 'forall' x : T B" := [x : T | all B]^* (only parsing) : fin_quant_scope. Notation ", 'forall' ( x | C ) B" := [x | all_in C B]^* (x at level 99, format ", '/ ' '[' 'forall' ( x '/ ' | C ) ']' B") : fin_quant_scope. Notation ", 'forall' ( x : T | C ) B" := [x : T | all_in C B]^* (only parsing) : fin_quant_scope. Notation ", 'forall' x 'in' A B" := [x | all_in (x \in A) B]^* (format ", '/ ' '[' 'forall' x '/ ' 'in' A ']' B") : bool_scope. Notation ", 'forall' x : T 'in' A B" := [x : T | all_in (x \in A) B]^* (only parsing) : bool_scope. Notation "[ 'exists' x B ]" := (~~ [x | ex B]) (x at level 99, format "[ '[hv' 'exists' x B ] ']'") : bool_scope. Notation "[ 'exists' x : T B ]" := (~~ [x : T | ex B]) (only parsing) : bool_scope. Notation "[ 'exists' ( x | C ) B ]" := (~~ [x | ex_in C B]) (x at level 99, format "[ '[hv' '[' 'exists' ( x '/ ' | C ) ']' B ] ']'") : bool_scope. Notation "[ 'exists' ( x : T | C ) B ]" := (~~ [x : T | ex_in C B]) (only parsing) : bool_scope. Notation "[ 'exists' x 'in' A B ]" := (~~ [x | ex_in (x \in A) B]) (format "[ '[hv' '[' 'exists' x '/ ' 'in' A ']' B ] ']'") : bool_scope. Notation "[ 'exists' x : T 'in' A B ]" := (~~ [x : T | ex_in (x \in A) B]) (only parsing) : bool_scope. Notation ", 'exists' x B" := (~~ [x | ex B])^* (x at level 99, format ", '/ ' 'exists' x B") : fin_quant_scope. Notation ", 'exists' x : T B" := (~~ [x : T | ex B])^* (only parsing) : fin_quant_scope. Notation ", 'exists' ( x | C ) B" := (~~ [x | ex_in C B])^* (x at level 99, format ", '/ ' '[' 'exists' ( x '/ ' | C ) ']' B") : fin_quant_scope. Notation ", 'exists' ( x : T | C ) B" := (~~ [x : T | ex_in C B])^* (only parsing) : fin_quant_scope. Notation ", 'exists' x 'in' A B" := (~~ [x | ex_in (x \in A) B])^* (format ", '/ ' '[' 'exists' x '/ ' 'in' A ']' B") : bool_scope. Notation ", 'exists' x : T 'in' A B" := (~~ [x : T | ex_in (x \in A) B])^* (only parsing) : bool_scope. End Exports. End FiniteQuant. Export FiniteQuant.Exports. Definition disjoint T (A B : mem_pred _) := @pred0b T (predI A B). Notation "[ 'disjoint' A & B ]" := (disjoint (mem A) (mem B)) (format "'[hv' [ 'disjoint' '/ ' A '/' & B ] ']'") : bool_scope. HB.lock Definition subset (T : finType) (A B : mem_pred T) : bool := pred0b (predD A B). Canonical subset_unlock := Unlockable subset.unlock. Notation "A \subset B" := (subset (mem A) (mem B)) (at level 70, no associativity) : bool_scope. Definition proper T A B := @subset T A B && ~~ subset B A. Notation "A \proper B" := (proper (mem A) (mem B)) (at level 70, no associativity) : bool_scope. (* image, xinv, inv, and ordinal operations will be defined later. *) Section OpsTheory. Variable T : finType. Implicit Types (A B C D : {pred T}) (P Q : pred T) (x y : T) (s : seq T). Lemma enumP : Finite.axiom (Finite.enum T). Proof. by rewrite unlock; apply: enumP_subdef. Qed. Section EnumPick. Variable P : pred T. Lemma enumT : enum T = Finite.enum T. Proof. exact: filter_predT. Qed. Lemma mem_enum A : enum A =i A. Proof. by move=> x; rewrite mem_filter andbC -has_pred1 has_count enumP. Qed. Lemma enum_uniq A : uniq (enum A). Proof. by apply/filter_uniq/count_mem_uniq => x; rewrite enumP -enumT mem_enum. Qed. Lemma enum0 : enum pred0 = Nil T. Proof. exact: filter_pred0. Qed. Lemma enum1 x : enum (pred1 x) = [:: x]. Proof. rewrite [enum _](all_pred1P x _ _); first by rewrite size_filter enumP. by apply/allP=> y; rewrite mem_enum. Qed. Variant pick_spec : option T -> Type := | Pick x of P x : pick_spec (Some x) | Nopick of P =1 xpred0 : pick_spec None. Lemma pickP : pick_spec (pick P). Proof. rewrite /pick; case: (enum _) (mem_enum P) => [|x s] Pxs /=. by right; apply: fsym. by left; rewrite -[P _]Pxs mem_head. Qed. End EnumPick. Lemma eq_enum A B : A =i B -> enum A = enum B. Proof. by move=> eqAB; apply: eq_filter. Qed. Lemma eq_pick P Q : P =1 Q -> pick P = pick Q. Proof. by move=> eqPQ; rewrite /pick (eq_enum eqPQ). Qed. Lemma cardE A : #|A| = size (enum A). Proof. by rewrite unlock. Qed. Lemma eq_card A B : A =i B -> #|A| = #|B|. Proof. by move=> eqAB; rewrite !cardE (eq_enum eqAB). Qed. Lemma eq_card_trans A B n : #|A| = n -> B =i A -> #|B| = n. Proof. by move <-; apply: eq_card. Qed. Lemma card0 : #|@pred0 T| = 0. Proof. by rewrite cardE enum0. Qed. Lemma cardT : #|T| = size (enum T). Proof. by rewrite cardE. Qed. Lemma card1 x : #|pred1 x| = 1. Proof. by rewrite cardE enum1. Qed. Lemma eq_card0 A : A =i pred0 -> #|A| = 0. Proof. exact: eq_card_trans card0. Qed. Lemma eq_cardT A : A =i predT -> #|A| = size (enum T). Proof. exact: eq_card_trans cardT. Qed. Lemma eq_card1 x A : A =i pred1 x -> #|A| = 1. Proof. exact: eq_card_trans (card1 x). Qed. Lemma cardUI A B : #|[predU A & B]| + #|[predI A & B]| = #|A| + #|B|. Proof. by rewrite !cardE !size_filter count_predUI. Qed. Lemma cardID B A : #|[predI A & B]| + #|[predD A & B]| = #|A|. Proof. rewrite -cardUI addnC [#|predI _ _|]eq_card0 => [|x] /=. by apply: eq_card => x; rewrite !inE andbC -andb_orl orbN. by rewrite !inE -!andbA andbC andbA andbN. Qed. Lemma cardC A : #|A| + #|[predC A]| = #|T|. Proof. by rewrite !cardE !size_filter count_predC. Qed. Lemma cardU1 x A : #|[predU1 x & A]| = (x \notin A) + #|A|. Proof. case Ax: (x \in A). by apply: eq_card => y /[1!inE]/=; case: eqP => // ->. rewrite /= -(card1 x) -cardUI addnC. rewrite [#|predI _ _|]eq_card0 => [|y /=]; first exact: eq_card. by rewrite !inE; case: eqP => // ->. Qed. Lemma card2 x y : #|pred2 x y| = (x != y).+1. Proof. by rewrite cardU1 card1 addn1. Qed. Lemma cardC1 x : #|predC1 x| = #|T|.-1. Proof. by rewrite -(cardC (pred1 x)) card1. Qed. Lemma cardD1 x A : #|A| = (x \in A) + #|[predD1 A & x]|. Proof. case Ax: (x \in A); last first. by apply: eq_card => y /[!inE]/=; case: eqP => // ->. rewrite /= -(card1 x) -cardUI addnC /=. rewrite [#|predI _ _|]eq_card0 => [|y]; last by rewrite !inE; case: eqP. by apply: eq_card => y /[!inE]; case: eqP => // ->. Qed. Lemma max_card A : #|A| <= #|T|. Proof. by rewrite -(cardC A) leq_addr. Qed. Lemma card_size s : #|s| <= size s. Proof. elim: s => [|x s IHs] /=; first by rewrite card0. by rewrite cardU1 /=; case: (~~ _) => //; apply: leqW. Qed. Lemma card_uniqP s : reflect (#|s| = size s) (uniq s). Proof. elim: s => [|x s IHs]; first by left; apply: card0. rewrite cardU1 /= /addn; case: {+}(x \in s) => /=. by right=> card_Ssz; have:= card_size s; rewrite card_Ssz ltnn. by apply: (iffP IHs) => [<-| [<-]]. Qed. Lemma card0_eq A : #|A| = 0 -> A =i pred0. Proof. by move=> A0 x; apply/idP => Ax; rewrite (cardD1 x) Ax in A0. Qed. Lemma fintype0 : T -> #|T| <> 0. Proof. by move=> x /card0_eq/(_ x). Qed. Lemma pred0P P : reflect (P =1 pred0) (pred0b P). Proof. by apply: (iffP eqP); [apply: card0_eq | apply: eq_card0]. Qed. Lemma pred0Pn P : reflect (exists x, P x) (~~ pred0b P). Proof. case: (pickP P) => [x Px | P0]. by rewrite (introN (pred0P P)) => [|P0]; [left; exists x | rewrite P0 in Px]. by rewrite -lt0n eq_card0 //; right=> [[x]]; rewrite P0. Qed. Lemma card_gt0P A : reflect (exists i, i \in A) (#|A| > 0). Proof. by rewrite lt0n; apply: pred0Pn. Qed. Lemma card_le1P {A} : reflect {in A, forall x, A =i pred1 x} (#|A| <= 1). Proof. apply: (iffP idP) => [A1 x xA y|]; last first. by have [/= x xA /(_ _ xA)/eq_card1->|/eq_card0->//] := pickP [in A]. move: A1; rewrite (cardD1 x) xA ltnS leqn0 => /eqP/card0_eq/(_ y). by rewrite !inE; have [->|]:= eqP. Qed. Lemma mem_card1 A : #|A| = 1 -> {x | A =i pred1 x}. Proof. move=> A1; have /card_gt0P/sigW[x xA]: #|A| > 0 by rewrite A1. by exists x; apply/card_le1P; rewrite ?A1. Qed. Lemma card1P A : reflect (exists x, A =i pred1 x) (#|A| == 1). Proof. by apply: (iffP idP) => [/eqP/mem_card1[x inA]|[x /eq_card1/eqP//]]; exists x. Qed. Lemma card_le1_eqP A : reflect {in A &, forall x, all_equal_to x} (#|A| <= 1). Proof. apply: (iffP card_le1P) => [Ale1 x y xA yA /=|all_eq x xA y]. by apply/eqP; rewrite -[_ == _]/(y \in pred1 x) -Ale1. by rewrite inE; case: (altP (y =P x)) => [->//|]; exact/contra_neqF/all_eq. Qed. Lemma fintype_le1P : reflect (forall x : T, all_equal_to x) (#|T| <= 1). Proof. apply: (iffP (card_le1_eqP {:T})); [exact: in2T | exact: in2W]. Qed. Lemma fintype1 : #|T| = 1 -> {x : T | all_equal_to x}. Proof. by move=> /mem_card1[x ex]; exists x => y; suff: y \in T by rewrite ex => /eqP. Qed. Lemma fintype1P : reflect (exists x, all_equal_to x) (#|T| == 1). Proof. apply: (iffP idP) => [/eqP/fintype1|] [x eqx]; first by exists x. by apply/card1P; exists x => y; rewrite eqx !inE eqxx. Qed. Lemma subsetE A B : (A \subset B) = pred0b [predD A & B]. Proof. by rewrite unlock. Qed. Lemma subsetP A B : reflect {subset A <= B} (A \subset B). Proof. rewrite unlock; apply: (iffP (pred0P _)) => [AB0 x | sAB x /=]. by apply/implyP; apply/idPn; rewrite negb_imply andbC [_ && _]AB0. by rewrite andbC -negb_imply; apply/negbF/implyP; apply: sAB. Qed. Lemma subsetPn A B : reflect (exists2 x, x \in A & x \notin B) (~~ (A \subset B)). Proof. rewrite unlock; apply: (iffP (pred0Pn _)) => [[x] | [x Ax nBx]]. by case/andP; exists x. by exists x; rewrite /= nBx. Qed. Lemma subset_leq_card A B : A \subset B -> #|A| <= #|B|. Proof. move=> sAB. rewrite -(cardID A B) [#|predI _ _|](@eq_card _ A) ?leq_addr //= => x. by rewrite !inE andbC; case Ax: (x \in A) => //; apply: subsetP Ax. Qed. Lemma subxx_hint (mA : mem_pred T) : subset mA mA. Proof. by case: mA => A; have:= introT (subsetP A A); rewrite !unlock => ->. Qed. Hint Resolve subxx_hint : core. (* The parametrization by predType makes it easier to apply subxx. *) Lemma subxx (pT : predType T) (pA : pT) : pA \subset pA. Proof. by []. Qed. Lemma eq_subset A B : A =i B -> subset (mem A) =1 subset (mem B). Proof. move=> eqAB [C]; rewrite !unlock; congr (_ == 0). by apply: eq_card => x; rewrite inE /= eqAB. Qed. Lemma eq_subset_r A B : A =i B -> (@subset T)^~ (mem A) =1 (@subset T)^~ (mem B). Proof. move=> eqAB [C]; rewrite !unlock; congr (_ == 0). by apply: eq_card => x; rewrite !inE /= eqAB. Qed. Lemma eq_subxx A B : A =i B -> A \subset B. Proof. by move/eq_subset->. Qed. Lemma subset_predT A : A \subset T. Proof. exact/subsetP. Qed. Lemma predT_subset A : T \subset A -> forall x, x \in A. Proof. by move/subsetP=> allA x; apply: allA. Qed. Lemma subset_pred1 A x : (pred1 x \subset A) = (x \in A). Proof. by apply/subsetP/idP=> [-> // | Ax y /eqP-> //]; apply: eqxx. Qed. Lemma subset_eqP A B : reflect (A =i B) ((A \subset B) && (B \subset A)). Proof. apply: (iffP andP) => [[sAB sBA] x| eqAB]; last by rewrite !eq_subxx. by apply/idP/idP; apply: subsetP. Qed. Lemma subset_cardP A B : #|A| = #|B| -> reflect (A =i B) (A \subset B). Proof. move=> eqcAB; case: (subsetP A B) (subset_eqP A B) => //= sAB. case: (subsetP B A) => [//|[]] x Bx; apply/idPn => Ax. case/idP: (ltnn #|A|); rewrite {2}eqcAB (cardD1 x B) Bx /=. apply: subset_leq_card; apply/subsetP=> y Ay; rewrite inE /= andbC. by rewrite sAB //; apply/eqP => eqyx; rewrite -eqyx Ay in Ax. Qed. Lemma subset_leqif_card A B : A \subset B -> #|A| <= #|B| ?= iff (B \subset A). Proof. move=> sAB; split; [exact: subset_leq_card | apply/eqP/idP]. by move/subset_cardP=> sABP; rewrite (eq_subset_r (sABP sAB)). by move=> sBA; apply: eq_card; apply/subset_eqP; rewrite sAB. Qed. Lemma subset_trans A B C : A \subset B -> B \subset C -> A \subset C. Proof. by move/subsetP=> sAB /subsetP=> sBC; apply/subsetP=> x /sAB; apply: sBC. Qed. Lemma subset_all s A : (s \subset A) = all [in A] s. Proof. exact: (sameP (subsetP _ _) allP). Qed. Lemma subset_cons s x : s \subset x :: s. Proof. by apply/subsetP => y /[!inE] ->; rewrite orbT. Qed. Lemma subset_cons2 s1 s2 x : s1 \subset s2 -> x :: s1 \subset x :: s2. Proof. by move=> ?; apply/subsetP => y /[!inE]; case: eqP => // _; apply: subsetP. Qed. Lemma subset_catl s s' : s \subset s ++ s'. Proof. by apply/subsetP=> x xins; rewrite mem_cat xins. Qed. Lemma subset_catr s s' : s \subset s' ++ s. Proof. by apply/subsetP => x xins; rewrite mem_cat xins orbT. Qed. Lemma subset_cat2 s1 s2 s3 : s1 \subset s2 -> s3 ++ s1 \subset s3 ++ s2. Proof. move=> /subsetP s12; apply/subsetP => x. by rewrite !mem_cat => /orP[->|/s12->]; rewrite ?orbT. Qed. Lemma filter_subset p s : [seq a <- s | p a] \subset s. Proof. by apply/subsetP=> x; rewrite mem_filter => /andP[]. Qed. Lemma subset_filter p s1 s2 : s1 \subset s2 -> [seq a <- s1 | p a] \subset [seq a <- s2 | p a]. Proof. by move/subsetP=> s12; apply/subsetP=> x; rewrite !mem_filter=> /andP[-> /s12]. Qed. Lemma properE A B : A \proper B = (A \subset B) && ~~ (B \subset A). Proof. by []. Qed. Lemma properP A B : reflect (A \subset B /\ (exists2 x, x \in B & x \notin A)) (A \proper B). Proof. by rewrite properE; apply: (iffP andP) => [] [-> /subsetPn]. Qed. Lemma proper_sub A B : A \proper B -> A \subset B. Proof. by case/andP. Qed. Lemma proper_subn A B : A \proper B -> ~~ (B \subset A). Proof. by case/andP. Qed. Lemma proper_trans A B C : A \proper B -> B \proper C -> A \proper C. Proof. case/properP=> sAB [x Bx nAx] /properP[sBC [y Cy nBy]]. rewrite properE (subset_trans sAB) //=; apply/subsetPn; exists y => //. by apply: contra nBy; apply: subsetP. Qed. Lemma proper_sub_trans A B C : A \proper B -> B \subset C -> A \proper C. Proof. case/properP=> sAB [x Bx nAx] sBC; rewrite properE (subset_trans sAB) //. by apply/subsetPn; exists x; rewrite ?(subsetP _ _ sBC). Qed. Lemma sub_proper_trans A B C : A \subset B -> B \proper C -> A \proper C. Proof. move=> sAB /properP[sBC [x Cx nBx]]; rewrite properE (subset_trans sAB) //. by apply/subsetPn; exists x => //; apply: contra nBx; apply: subsetP. Qed. Lemma proper_card A B : A \proper B -> #|A| < #|B|. Proof. by case/andP=> sAB nsBA; rewrite ltn_neqAle !(subset_leqif_card sAB) andbT. Qed. Lemma proper_irrefl A : ~~ (A \proper A). Proof. by rewrite properE subxx. Qed. Lemma properxx A : (A \proper A) = false. Proof. by rewrite properE subxx. Qed. Lemma eq_proper A B : A =i B -> proper (mem A) =1 proper (mem B). Proof. move=> eAB [C]; congr (_ && _); first exact: (eq_subset eAB). by rewrite (eq_subset_r eAB). Qed. Lemma eq_proper_r A B : A =i B -> (@proper T)^~ (mem A) =1 (@proper T)^~ (mem B). Proof. move=> eAB [C]; congr (_ && _); first exact: (eq_subset_r eAB). by rewrite (eq_subset eAB). Qed. Lemma card_geqP {A n} : reflect (exists s, [/\ uniq s, size s = n & {subset s <= A}]) (n <= #|A|). Proof. apply: (iffP idP) => [n_le_A|[s] [uniq_s size_s /subsetP subA]]; last first. by rewrite -size_s -(card_uniqP _ uniq_s); exact: subset_leq_card. exists (take n (enum A)); rewrite take_uniq ?enum_uniq // size_take. split => //; last by move => x /mem_take; rewrite mem_enum. case: (ltnP n (size (enum A))) => // size_A. by apply/eqP; rewrite eqn_leq size_A -cardE n_le_A. Qed. Lemma card_gt1P A : reflect (exists x y, [/\ x \in A, y \in A & x != y]) (1 < #|A|). Proof. apply: (iffP card_geqP) => [[s] []|[x] [y] [xA yA xDy]]. case: s => [|a [|b []]]//= /[!(inE, andbT)] aDb _ subD. by exists a, b; rewrite aDb !subD ?inE ?eqxx ?orbT. by exists [:: x; y]; rewrite /= !inE xDy; split=> // z /[!inE] /pred2P[]->. Qed. Lemma card_gt2P A : reflect (exists x y z, [/\ x \in A, y \in A & z \in A] /\ [/\ x != y, y != z & z != x]) (2 < #|A|). Proof. apply: (iffP card_geqP) => [[s] []|[x] [y] [z] [[xD yD zD] [xDy xDz yDz]]]. case: s => [|x [|y [|z []]]]//=; rewrite !inE !andbT negb_or -andbA. case/and3P => xDy xDz yDz _ subA. by exists x, y, z; rewrite xDy yDz eq_sym xDz !subA ?inE ?eqxx ?orbT. exists [:: x; y; z]; rewrite /= !inE negb_or xDy xDz eq_sym yDz; split=> // u. by rewrite !inE => /or3P [] /eqP->. Qed. Lemma disjoint_sym A B : [disjoint A & B] = [disjoint B & A]. Proof. by congr (_ == 0); apply: eq_card => x; apply: andbC. Qed. Lemma eq_disjoint A B : A =i B -> disjoint (mem A) =1 disjoint (mem B). Proof. by move=> eqAB [C]; congr (_ == 0); apply: eq_card => x; rewrite !inE eqAB. Qed. Lemma eq_disjoint_r A B : A =i B -> (@disjoint T)^~ (mem A) =1 (@disjoint T)^~ (mem B). Proof. by move=> eqAB [C]; congr (_ == 0); apply: eq_card => x; rewrite !inE eqAB. Qed. Lemma subset_disjoint A B : (A \subset B) = [disjoint A & [predC B]]. Proof. by rewrite disjoint_sym unlock. Qed. Lemma disjoint_subset A B : [disjoint A & B] = (A \subset [predC B]). Proof. by rewrite subset_disjoint; apply: eq_disjoint_r => x; rewrite !inE /= negbK. Qed. Lemma disjointFr A B x : [disjoint A & B] -> x \in A -> x \in B = false. Proof. by move/pred0P/(_ x) => /=; case: (x \in A). Qed. Lemma disjointFl A B x : [disjoint A & B] -> x \in B -> x \in A = false. Proof. rewrite disjoint_sym; exact: disjointFr. Qed. Lemma disjointWl A B C : A \subset B -> [disjoint B & C] -> [disjoint A & C]. Proof. by rewrite 2!disjoint_subset; apply: subset_trans. Qed. Lemma disjointWr A B C : A \subset B -> [disjoint C & B] -> [disjoint C & A]. Proof. rewrite ![[disjoint C & _]]disjoint_sym. exact:disjointWl. Qed. Lemma disjointW A B C D : A \subset B -> C \subset D -> [disjoint B & D] -> [disjoint A & C]. Proof. by move=> subAB subCD BD; apply/(disjointWl subAB)/(disjointWr subCD). Qed. Lemma disjoint0 A : [disjoint pred0 & A]. Proof. exact/pred0P. Qed. Lemma eq_disjoint0 A B : A =i pred0 -> [disjoint A & B]. Proof. by move/eq_disjoint->; apply: disjoint0. Qed. Lemma disjoint1 x A : [disjoint pred1 x & A] = (x \notin A). Proof. apply/negbRL/(sameP (pred0Pn _))=> /=. apply: introP => [Ax | notAx [_ /andP[/eqP->]]]; last exact: negP. by exists x; rewrite inE eqxx. Qed. Lemma eq_disjoint1 x A B : A =i pred1 x -> [disjoint A & B] = (x \notin B). Proof. by move/eq_disjoint->; apply: disjoint1. Qed. Lemma disjointU A B C : [disjoint predU A B & C] = [disjoint A & C] && [disjoint B & C]. Proof. case: [disjoint A & C] / (pred0P (xpredI A C)) => [A0 | nA0] /=. by congr (_ == 0); apply: eq_card => x; rewrite [x \in _]andb_orl A0. apply/pred0P=> nABC; case: nA0 => x; apply/idPn=> /=; move/(_ x): nABC. by rewrite [_ x]andb_orl; case/norP. Qed. Lemma disjointU1 x A B : [disjoint predU1 x A & B] = (x \notin B) && [disjoint A & B]. Proof. by rewrite disjointU disjoint1. Qed. Lemma disjoint_cons x s B : [disjoint x :: s & B] = (x \notin B) && [disjoint s & B]. Proof. exact: disjointU1. Qed. Lemma disjoint_has s A : [disjoint s & A] = ~~ has [in A] s. Proof. apply/negbRL; apply/pred0Pn/hasP => [[x /andP[]]|[x]]; exists x => //. exact/andP. Qed. Lemma disjoint_cat s1 s2 A : [disjoint s1 ++ s2 & A] = [disjoint s1 & A] && [disjoint s2 & A]. Proof. by rewrite !disjoint_has has_cat negb_or. Qed. End OpsTheory. Lemma map_subset {T T' : finType} (s1 s2 : seq T) (f : T -> T') : s1 \subset s2 -> [seq f x | x <- s1 ] \subset [seq f x | x <- s2]. Proof. move=> s1s2; apply/subsetP => _ /mapP[y] /[swap] -> ys1. by apply/mapP; exists y => //; move/subsetP : s1s2; exact. Qed. #[global] Hint Resolve subxx_hint : core. Arguments pred0P {T P}. Arguments pred0Pn {T P}. Arguments card_le1P {T A}. Arguments card_le1_eqP {T A}. Arguments card1P {T A}. Arguments fintype_le1P {T}. Arguments fintype1P {T}. Arguments subsetP {T A B}. Arguments subsetPn {T A B}. Arguments subset_eqP {T A B}. Arguments card_uniqP {T s}. Arguments card_geqP {T A n}. Arguments card_gt0P {T A}. Arguments card_gt1P {T A}. Arguments card_gt2P {T A}. Arguments properP {T A B}. (**********************************************************************) (* *) (* Boolean quantifiers for finType *) (* *) (**********************************************************************) Section QuantifierCombinators. Variables (T : finType) (P : pred T) (PP : T -> Prop). Hypothesis viewP : forall x, reflect (PP x) (P x). Lemma existsPP : reflect (exists x, PP x) [exists x, P x]. Proof. by apply: (iffP pred0Pn) => -[x /viewP]; exists x. Qed. Lemma forallPP : reflect (forall x, PP x) [forall x, P x]. Proof. by apply: (iffP pred0P) => /= allP x; have /viewP//=-> := allP x. Qed. End QuantifierCombinators. Notation "'exists_ view" := (existsPP (fun _ => view)) (at level 4, right associativity, format "''exists_' view"). Notation "'forall_ view" := (forallPP (fun _ => view)) (at level 4, right associativity, format "''forall_' view"). Section Quantifiers. Variables (T : finType) (rT : T -> eqType). Implicit Types (D P : pred T) (f : forall x, rT x). Lemma forallP P : reflect (forall x, P x) [forall x, P x]. Proof. exact: 'forall_idP. Qed. Lemma eqfunP f1 f2 : reflect (forall x, f1 x = f2 x) [forall x, f1 x == f2 x]. Proof. exact: 'forall_eqP. Qed. Lemma forall_inP D P : reflect (forall x, D x -> P x) [forall (x | D x), P x]. Proof. exact: 'forall_implyP. Qed. Lemma forall_inPP D P PP : (forall x, reflect (PP x) (P x)) -> reflect (forall x, D x -> PP x) [forall (x | D x), P x]. Proof. by move=> vP; apply: (iffP (forall_inP _ _)) => /(_ _ _) /vP. Qed. Lemma eqfun_inP D f1 f2 : reflect {in D, forall x, f1 x = f2 x} [forall (x | x \in D), f1 x == f2 x]. Proof. exact: (forall_inPP _ (fun=> eqP)). Qed. Lemma existsP P : reflect (exists x, P x) [exists x, P x]. Proof. exact: 'exists_idP. Qed. Lemma existsb P (x : T) : P x -> [exists x, P x]. Proof. by move=> Px; apply/existsP; exists x. Qed. Lemma exists_eqP f1 f2 : reflect (exists x, f1 x = f2 x) [exists x, f1 x == f2 x]. Proof. exact: 'exists_eqP. Qed. Lemma exists_inP D P : reflect (exists2 x, D x & P x) [exists (x | D x), P x]. Proof. by apply: (iffP 'exists_andP) => [[x []] | [x]]; exists x. Qed. Lemma exists_inb D P (x : T) : D x -> P x -> [exists (x | D x), P x]. Proof. by move=> Dx Px; apply/exists_inP; exists x. Qed. Lemma exists_inPP D P PP : (forall x, reflect (PP x) (P x)) -> reflect (exists2 x, D x & PP x) [exists (x | D x), P x]. Proof. by move=> vP; apply: (iffP (exists_inP _ _)) => -[x?/vP]; exists x. Qed. Lemma exists_eq_inP D f1 f2 : reflect (exists2 x, D x & f1 x = f2 x) [exists (x | D x), f1 x == f2 x]. Proof. exact: (exists_inPP _ (fun=> eqP)). Qed. Lemma eq_existsb P1 P2 : P1 =1 P2 -> [exists x, P1 x] = [exists x, P2 x]. Proof. by move=> eqP12; congr (_ != 0); apply: eq_card. Qed. Lemma eq_existsb_in D P1 P2 : (forall x, D x -> P1 x = P2 x) -> [exists (x | D x), P1 x] = [exists (x | D x), P2 x]. Proof. by move=> eqP12; apply: eq_existsb => x; apply: andb_id2l => /eqP12. Qed. Lemma eq_forallb P1 P2 : P1 =1 P2 -> [forall x, P1 x] = [forall x, P2 x]. Proof. by move=> eqP12; apply/negb_inj/eq_existsb=> /= x; rewrite eqP12. Qed. Lemma eq_forallb_in D P1 P2 : (forall x, D x -> P1 x = P2 x) -> [forall (x | D x), P1 x] = [forall (x | D x), P2 x]. Proof. by move=> eqP12; apply: eq_forallb => i; case Di: (D i); rewrite // eqP12. Qed. Lemma existsbWl P Q : [exists x, P x && Q x] -> [exists x, P x]. Proof. move => /existsP ; case => x /andP [H _] ; apply/existsP ; by exists x. Qed. Lemma existsbWr P Q : [exists x, P x && Q x] -> [exists x, Q x]. Proof. move => /existsP ; case => x /andP [_ H] ; apply/existsP ; by exists x. Qed. Lemma negb_forall P : ~~ [forall x, P x] = [exists x, ~~ P x]. Proof. by []. Qed. Lemma negb_forall_in D P : ~~ [forall (x | D x), P x] = [exists (x | D x), ~~ P x]. Proof. by apply: eq_existsb => x; rewrite negb_imply. Qed. Lemma negb_exists P : ~~ [exists x, P x] = [forall x, ~~ P x]. Proof. by apply/negbLR/esym/eq_existsb=> x; apply: negbK. Qed. Lemma negb_exists_in D P : ~~ [exists (x | D x), P x] = [forall (x | D x), ~~ P x]. Proof. by rewrite negb_exists; apply/eq_forallb => x; rewrite [~~ _]fun_if. Qed. Lemma existsPn P : reflect (forall x, ~~ P x) (~~ [exists x, P x]). Proof. rewrite negb_exists. exact: forallP. Qed. Lemma forallPn P : reflect (exists x, ~~ P x) (~~ [forall x, P x]). Proof. rewrite negb_forall. exact: existsP. Qed. Lemma exists_inPn D P : reflect (forall x, x \in D -> ~~ P x) (~~ [exists x in D, P x]). Proof. rewrite negb_exists_in. exact: forall_inP. Qed. Lemma forall_inPn D P : reflect (exists2 x, x \in D & ~~ P x) (~~ [forall x in D, P x]). Proof. rewrite negb_forall_in. exact: exists_inP. Qed. End Quantifiers. Arguments forallP {T P}. Arguments eqfunP {T rT f1 f2}. Arguments forall_inP {T D P}. Arguments eqfun_inP {T rT D f1 f2}. Arguments existsP {T P}. Arguments existsb {T P}. Arguments exists_eqP {T rT f1 f2}. Arguments exists_inP {T D P}. Arguments exists_inb {T D P}. Arguments exists_eq_inP {T rT D f1 f2}. Arguments existsPn {T P}. Arguments exists_inPn {T D P}. Arguments forallPn {T P}. Arguments forall_inPn {T D P}. Notation "'exists_in_ view" := (exists_inPP _ (fun _ => view)) (at level 4, right associativity, format "''exists_in_' view"). Notation "'forall_in_ view" := (forall_inPP _ (fun _ => view)) (at level 4, right associativity, format "''forall_in_' view"). (**********************************************************************) (* *) (* Boolean injectivity test for functions with a finType domain *) (* *) (**********************************************************************) Section Injectiveb. Variables (aT : finType) (rT : eqType). Implicit Type (f : aT -> rT) (D : {pred aT}). Definition dinjectiveb f D := uniq (map f (enum D)). Definition injectiveb f := dinjectiveb f aT. Lemma dinjectivePn f D : reflect (exists2 x, x \in D & exists2 y, y \in [predD1 D & x] & f x = f y) (~~ dinjectiveb f D). Proof. apply: (iffP idP) => [injf | [x Dx [y Dxy eqfxy]]]; last first. move: Dx; rewrite -(mem_enum D) => /rot_to[i E defE]. rewrite /dinjectiveb -(rot_uniq i) -map_rot defE /=; apply/nandP; left. rewrite inE /= -(mem_enum D) -(mem_rot i) defE inE in Dxy. rewrite andb_orr andbC andbN in Dxy. by rewrite eqfxy map_f //; case/andP: Dxy. pose p := [pred x in D | [exists (y | y \in [predD1 D & x]), f x == f y]]. case: (pickP p) => [x /= /andP[Dx /exists_inP[y Dxy /eqP eqfxy]] | no_p]. by exists x; last exists y. rewrite /dinjectiveb map_inj_in_uniq ?enum_uniq // in injf => x y Dx Dy eqfxy. apply: contraNeq (negbT (no_p x)) => ne_xy /=; rewrite -mem_enum Dx. by apply/existsP; exists y; rewrite /= !inE eq_sym ne_xy -mem_enum Dy eqfxy /=. Qed. Lemma dinjectiveP f D : reflect {in D &, injective f} (dinjectiveb f D). Proof. rewrite -[dinjectiveb f D]negbK. case: dinjectivePn=> [noinjf | injf]; constructor. case: noinjf => x Dx [y /andP[neqxy /= Dy] eqfxy] injf. by case/eqP: neqxy; apply: injf. move=> x y Dx Dy /= eqfxy; apply/eqP; apply/idPn=> nxy; case: injf. by exists x => //; exists y => //=; rewrite inE /= eq_sym nxy. Qed. Lemma eq_dinjectiveb f1 f2 D1 D2 : f1 =1 f2 -> D1 =i D2 -> dinjectiveb f1 D1 = dinjectiveb f2 D2. Proof. move=> ef eD; rewrite /dinjectiveb (eq_enum eD). by under eq_map => x do rewrite ef. Qed. Lemma injectivePn f : reflect (exists x, exists2 y, x != y & f x = f y) (~~ injectiveb f). Proof. apply: (iffP (dinjectivePn _ _)) => [[x _ [y nxy eqfxy]] | [x [y nxy eqfxy]]]; by exists x => //; exists y => //; rewrite inE /= andbT eq_sym in nxy *. Qed. Lemma injectiveP f : reflect (injective f) (injectiveb f). Proof. by apply: (iffP (dinjectiveP _ _)) => injf x y => [|_ _]; apply: injf. Qed. Lemma eq_injectiveb f1 f2 : f1 =1 f2 -> injectiveb f1 = injectiveb f2. Proof. move=> ?; exact: eq_dinjectiveb. Qed. End Injectiveb. Definition image_mem T T' f mA : seq T' := map f (@enum_mem T mA). Notation image f A := (image_mem f (mem A)). Notation "[ 'seq' F | x 'in' A ]" := (image (fun x => F) A) (x binder, format "'[hv' [ 'seq' F '/ ' | x 'in' A ] ']'") : seq_scope. Notation "[ 'seq' F | x ]" := [seq F | x in pred_of_simpl (@pred_of_argType (* kludge for getting the type of x *) match _, (fun x => I) with | T, f => match match f return T -> True with f' => f' end with | _ => T end end)] (x binder, only parsing) : seq_scope. Notation "[ 'seq' F | x : T ]" := [seq F | x in pred_of_simpl (@pred_of_argType T)] (x binder, only printing, format "'[hv' [ 'seq' F '/ ' | x : T ] ']'") : seq_scope. Notation "[ 'seq' F , x ]" := [seq F | x ] (x binder, only parsing) : seq_scope. Definition codom T T' f := @image_mem T T' f (mem T). Section Image. Variable T : finType. Implicit Type A : {pred T}. Section SizeImage. Variables (T' : Type) (f : T -> T'). Lemma size_image A : size (image f A) = #|A|. Proof. by rewrite size_map -cardE. Qed. Lemma size_codom : size (codom f) = #|T|. Proof. exact: size_image. Qed. Lemma codomE : codom f = map f (enum T). Proof. by []. Qed. End SizeImage. Variables (T' : eqType) (f : T -> T'). Lemma imageP A y : reflect (exists2 x, x \in A & y = f x) (y \in image f A). Proof. by apply: (iffP mapP) => [] [x Ax y_fx]; exists x; rewrite // mem_enum in Ax *. Qed. Lemma codomP y : reflect (exists x, y = f x) (y \in codom f). Proof. by apply: (iffP (imageP _ y)) => [][x]; exists x. Qed. Remark iinv_proof A y : y \in image f A -> {x | x \in A & f x = y}. Proof. move=> fy; pose b x := A x && (f x == y). case: (pickP b) => [x /andP[Ax /eqP] | nfy]; first by exists x. by case/negP: fy => /imageP[x Ax fx_y]; case/andP: (nfy x); rewrite fx_y. Qed. Definition iinv A y fAy := s2val (@iinv_proof A y fAy). Lemma f_iinv A y fAy : f (@iinv A y fAy) = y. Proof. exact: s2valP' (iinv_proof fAy). Qed. Lemma mem_iinv A y fAy : @iinv A y fAy \in A. Proof. exact: s2valP (iinv_proof fAy). Qed. Lemma in_iinv_f A : {in A &, injective f} -> forall x fAfx, x \in A -> @iinv A (f x) fAfx = x. Proof. by move=> injf x fAfx Ax; apply: injf => //; [apply: mem_iinv | apply: f_iinv]. Qed. Lemma preim_iinv A B y fAy : preim f B (@iinv A y fAy) = B y. Proof. by rewrite /= f_iinv. Qed. Lemma image_f A x : x \in A -> f x \in image f A. Proof. by move=> Ax; apply/imageP; exists x. Qed. Lemma codom_f x : f x \in codom f. Proof. exact: image_f. Qed. Lemma image_codom A : {subset image f A <= codom f}. Proof. by move=> _ /imageP[x _ ->]; apply: codom_f. Qed. Lemma image_pred0 : image f pred0 =i pred0. Proof. by move=> x; rewrite /image_mem /= enum0. Qed. Section Injective. Hypothesis injf : injective f. Lemma mem_image A x : (f x \in image f A) = (x \in A). Proof. by rewrite mem_map ?mem_enum. Qed. Lemma pre_image A : [preim f of image f A] =i A. Proof. by move=> x; rewrite inE /= mem_image. Qed. Lemma image_iinv A y (fTy : y \in codom f) : (y \in image f A) = (iinv fTy \in A). Proof. by rewrite -mem_image ?f_iinv. Qed. Lemma iinv_f x fTfx : @iinv T (f x) fTfx = x. Proof. by apply: in_iinv_f; first apply: in2W. Qed. Lemma image_pre (B : pred T') : image f [preim f of B] =i [predI B & codom f]. Proof. by move=> y; rewrite /image_mem -filter_map /= mem_filter -enumT. Qed. Lemma bij_on_codom (x0 : T) : {on [pred y in codom f], bijective f}. Proof. pose g y := iinv (valP (insigd (codom_f x0) y)). by exists g => [x fAfx | y fAy]; first apply: injf; rewrite f_iinv insubdK. Qed. Lemma bij_on_image A (x0 : T) : {on [pred y in image f A], bijective f}. Proof. exact: subon_bij (@image_codom A) (bij_on_codom x0). Qed. End Injective. Fixpoint preim_seq s := if s is y :: s' then (if pick (preim f (pred1 y)) is Some x then cons x else id) (preim_seq s') else [::]. Lemma map_preim (s : seq T') : {subset s <= codom f} -> map f (preim_seq s) = s. Proof. elim: s => //= y s IHs; case: pickP => [x /eqP fx_y | nfTy] fTs. by rewrite /= fx_y IHs // => z s_z; apply: fTs; apply: predU1r. by case/imageP: (fTs y (mem_head y s)) => x _ fx_y; case/eqP: (nfTy x). Qed. End Image. Prenex Implicits codom iinv. Arguments imageP {T T' f A y}. Arguments codomP {T T' f y}. Lemma flatten_imageP (aT : finType) (rT : eqType) (A : aT -> seq rT) (P : {pred aT}) (y : rT) : reflect (exists2 x, x \in P & y \in A x) (y \in flatten [seq A x | x in P]). Proof. by apply: (iffP flatten_mapP) => [][x Px]; exists x; rewrite ?mem_enum in Px *. Qed. Arguments flatten_imageP {aT rT A P y}. Section CardFunImage. Variables (T T' : finType) (f : T -> T'). Implicit Type A : {pred T}. Lemma leq_image_card A : #|image f A| <= #|A|. Proof. by rewrite (cardE A) -(size_map f) card_size. Qed. Lemma card_in_image A : {in A &, injective f} -> #|image f A| = #|A|. Proof. move=> injf; rewrite (cardE A) -(size_map f); apply/card_uniqP. by rewrite map_inj_in_uniq ?enum_uniq // => x y; rewrite !mem_enum; apply: injf. Qed. Lemma image_injP A : reflect {in A &, injective f} (#|image f A| == #|A|). Proof. apply: (iffP eqP) => [eqfA |]; last exact: card_in_image. by apply/dinjectiveP; apply/card_uniqP; rewrite size_map -cardE. Qed. Lemma leq_card_in A : {in A &, injective f} -> #|A| <= #|T'|. Proof. by move=> /card_in_image <-; rewrite max_card. Qed. Hypothesis injf : injective f. Lemma card_image A : #|image f A| = #|A|. Proof. by apply: card_in_image; apply: in2W. Qed. Lemma card_codom : #|codom f| = #|T|. Proof. exact: card_image. Qed. Lemma card_preim (B : {pred T'}) : #|[preim f of B]| = #|[predI codom f & B]|. Proof. rewrite -card_image /=; apply: eq_card => y. by rewrite [y \in _]image_pre !inE andbC. Qed. Lemma leq_card : #|T| <= #|T'|. Proof. exact: (leq_card_in (in2W _)). Qed. Hypothesis card_range : #|T| >= #|T'|. Let eq_card : #|T| = #|T'|. Proof. by apply/eqP; rewrite eqn_leq leq_card. Qed. Lemma inj_card_onto y : y \in codom f. Proof. by move: y; apply/subset_cardP; rewrite ?card_codom ?subset_predT. Qed. Lemma inj_card_bij : bijective f. Proof. by exists (fun y => iinv (inj_card_onto y)) => y; rewrite ?iinv_f ?f_iinv. Qed. End CardFunImage. Arguments image_injP {T T' f A}. Arguments leq_card_in [T T'] f. Arguments leq_card [T T'] f. Lemma bij_eq_card (T T' : finType) (f : T -> T') : bijective f -> #|T| = #|T'|. Proof. by move=> [g /can_inj/leq_card + /can_inj/leq_card]; case: ltngtP. Qed. Section FinCancel. Variables (T : finType) (f g : T -> T). Section Inv. Hypothesis injf : injective f. Lemma injF_onto y : y \in codom f. Proof. exact: inj_card_onto. Qed. Definition invF y := iinv (injF_onto y). Lemma invF_f : cancel f invF. Proof. by move=> x; apply: iinv_f. Qed. Lemma f_invF : cancel invF f. Proof. by move=> y; apply: f_iinv. Qed. Lemma injF_bij : bijective f. Proof. exact: inj_card_bij. Qed. End Inv. Hypothesis fK : cancel f g. Lemma canF_sym : cancel g f. Proof. exact/(bij_can_sym (injF_bij (can_inj fK))). Qed. Lemma canF_LR x y : x = g y -> f x = y. Proof. exact: canLR canF_sym. Qed. Lemma canF_RL x y : g x = y -> x = f y. Proof. exact: canRL canF_sym. Qed. Lemma canF_eq x y : (f x == y) = (x == g y). Proof. exact: (can2_eq fK canF_sym). Qed. Lemma canF_invF : g =1 invF (can_inj fK). Proof. by move=> y; apply: (canLR fK); rewrite f_invF. Qed. End FinCancel. Section EqImage. Variables (T : finType) (T' : Type). Lemma eq_image (A B : {pred T}) (f g : T -> T') : A =i B -> f =1 g -> image f A = image g B. Proof. by move=> eqAB eqfg; rewrite /image_mem (eq_enum eqAB) (eq_map eqfg). Qed. Lemma eq_codom (f g : T -> T') : f =1 g -> codom f = codom g. Proof. exact: eq_image. Qed. Lemma eq_invF f g injf injg : f =1 g -> @invF T f injf =1 @invF T g injg. Proof. by move=> eq_fg x; apply: (canLR (invF_f injf)); rewrite eq_fg f_invF. Qed. End EqImage. (* Standard finTypes *) Lemma unit_enumP : Finite.axiom [::tt]. Proof. by case. Qed. HB.instance Definition _ := isFinite.Build unit unit_enumP. Lemma card_unit : #|{: unit}| = 1. Proof. by rewrite cardT enumT unlock. Qed. Lemma bool_enumP : Finite.axiom [:: true; false]. Proof. by case. Qed. HB.instance Definition _ := isFinite.Build bool bool_enumP. Lemma card_bool : #|{: bool}| = 2. Proof. by rewrite cardT enumT unlock. Qed. Lemma void_enumP : Finite.axiom (Nil void). Proof. by case. Qed. HB.instance Definition _ := isFinite.Build void void_enumP. Lemma card_void : #|{: void}| = 0. Proof. by rewrite cardT enumT unlock. Qed. Local Notation enumF T := (Finite.enum T). Section OptionFinType. Variable T : finType. Definition option_enum := None :: map some (enumF T). Lemma option_enumP : Finite.axiom option_enum. Proof. by case=> [x|]; rewrite /= count_map (count_pred0, enumP). Qed. HB.instance Definition _ := isFinite.Build (option T) option_enumP. Lemma card_option : #|{: option T}| = #|T|.+1. Proof. by rewrite !cardT !enumT [in LHS]unlock /= !size_map. Qed. End OptionFinType. Section TransferFinTypeFromCount. Variables (eT : countType) (fT : finType) (f : eT -> fT). Lemma pcan_enumP g : pcancel f g -> Finite.axiom (undup (pmap g (enumF fT))). Proof. move=> fK x; rewrite count_uniq_mem ?undup_uniq // mem_undup. by rewrite mem_pmap -fK map_f // -enumT mem_enum. Qed. Definition PCanIsFinite g fK := @isFinite.Build _ _ (@pcan_enumP g fK). Definition CanIsFinite g (fK : cancel f g) := PCanIsFinite (can_pcan fK). End TransferFinTypeFromCount. Section TransferFinType. Variables (eT : Type) (fT : finType) (f : eT -> fT). HB.instance Definition _ (g : fT -> option eT) (fK : pcancel f g) := isFinite.Build (pcan_type fK) (@pcan_enumP (pcan_type fK) fT f g fK). HB.instance Definition _ (g : fT -> eT) (fK : cancel f g) := isFinite.Build (can_type fK) (@pcan_enumP (can_type fK) fT f _ (can_pcan fK)). End TransferFinType. #[short(type="subFinType")] HB.structure Definition SubFinite (T : Type) (P : pred T) := { sT of Finite sT & isSub T P sT }. Section SubFinType. Variables (T : choiceType) (P : pred T). Import Finite. Implicit Type sT : subFinType P. Lemma codom_val sT x : (x \in codom (val : sT -> T)) = P x. Proof. by apply/codomP/idP=> [[u ->]|Px]; last exists (Sub x Px); rewrite ?valP ?SubK. Qed. End SubFinType. HB.factory Record SubCountable_isFinite (T : finType) P (sT : Type) of SubCountable T P sT := { }. HB.builders Context (T : finType) (P : pred T) (sT : Type) (a : SubCountable_isFinite T P sT). Definition sub_enum : seq sT := pmap insub (enumF T). Lemma mem_sub_enum u : u \in sub_enum. Proof. by rewrite mem_pmap_sub -enumT mem_enum. Qed. Lemma sub_enum_uniq : uniq sub_enum. Proof. by rewrite pmap_sub_uniq // -enumT enum_uniq. Qed. Lemma val_sub_enum : map val sub_enum = enum P. Proof. rewrite pmap_filter; last exact: insubK. by apply: eq_filter => x; apply: isSome_insub. Qed. HB.instance Definition SubFinMixin := isFinite.Build sT (Finite.uniq_enumP sub_enum_uniq mem_sub_enum). HB.end. (* This assumes that T has a subCountType structure over a type that *) (* has a finType structure. *) HB.instance Definition _ (T : finType) (P : pred T) (sT : subType P) := (SubCountable_isFinite.Build _ _ (sub_type sT)). Notation "[ 'Finite' 'of' T 'by' <: ]" := (Finite.copy T%type (sub_type T%type)) (format "[ 'Finite' 'of' T 'by' <: ]") : form_scope. Section SubCountable_isFiniteTheory. Variables (T : finType) (P : pred T) (sfT : subFinType P). Lemma card_sub : #|sfT| = #|[pred x | P x]|. Proof. by rewrite -(eq_card (codom_val sfT)) (card_image val_inj). Qed. Lemma eq_card_sub (A : {pred sfT}) : A =i predT -> #|A| = #|[pred x | P x]|. Proof. exact: eq_card_trans card_sub. Qed. End SubCountable_isFiniteTheory. (* (* Regression for the subFinType stack *) *) (* Record myb : Type := MyB {myv : bool; _ : ~~ myv}. *) (* HB.instance Definition myb_sub : isSub bool (fun x => ~~ x) myb := *) (* [isSub for myv]. *) (* HB.instance Definition _ := [Finite of myb by <:]. *) (* Check [subFinType of myb]. *) (* Check [finType of myb]. *) Section CardSig. Variables (T : finType) (P : pred T). HB.instance Definition _ := [Finite of {x | P x} by <:]. Lemma card_sig : #|{: {x | P x}}| = #|[pred x | P x]|. Proof. exact: card_sub. Qed. End CardSig. (* Subtype for an explicit enumeration. *) Section SeqSubType. Variables (T : eqType) (s : seq T). Record seq_sub : Type := SeqSub {ssval : T; ssvalP : in_mem ssval (@mem T _ s)}. HB.instance Definition _ := [isSub for ssval]. HB.instance Definition _ := [Equality of seq_sub by <:]. Definition seq_sub_enum : seq seq_sub := undup (pmap insub s). Lemma mem_seq_sub_enum x : x \in seq_sub_enum. Proof. by rewrite mem_undup mem_pmap -valK map_f ?ssvalP. Qed. Lemma val_seq_sub_enum : uniq s -> map val seq_sub_enum = s. Proof. move=> Us; rewrite /seq_sub_enum undup_id ?pmap_sub_uniq //. rewrite (pmap_filter (insubK _)); apply/all_filterP. by apply/allP => x; rewrite isSome_insub. Qed. Definition seq_sub_pickle x := index x seq_sub_enum. Definition seq_sub_unpickle n := nth None (map some seq_sub_enum) n. Lemma seq_sub_pickleK : pcancel seq_sub_pickle seq_sub_unpickle. Proof. rewrite /seq_sub_unpickle => x. by rewrite (nth_map x) ?nth_index ?index_mem ?mem_seq_sub_enum. Qed. Definition seq_sub_isCountable := isCountable.Build seq_sub seq_sub_pickleK. Fact seq_sub_axiom : Finite.axiom seq_sub_enum. Proof. exact: Finite.uniq_enumP (undup_uniq _) mem_seq_sub_enum. Qed. Definition seq_sub_isFinite := isFinite.Build seq_sub seq_sub_axiom. (* Beware: these are not the canonical instances, as they are not consistent *) (* with the generic sub_choiceType canonical instance. *) Definition adhoc_seq_sub_choiceType : choiceType := pcan_type seq_sub_pickleK. Definition adhoc_seq_sub_countType := HB.pack_for countType seq_sub seq_sub_isCountable (Choice.class adhoc_seq_sub_choiceType). Definition adhoc_seq_sub_finType := HB.pack_for finType seq_sub seq_sub_isFinite seq_sub_isCountable (Choice.class adhoc_seq_sub_choiceType). End SeqSubType. Section SeqReplace. Variables (T : eqType). Implicit Types (s : seq T). Lemma seq_sub_default s : size s > 0 -> seq_sub s. Proof. by case: s => // x s _; exists x; rewrite mem_head. Qed. Lemma seq_subE s (s_gt0 : size s > 0) : s = map val (map (insubd (seq_sub_default s_gt0)) s : seq (seq_sub s)). Proof. by rewrite -map_comp map_id_in// => x x_in_s /=; rewrite insubdK. Qed. End SeqReplace. Notation in_sub_seq s_gt0 := (insubd (seq_sub_default s_gt0)). Section SeqFinType. Variables (T : choiceType) (s : seq T). Local Notation sT := (seq_sub s). HB.instance Definition _ := [Choice of sT by <:]. HB.instance Definition _ : isCountable sT := seq_sub_isCountable s. HB.instance Definition _ : isFinite sT := seq_sub_isFinite s. Lemma card_seq_sub : uniq s -> #|{:sT}| = size s. Proof. by move=> Us; rewrite cardE enumT -(size_map val) unlock val_seq_sub_enum. Qed. End SeqFinType. Section Extrema. Variant extremum_spec {T : eqType} (ord : rel T) {I : finType} (P : pred I) (F : I -> T) : I -> Type := ExtremumSpec (i : I) of P i & (forall j : I, P j -> ord (F i) (F j)) : extremum_spec ord P F i. Let arg_pred {T : eqType} ord {I : finType} (P : pred I) (F : I -> T) := [pred i | P i & [forall (j | P j), ord (F i) (F j)]]. Section Extremum. Context {T : eqType} {I : finType} (ord : rel T). Context (i0 : I) (P : pred I) (F : I -> T). Definition extremum := odflt i0 (pick (arg_pred ord P F)). Hypothesis ord_refl : reflexive ord. Hypothesis ord_trans : transitive ord. Hypothesis ord_total : total ord. Hypothesis Pi0 : P i0. Lemma extremumP : extremum_spec ord P F extremum. Proof. rewrite /extremum; case: pickP => [i /andP[Pi /'forall_implyP/= min_i] | no_i]. by split=> // j; apply/implyP. have := sort_sorted ord_total [seq F i | i <- enum P]. set s := sort _ _ => ss; have s_gt0 : size s > 0 by rewrite size_sort size_map -cardE; apply/card_gt0P; exists i0. pose t0 := nth (F i0) s 0; have: t0 \in s by rewrite mem_nth. rewrite mem_sort => /mapP/sig2_eqW[it0]; rewrite mem_enum => it0P def_t0. have /negP[/=] := no_i it0; rewrite [P _]it0P/=; apply/'forall_implyP=> j Pj. have /(nthP (F i0))[k g_lt <-] : F j \in s by rewrite mem_sort map_f ?mem_enum. by rewrite -def_t0 sorted_leq_nth. Qed. End Extremum. Section ExtremumIn. Context {T : eqType} {I : finType} (ord : rel T). Context (i0 : I) (P : pred I) (F : I -> T). Hypothesis ord_refl : {in P, reflexive (relpre F ord)}. Hypothesis ord_trans : {in P & P & P, transitive (relpre F ord)}. Hypothesis ord_total : {in P &, total (relpre F ord)}. Hypothesis Pi0 : P i0. Lemma extremum_inP : extremum_spec ord P F (extremum ord i0 P F). Proof. rewrite /extremum; case: pickP => [i /andP[Pi /'forall_implyP/= min_i] | no_i]. by split=> // j; apply/implyP. pose TP := seq_sub [seq F i | i <- enum P]. have FPP (iP : {i | P i}) : F (proj1_sig iP) \in [seq F i | i <- enum P]. by rewrite map_f// mem_enum; apply: valP. pose FP := SeqSub (FPP _). have []//= := @extremumP _ _ (relpre val ord) (exist P i0 Pi0) xpredT FP. - by move=> [/= _/mapP[i iP ->]]; apply: ord_refl; rewrite mem_enum in iP. - move=> [/= _/mapP[j jP ->]] [/= _/mapP[i iP ->]] [/= _/mapP[k kP ->]]. by apply: ord_trans; rewrite !mem_enum in iP jP kP. - move=> [/= _/mapP[i iP ->]] [/= _/mapP[j jP ->]]. by apply: ord_total; rewrite !mem_enum in iP jP. - rewrite /FP => -[/= i Pi] _ /(_ (exist _ _ _))/= ordF. have /negP/negP/= := no_i i; rewrite Pi/= negb_forall => /existsP/sigW[j]. by rewrite negb_imply => /andP[Pj]; rewrite ordF. Qed. End ExtremumIn. Notation "[ 'arg[' ord ]_( i < i0 | P ) F ]" := (extremum ord i0 (fun i => P%B) (fun i => F)) (ord, i, i0 at level 10, format "[ 'arg[' ord ]_( i < i0 | P ) F ]") : nat_scope. Notation "[ 'arg[' ord ]_( i < i0 'in' A ) F ]" := [arg[ord]_(i < i0 | i \in A) F] (format "[ 'arg[' ord ]_( i < i0 'in' A ) F ]") : nat_scope. Notation "[ 'arg[' ord ]_( i < i0 ) F ]" := [arg[ord]_(i < i0 | true) F] (format "[ 'arg[' ord ]_( i < i0 ) F ]") : nat_scope. Section ArgMinMax. Variables (I : finType) (i0 : I) (P : pred I) (F : I -> nat) (Pi0 : P i0). Definition arg_min := extremum leq i0 P F. Definition arg_max := extremum geq i0 P F. Lemma arg_minnP : extremum_spec leq P F arg_min. Proof. by apply: extremumP => //; [apply: leq_trans|apply: leq_total]. Qed. Lemma arg_maxnP : extremum_spec geq P F arg_max. Proof. apply: extremumP => //; first exact: leqnn. by move=> n m p mn np; apply: leq_trans mn. by move=> ??; apply: leq_total. Qed. End ArgMinMax. End Extrema. Notation "[ 'arg' 'min_' ( i < i0 | P ) F ]" := (arg_min i0 (fun i => P%B) (fun i => F)) (i, i0 at level 10, format "[ 'arg' 'min_' ( i < i0 | P ) F ]") : nat_scope. Notation "[ 'arg' 'min_' ( i < i0 'in' A ) F ]" := [arg min_(i < i0 | i \in A) F] (format "[ 'arg' 'min_' ( i < i0 'in' A ) F ]") : nat_scope. Notation "[ 'arg' 'min_' ( i < i0 ) F ]" := [arg min_(i < i0 | true) F] (format "[ 'arg' 'min_' ( i < i0 ) F ]") : nat_scope. Notation "[ 'arg' 'max_' ( i > i0 | P ) F ]" := (arg_max i0 (fun i => P%B) (fun i => F)) (i, i0 at level 10, format "[ 'arg' 'max_' ( i > i0 | P ) F ]") : nat_scope. Notation "[ 'arg' 'max_' ( i > i0 'in' A ) F ]" := [arg max_(i > i0 | i \in A) F] (format "[ 'arg' 'max_' ( i > i0 'in' A ) F ]") : nat_scope. Notation "[ 'arg' 'max_' ( i > i0 ) F ]" := [arg max_(i > i0 | true) F] (format "[ 'arg' 'max_' ( i > i0 ) F ]") : nat_scope. (**********************************************************************) (* *) (* Ordinal finType : {0, ... , n-1} *) (* *) (**********************************************************************) Section OrdinalSub. Variable n : nat. Inductive ordinal : predArgType := Ordinal m of m < n. Coercion nat_of_ord i := let: Ordinal m _ := i in m. HB.instance Definition _ := [isSub of ordinal for nat_of_ord]. HB.instance Definition _ := [Countable of ordinal by <:]. Lemma ltn_ord (i : ordinal) : i < n. Proof. exact: valP i. Qed. Lemma ord_inj : injective nat_of_ord. Proof. exact: val_inj. Qed. Definition ord_enum : seq ordinal := pmap insub (iota 0 n). Lemma val_ord_enum : map val ord_enum = iota 0 n. Proof. rewrite pmap_filter; last exact: insubK. by apply/all_filterP; apply/allP=> i; rewrite mem_iota isSome_insub. Qed. Lemma ord_enum_uniq : uniq ord_enum. Proof. by rewrite pmap_sub_uniq ?iota_uniq. Qed. Lemma mem_ord_enum i : i \in ord_enum. Proof. by rewrite -(mem_map ord_inj) val_ord_enum mem_iota ltn_ord. Qed. HB.instance Definition _ := isFinite.Build ordinal (Finite.uniq_enumP ord_enum_uniq mem_ord_enum). End OrdinalSub. Notation "''I_' n" := (ordinal n) (at level 0, n at level 2, format "''I_' n"). #[global] Hint Resolve ltn_ord : core. Section OrdinalEnum. Variable n : nat. Lemma val_enum_ord : map val (enum 'I_n) = iota 0 n. Proof. by rewrite enumT unlock val_ord_enum. Qed. Lemma size_enum_ord : size (enum 'I_n) = n. Proof. by rewrite -(size_map val) val_enum_ord size_iota. Qed. Lemma card_ord : #|'I_n| = n. Proof. by rewrite cardE size_enum_ord. Qed. Lemma nth_enum_ord i0 m : m < n -> nth i0 (enum 'I_n) m = m :> nat. Proof. by move=> ?; rewrite -(nth_map _ 0) (size_enum_ord, val_enum_ord) // nth_iota. Qed. Lemma nth_ord_enum (i0 i : 'I_n) : nth i0 (enum 'I_n) i = i. Proof. by apply: val_inj; apply: nth_enum_ord. Qed. Lemma index_enum_ord (i : 'I_n) : index i (enum 'I_n) = i. Proof. by rewrite -[in LHS](nth_ord_enum i i) index_uniq ?(enum_uniq, size_enum_ord). Qed. Lemma mask_enum_ord m : mask m (enum 'I_n) = [seq i <- enum 'I_n | nth false m (val i)]. Proof. rewrite mask_filter ?enum_uniq//; apply: eq_filter => i. by rewrite in_mask ?enum_uniq ?mem_enum// index_enum_ord. Qed. End OrdinalEnum. Lemma enum_ord0 : enum 'I_0 = [::]. Proof. by apply/eqP; rewrite -size_eq0 size_enum_ord. Qed. Lemma widen_ord_proof n m (i : 'I_n) : n <= m -> i < m. Proof. exact: leq_trans. Qed. Definition widen_ord n m le_n_m i := Ordinal (@widen_ord_proof n m i le_n_m). Lemma cast_ord_proof n m (i : 'I_n) : n = m -> i < m. Proof. by move <-. Qed. Definition cast_ord n m eq_n_m i := Ordinal (@cast_ord_proof n m i eq_n_m). Lemma cast_ord_id n eq_n i : cast_ord eq_n i = i :> 'I_n. Proof. exact: val_inj. Qed. Lemma cast_ord_comp n1 n2 n3 eq_n2 eq_n3 i : @cast_ord n2 n3 eq_n3 (@cast_ord n1 n2 eq_n2 i) = cast_ord (etrans eq_n2 eq_n3) i. Proof. exact: val_inj. Qed. Lemma cast_ordK n1 n2 eq_n : cancel (@cast_ord n1 n2 eq_n) (cast_ord (esym eq_n)). Proof. by move=> i; apply: val_inj. Qed. Lemma cast_ordKV n1 n2 eq_n : cancel (cast_ord (esym eq_n)) (@cast_ord n1 n2 eq_n). Proof. by move=> i; apply: val_inj. Qed. Lemma cast_ord_inj n1 n2 eq_n : injective (@cast_ord n1 n2 eq_n). Proof. exact: can_inj (cast_ordK eq_n). Qed. Fact ordS_subproof n (i : 'I_n) : i.+1 %% n < n. Proof. by case: n i => [|n] [m m_lt]//=; rewrite ltn_pmod. Qed. Definition ordS n (i : 'I_n) := Ordinal (ordS_subproof i). Fact ord_pred_subproof n (i : 'I_n) : (i + n).-1 %% n < n. Proof. by case: n i => [|n] [m m_lt]//=; rewrite ltn_pmod. Qed. Definition ord_pred n (i : 'I_n) := Ordinal (ord_pred_subproof i). Lemma ordSK n : cancel (@ordS n) (@ord_pred n). Proof. move=> [i ilt]; apply/val_inj => /=. case: (ltngtP i.+1) (ilt) => // [Silt|<-]; last by rewrite modnn/= modn_small. by rewrite [i.+1 %% n]modn_small// addSn/= modnDr modn_small. Qed. Lemma ord_predK n : cancel (@ord_pred n) (@ordS n). Proof. move=> [[|i] ilt]; apply/val_inj => /=. by rewrite [n.-1 %% n]modn_small// prednK// modnn. by rewrite modnDr [i %% n]modn_small ?modn_small// ltnW. Qed. Lemma ordS_bij n : bijective (@ordS n). Proof. exact: (Bijective (@ordSK n) (@ord_predK n)). Qed. Lemma ordS_inj n : injective (@ordS n). Proof. exact: (bij_inj (ordS_bij n)). Qed. Lemma ord_pred_bij n : bijective (@ord_pred n). Proof. exact (Bijective (@ord_predK n) (@ordSK n)). Qed. Lemma ord_pred_inj n : injective (@ord_pred n). Proof. exact: (bij_inj (ord_pred_bij n)). Qed. Lemma rev_ord_proof n (i : 'I_n) : n - i.+1 < n. Proof. by case: n i => [|n] [i lt_i_n] //; rewrite ltnS subSS leq_subr. Qed. Definition rev_ord n i := Ordinal (@rev_ord_proof n i). Lemma rev_ordK {n} : involutive (@rev_ord n). Proof. by case: n => [|n] [i lti] //; apply: val_inj; rewrite /= !subSS subKn. Qed. Lemma rev_ord_inj {n} : injective (@rev_ord n). Proof. exact: inv_inj rev_ordK. Qed. Lemma inj_leq m n (f : 'I_m -> 'I_n) : injective f -> m <= n. Proof. by move=> /leq_card; rewrite !card_ord. Qed. Arguments inj_leq [m n] f _. (* bijection between any finType T and the Ordinal finType of its cardinal *) Lemma enum_rank_subproof (T : finType) x0 (A : {pred T}) : x0 \in A -> 0 < #|A|. Proof. by move=> Ax0; rewrite (cardD1 x0) Ax0. Qed. HB.lock Definition enum_rank_in (T : finType) x0 (A : {pred T}) (Ax0 : x0 \in A) x := insubd (Ordinal (@enum_rank_subproof T x0 [eta A] Ax0)) (index x (enum A)). Canonical unlockable_enum_rank_in := Unlockable enum_rank_in.unlock. Section EnumRank. Variable T : finType. Implicit Type A : {pred T}. Definition enum_rank x := @enum_rank_in T x T (erefl true) x. Lemma enum_default A : 'I_(#|A|) -> T. Proof. by rewrite cardE; case: (enum A) => [|//] []. Qed. Definition enum_val A i := nth (@enum_default [eta A] i) (enum A) i. Prenex Implicits enum_val. Lemma enum_valP A i : @enum_val A i \in A. Proof. by rewrite -mem_enum mem_nth -?cardE. Qed. Lemma enum_val_nth A x i : @enum_val A i = nth x (enum A) i. Proof. by apply: set_nth_default; rewrite cardE in i *; apply: ltn_ord. Qed. Lemma nth_image T' y0 (f : T -> T') A (i : 'I_#|A|) : nth y0 (image f A) i = f (enum_val i). Proof. by rewrite -(nth_map _ y0) // -cardE. Qed. Lemma nth_codom T' y0 (f : T -> T') (i : 'I_#|T|) : nth y0 (codom f) i = f (enum_val i). Proof. exact: nth_image. Qed. Lemma nth_enum_rank_in x00 x0 A Ax0 : {in A, cancel (@enum_rank_in T x0 A Ax0) (nth x00 (enum A))}. Proof. move=> x Ax; rewrite enum_rank_in.unlock insubdK ?nth_index ?mem_enum //. by rewrite cardE [_ \in _]index_mem mem_enum. Qed. Lemma nth_enum_rank x0 : cancel enum_rank (nth x0 (enum T)). Proof. by move=> x; apply: nth_enum_rank_in. Qed. Lemma enum_rankK_in x0 A Ax0 : {in A, cancel (@enum_rank_in T x0 A Ax0) enum_val}. Proof. by move=> x; apply: nth_enum_rank_in. Qed. Lemma enum_rankK : cancel enum_rank enum_val. Proof. by move=> x; apply: enum_rankK_in. Qed. Lemma enum_valK_in x0 A Ax0 : cancel enum_val (@enum_rank_in T x0 A Ax0). Proof. move=> x; apply: ord_inj; rewrite enum_rank_in.unlock insubdK; last first. by rewrite cardE [_ \in _]index_mem mem_nth // -cardE. by rewrite index_uniq ?enum_uniq // -cardE. Qed. Lemma enum_valK : cancel enum_val enum_rank. Proof. by move=> x; apply: enum_valK_in. Qed. Lemma enum_rank_inj : injective enum_rank. Proof. exact: can_inj enum_rankK. Qed. Lemma enum_val_inj A : injective (@enum_val A). Proof. by move=> i; apply: can_inj (enum_valK_in (enum_valP i)) (i). Qed. Lemma enum_val_bij_in x0 A : x0 \in A -> {on A, bijective (@enum_val A)}. Proof. move=> Ax0; exists (enum_rank_in Ax0) => [i _|]; last exact: enum_rankK_in. exact: enum_valK_in. Qed. Lemma eq_enum_rank_in (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) : {in A, enum_rank_in Ax0 =1 enum_rank_in Ay0}. Proof. by move=> x xA; apply: enum_val_inj; rewrite !enum_rankK_in. Qed. Lemma enum_rank_in_inj (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) : {in A &, forall x y, enum_rank_in Ax0 x = enum_rank_in Ay0 y -> x = y}. Proof. by move=> x y xA yA /(congr1 enum_val); rewrite !enum_rankK_in. Qed. Lemma enum_rank_bij : bijective enum_rank. Proof. by move: enum_rankK enum_valK; exists (@enum_val T). Qed. Lemma enum_val_bij : bijective (@enum_val T). Proof. by move: enum_rankK enum_valK; exists enum_rank. Qed. (* Due to the limitations of the Coq unification patterns, P can only be *) (* inferred from the premise of this lemma, not its conclusion. As a result *) (* this lemma will only be usable in forward chaining style. *) Lemma fin_all_exists U (P : forall x : T, U x -> Prop) : (forall x, exists u, P x u) -> (exists u, forall x, P x (u x)). Proof. move=> ex_u; pose Q m x := enum_rank x < m -> {ux | P x ux}. suffices: forall m, m <= #|T| -> exists w : forall x, Q m x, True. case/(_ #|T|)=> // w _; pose u x := sval (w x (ltn_ord _)). by exists u => x; rewrite {}/u; case: (w x _). elim=> [|m IHm] ltmX; first by have w x: Q 0 x by []; exists w. have{IHm} [w _] := IHm (ltnW ltmX); pose i := Ordinal ltmX. have [u Pu] := ex_u (enum_val i); suffices w' x: Q m.+1 x by exists w'. rewrite /Q ltnS leq_eqVlt (val_eqE _ i); case: eqP => [def_i _ | _ /w //]. by rewrite -def_i enum_rankK in u Pu; exists u. Qed. Lemma fin_all_exists2 U (P Q : forall x : T, U x -> Prop) : (forall x, exists2 u, P x u & Q x u) -> (exists2 u, forall x, P x (u x) & forall x, Q x (u x)). Proof. move=> ex_u; have (x): exists u, P x u /\ Q x u by have [u] := ex_u x; exists u. by case/fin_all_exists=> u /all_and2[]; exists u. Qed. End EnumRank. Arguments enum_val_inj {T A} [i1 i2] : rename. Arguments enum_rank_inj {T} [x1 x2]. Prenex Implicits enum_val enum_rank enum_valK enum_rankK. Lemma enum_rank_ord n i : enum_rank i = cast_ord (esym (card_ord n)) i. Proof. apply: val_inj; rewrite /enum_rank enum_rank_in.unlock. by rewrite insubdK ?index_enum_ord // card_ord [_ \in _]ltn_ord. Qed. Lemma enum_val_ord n i : enum_val i = cast_ord (card_ord n) i. Proof. by apply: canLR (@enum_rankK _) _; apply: val_inj; rewrite enum_rank_ord. Qed. (* The integer bump / unbump operations. *) Definition bump h i := (h <= i) + i. Definition unbump h i := i - (h < i). Lemma bumpK h : cancel (bump h) (unbump h). Proof. rewrite /bump /unbump => i. have [le_hi | lt_ih] := leqP h i; first by rewrite ltnS le_hi subn1. by rewrite ltnNge ltnW ?subn0. Qed. Lemma neq_bump h i : h != bump h i. Proof. rewrite /bump eqn_leq; have [le_hi | lt_ih] := leqP h i. by rewrite ltnNge le_hi andbF. by rewrite leqNgt lt_ih. Qed. Lemma unbumpKcond h i : bump h (unbump h i) = (i == h) + i. Proof. rewrite /bump /unbump leqNgt -subSKn. case: (ltngtP i h) => /= [-> | ltih | ->] //; last by rewrite ltnn. by rewrite subn1 /= leqNgt !(ltn_predK ltih, ltih, add1n). Qed. Lemma unbumpK {h} : {in predC1 h, cancel (unbump h) (bump h)}. Proof. by move=> i /negbTE-neq_h_i; rewrite unbumpKcond neq_h_i. Qed. Lemma bumpDl h i k : bump (k + h) (k + i) = k + bump h i. Proof. by rewrite /bump leq_add2l addnCA. Qed. Lemma bumpS h i : bump h.+1 i.+1 = (bump h i).+1. Proof. exact: addnS. Qed. Lemma unbumpDl h i k : unbump (k + h) (k + i) = k + unbump h i. Proof. apply: (can_inj (bumpK (k + h))). by rewrite bumpDl !unbumpKcond eqn_add2l addnCA. Qed. Lemma unbumpS h i : unbump h.+1 i.+1 = (unbump h i).+1. Proof. exact: unbumpDl 1. Qed. Lemma leq_bump h i j : (i <= bump h j) = (unbump h i <= j). Proof. rewrite /bump leq_subLR. case: (leqP i h) (leqP h j) => [le_i_h | lt_h_i] [le_h_j | lt_j_h] //. by rewrite leqW (leq_trans le_i_h). by rewrite !(leqNgt i) ltnW (leq_trans _ lt_h_i). Qed. Lemma leq_bump2 h i j : (bump h i <= bump h j) = (i <= j). Proof. by rewrite leq_bump bumpK. Qed. Lemma bumpC h1 h2 i : bump h1 (bump h2 i) = bump (bump h1 h2) (bump (unbump h2 h1) i). Proof. rewrite {1 5}/bump -leq_bump addnCA; congr (_ + (_ + _)). rewrite 2!leq_bump /unbump /bump; case: (leqP h1 h2) => [le_h12 | lt_h21]. by rewrite subn0 ltnS le_h12 subn1. by rewrite subn1 (ltn_predK lt_h21) (leqNgt h1) lt_h21 subn0. Qed. (* The lift operations on ordinals; to avoid a messy dependent type, *) (* unlift is a partial operation (returns an option). *) Lemma lift_subproof n h (i : 'I_n.-1) : bump h i < n. Proof. by case: n i => [[]|n] //= i; rewrite -addnS (leq_add (leq_b1 _)). Qed. Definition lift n (h : 'I_n) (i : 'I_n.-1) := Ordinal (lift_subproof h i). Lemma unlift_subproof n (h : 'I_n) (u : {j | j != h}) : unbump h (val u) < n.-1. Proof. case: n h u => [|n h] [] //= j ne_jh. rewrite -(leq_bump2 h.+1) bumpS unbumpK // /bump. case: (ltngtP n h) => [|_|eq_nh]; rewrite ?(leqNgt _ h) ?ltn_ord //. by rewrite ltn_neqAle [j <= _](valP j) {2}eq_nh andbT. Qed. Definition unlift n (h i : 'I_n) := omap (fun u : {j | j != h} => Ordinal (unlift_subproof u)) (insub i). Variant unlift_spec n h i : option 'I_n.-1 -> Type := | UnliftSome j of i = lift h j : unlift_spec h i (Some j) | UnliftNone of i = h : unlift_spec h i None. Lemma unliftP n (h i : 'I_n) : unlift_spec h i (unlift h i). Proof. rewrite /unlift; case: insubP => [u nhi | ] def_i /=; constructor. by apply: val_inj; rewrite /= def_i unbumpK. by rewrite negbK in def_i; apply/eqP. Qed. Lemma neq_lift n (h : 'I_n) i : h != lift h i. Proof. exact: neq_bump. Qed. Lemma eq_liftF n (h : 'I_n) i : (h == lift h i) = false. Proof. exact/negbTE/neq_lift. Qed. Lemma lift_eqF n (h : 'I_n) i : (lift h i == h) = false. Proof. by rewrite eq_sym eq_liftF. Qed. Lemma unlift_none n (h : 'I_n) : unlift h h = None. Proof. by case: unliftP => // j Dh; case/eqP: (neq_lift h j). Qed. Lemma unlift_some n (h i : 'I_n) : h != i -> {j | i = lift h j & unlift h i = Some j}. Proof. rewrite eq_sym => /eqP neq_ih. by case Dui: (unlift h i) / (unliftP h i) => [j Dh|//]; exists j. Qed. Lemma lift_inj n (h : 'I_n) : injective (lift h). Proof. by move=> i1 i2 [/(can_inj (bumpK h))/val_inj]. Qed. Arguments lift_inj {n h} [i1 i2] eq_i12h : rename. Lemma liftK n (h : 'I_n) : pcancel (lift h) (unlift h). Proof. by move=> i; case: (unlift_some (neq_lift h i)) => j /lift_inj->. Qed. (* Shifting and splitting indices, for cutting and pasting arrays *) Lemma lshift_subproof m n (i : 'I_m) : i < m + n. Proof. by apply: leq_trans (valP i) _; apply: leq_addr. Qed. Lemma rshift_subproof m n (i : 'I_n) : m + i < m + n. Proof. by rewrite ltn_add2l. Qed. Definition lshift m n (i : 'I_m) := Ordinal (lshift_subproof n i). Definition rshift m n (i : 'I_n) := Ordinal (rshift_subproof m i). Lemma lshift_inj m n : injective (@lshift m n). Proof. by move=> ? ? /(f_equal val) /= /val_inj. Qed. Lemma rshift_inj m n : injective (@rshift m n). Proof. by move=> ? ? /(f_equal val) /addnI /val_inj. Qed. Lemma eq_lshift m n i j : (@lshift m n i == @lshift m n j) = (i == j). Proof. by rewrite (inj_eq (@lshift_inj _ _)). Qed. Lemma eq_rshift m n i j : (@rshift m n i == @rshift m n j) = (i == j). Proof. by rewrite (inj_eq (@rshift_inj _ _)). Qed. Lemma eq_lrshift m n i j : (@lshift m n i == @rshift m n j) = false. Proof. apply/eqP=> /(congr1 val)/= def_i; have := ltn_ord i. by rewrite def_i -ltn_subRL subnn. Qed. Lemma eq_rlshift m n i j : (@rshift m n i == @lshift m n j) = false. Proof. by rewrite eq_sym eq_lrshift. Qed. Definition eq_shift := (eq_lshift, eq_rshift, eq_lrshift, eq_rlshift). Lemma split_subproof m n (i : 'I_(m + n)) : i >= m -> i - m < n. Proof. by move/subSn <-; rewrite leq_subLR. Qed. Definition split {m n} (i : 'I_(m + n)) : 'I_m + 'I_n := match ltnP (i) m with | LtnNotGeq lt_i_m => inl _ (Ordinal lt_i_m) | GeqNotLtn ge_i_m => inr _ (Ordinal (split_subproof ge_i_m)) end. Variant split_spec m n (i : 'I_(m + n)) : 'I_m + 'I_n -> bool -> Type := | SplitLo (j : 'I_m) of i = j :> nat : split_spec i (inl _ j) true | SplitHi (k : 'I_n) of i = m + k :> nat : split_spec i (inr _ k) false. Lemma splitP m n (i : 'I_(m + n)) : split_spec i (split i) (i < m). Proof. (* We need to prevent the case on ltnP from rewriting the hidden constructor *) (* argument types of the match branches exposed by unfolding split. If the *) (* match representation is changed to omit these then this proof could reduce *) (* to by rewrite /split; case: ltnP; [left | right. rewrite subnKC]. *) set lt_i_m := i < m; rewrite /split. by case: _ _ _ _ {-}_ lt_i_m / ltnP; [left | right; rewrite subnKC]. Qed. Variant split_ord_spec m n (i : 'I_(m + n)) : 'I_m + 'I_n -> bool -> Type := | SplitOrdLo (j : 'I_m) of i = lshift _ j : split_ord_spec i (inl _ j) true | SplitOrdHi (k : 'I_n) of i = rshift _ k : split_ord_spec i (inr _ k) false. Lemma split_ordP m n (i : 'I_(m + n)) : split_ord_spec i (split i) (i < m). Proof. by case: splitP; [left|right]; apply: val_inj. Qed. Definition unsplit {m n} (jk : 'I_m + 'I_n) := match jk with inl j => lshift n j | inr k => rshift m k end. Lemma ltn_unsplit m n (jk : 'I_m + 'I_n) : (unsplit jk < m) = jk. Proof. by case: jk => [j|k]; rewrite /= ?ltn_ord // ltnNge leq_addr. Qed. Lemma splitK {m n} : cancel (@split m n) unsplit. Proof. by move=> i; case: split_ordP. Qed. Lemma unsplitK {m n} : cancel (@unsplit m n) split. Proof. by move=> [j|k]; case: split_ordP => ? /eqP; rewrite eq_shift// => /eqP->. Qed. Section OrdinalPos. Variable n' : nat. Local Notation n := n'.+1. Definition ord0 := Ordinal (ltn0Sn n'). Definition ord_max := Ordinal (ltnSn n'). Lemma leq_ord (i : 'I_n) : i <= n'. Proof. exact: valP i. Qed. Lemma sub_ord_proof m : n' - m < n. Proof. by rewrite ltnS leq_subr. Qed. Definition sub_ord m := Ordinal (sub_ord_proof m). Lemma sub_ordK (i : 'I_n) : n' - (n' - i) = i. Proof. by rewrite subKn ?leq_ord. Qed. Definition inord m : 'I_n := insubd ord0 m. Lemma inordK m : m < n -> inord m = m :> nat. Proof. by move=> lt_m; rewrite val_insubd lt_m. Qed. Lemma inord_val (i : 'I_n) : inord i = i. Proof. by rewrite /inord /insubd valK. Qed. Lemma enum_ordSl : enum 'I_n = ord0 :: map (lift ord0) (enum 'I_n'). Proof. apply: (inj_map val_inj); rewrite val_enum_ord /= -map_comp. by rewrite (map_comp (addn 1)) val_enum_ord -iotaDl. Qed. Lemma enum_ordSr : enum 'I_n = rcons (map (widen_ord (leqnSn _)) (enum 'I_n')) ord_max. Proof. apply: (inj_map val_inj); rewrite val_enum_ord. rewrite -[in iota _ _]addn1 iotaD/= cats1 map_rcons; congr (rcons _ _). by rewrite -map_comp/= (@eq_map _ _ _ val) ?val_enum_ord. Qed. Lemma lift_max (i : 'I_n') : lift ord_max i = i :> nat. Proof. by rewrite /= /bump leqNgt ltn_ord. Qed. Lemma lift0 (i : 'I_n') : lift ord0 i = i.+1 :> nat. Proof. by []. Qed. End OrdinalPos. Arguments ord0 {n'}. Arguments ord_max {n'}. Arguments inord {n'}. Arguments sub_ord {n'}. Arguments sub_ordK {n'}. Arguments inord_val {n'}. Lemma ord1 : all_equal_to (ord0 : 'I_1). Proof. by case=> [[] // ?]; apply: val_inj. Qed. (* Product of two fintypes which is a fintype *) Section ProdFinType. Variable T1 T2 : finType. Definition prod_enum := [seq (x1, x2) | x1 <- enum T1, x2 <- enum T2]. Lemma predX_prod_enum (A1 : {pred T1}) (A2 : {pred T2}) : count [predX A1 & A2] prod_enum = #|A1| * #|A2|. Proof. rewrite !cardE !size_filter -!enumT /prod_enum. elim: (enum T1) => //= x1 s1 IHs; rewrite count_cat {}IHs count_map /preim /=. by case: (x1 \in A1); rewrite ?count_pred0. Qed. Lemma prod_enumP : Finite.axiom prod_enum. Proof. by case=> x1 x2; rewrite (predX_prod_enum (pred1 x1) (pred1 x2)) !card1. Qed. HB.instance Definition _ := isFinite.Build (T1 * T2)%type prod_enumP. Lemma cardX (A1 : {pred T1}) (A2 : {pred T2}) : #|[predX A1 & A2]| = #|A1| * #|A2|. Proof. by rewrite -predX_prod_enum unlock size_filter unlock. Qed. Lemma card_prod : #|{: T1 * T2}| = #|T1| * #|T2|. Proof. by rewrite -cardX; apply: eq_card; case. Qed. Lemma eq_card_prod (A : {pred (T1 * T2)}) : A =i predT -> #|A| = #|T1| * #|T2|. Proof. exact: eq_card_trans card_prod. Qed. End ProdFinType. Section TagFinType. Variables (I : finType) (T_ : I -> finType). Definition tag_enum := flatten [seq [seq Tagged T_ x | x <- enumF (T_ i)] | i <- enumF I]. Lemma tag_enumP : Finite.axiom tag_enum. Proof. case=> i x; rewrite -(enumP i) /tag_enum -enumT. elim: (enum I) => //= j e IHe. rewrite count_cat count_map {}IHe; congr (_ + _). rewrite -size_filter -cardE /=; case: eqP => [-> | ne_j_i]. by apply: (@eq_card1 _ x) => y; rewrite -topredE /= tagged_asE ?eqxx. by apply: eq_card0 => y. Qed. HB.instance Definition _ := isFinite.Build {i : I & T_ i} tag_enumP. Lemma card_tagged : #|{: {i : I & T_ i}}| = sumn (map (fun i => #|T_ i|) (enum I)). Proof. rewrite cardE !enumT [in LHS]unlock size_flatten /shape -map_comp. by congr (sumn _); apply: eq_map => i; rewrite /= size_map -enumT -cardE. Qed. End TagFinType. Section SumFinType. Variables T1 T2 : finType. Definition sum_enum := [seq inl _ x | x <- enumF T1] ++ [seq inr _ y | y <- enumF T2]. Lemma sum_enum_uniq : uniq sum_enum. Proof. rewrite cat_uniq -!enumT !(enum_uniq, map_inj_uniq); try by move=> ? ? []. by rewrite andbT; apply/hasP=> [[_ /mapP[x _ ->] /mapP[]]]. Qed. Lemma mem_sum_enum u : u \in sum_enum. Proof. by case: u => x; rewrite mem_cat -!enumT map_f ?mem_enum ?orbT. Qed. HB.instance Definition sum_isFinite := isFinite.Build (T1 + T2)%type (Finite.uniq_enumP sum_enum_uniq mem_sum_enum). Lemma card_sum : #|{: T1 + T2}| = #|T1| + #|T2|. Proof. by rewrite !cardT !enumT [in LHS]unlock size_cat !size_map. Qed. End SumFinType.
BooleanAlgebra.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Bryan Gin-ge Chen -/ import Mathlib.Order.BooleanAlgebra.Defs import Mathlib.Order.BooleanAlgebra.Basic import Mathlib.Tactic.Linter.DeprecatedModule deprecated_module (since := "2025-06-19")
Comp.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.CategoryTheory.EffectiveEpi.Basic /-! # Composition of effective epimorphisms This file provides `EffectiveEpi` instances for certain compositions. -/ namespace CategoryTheory open Limits Category variable {C : Type*} [Category C] /-- An effective epi family precomposed by a family of split epis is effective epimorphic. This version takes an explicit section to the split epis, and is mainly used to define `effectiveEpiStructCompOfEffectiveEpiSplitEpi`, which takes a `IsSplitEpi` instance instead. -/ noncomputable def effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi' {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) (i : (a : α) → X a ⟶ Y a) (hi : ∀ a, i a ≫ g a = 𝟙 _) [EffectiveEpiFamily _ f] : EffectiveEpiFamilyStruct _ (fun a ↦ g a ≫ f a) where desc e w := EffectiveEpiFamily.desc _ f (fun a ↦ i a ≫ e a) fun a₁ a₂ g₁ g₂ _ ↦ (by simp only [← Category.assoc] apply w _ _ (g₁ ≫ i a₁) (g₂ ≫ i a₂) simp only [Category.assoc] simp only [← Category.assoc, hi] simpa) fac e w a := by simp only [Category.assoc, EffectiveEpiFamily.fac] rw [← Category.id_comp (e a), ← Category.assoc, ← Category.assoc] apply w simp only [Category.comp_id, Category.id_comp, ← Category.assoc] aesop uniq _ _ _ hm := by apply EffectiveEpiFamily.uniq _ f intro a rw [← hm a, ← Category.assoc, ← Category.assoc, hi, Category.id_comp] /-- An effective epi family precomposed with a family of split epis is effective epimorphic. -/ noncomputable def effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) [∀ a, IsSplitEpi (g a)] [EffectiveEpiFamily _ f] : EffectiveEpiFamilyStruct _ (fun a ↦ g a ≫ f a) := effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi' f g (fun a ↦ section_ (g a)) (fun a ↦ IsSplitEpi.id (g a)) instance {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) [∀ a, IsSplitEpi (g a)] [EffectiveEpiFamily _ f] : EffectiveEpiFamily _ (fun a ↦ g a ≫ f a) := ⟨⟨effectiveEpiFamilyStructCompOfEffectiveEpiSplitEpi f g⟩⟩ example {B X Y : C} (f : X ⟶ B) (g : Y ⟶ X) [IsSplitEpi g] [EffectiveEpi f] : EffectiveEpi (g ≫ f) := inferInstance instance IsSplitEpi.EffectiveEpi {B X : C} (f : X ⟶ B) [IsSplitEpi f] : EffectiveEpi f := by rw [← Category.comp_id f] infer_instance /-- If a family of morphisms with fixed target, precomposed by a family of epis is effective epimorphic, then the original family is as well. -/ noncomputable def effectiveEpiFamilyStructOfComp {C : Type*} [Category C] {I : Type*} {Z Y : I → C} {X : C} (g : ∀ i, Z i ⟶ Y i) (f : ∀ i, Y i ⟶ X) [EffectiveEpiFamily _ (fun i => g i ≫ f i)] [∀ i, Epi (g i)] : EffectiveEpiFamilyStruct _ f where desc {W} φ h := EffectiveEpiFamily.desc _ (fun i => g i ≫ f i) (fun i => g i ≫ φ i) (fun {T} i₁ i₂ g₁ g₂ eq => by simpa [assoc] using h i₁ i₂ (g₁ ≫ g i₁) (g₂ ≫ g i₂) (by simpa [assoc] using eq)) fac {W} φ h i := by rw [← cancel_epi (g i), ← assoc, EffectiveEpiFamily.fac _ (fun i => g i ≫ f i)] uniq {W} φ _ m hm := EffectiveEpiFamily.uniq _ (fun i => g i ≫ f i) _ _ _ (fun i => by rw [assoc, hm]) lemma effectiveEpiFamily_of_effectiveEpi_epi_comp {α : Type*} {B : C} {X Y : α → C} (f : (a : α) → X a ⟶ B) (g : (a : α) → Y a ⟶ X a) [∀ a, Epi (g a)] [EffectiveEpiFamily _ (fun a ↦ g a ≫ f a)] : EffectiveEpiFamily _ f := ⟨⟨effectiveEpiFamilyStructOfComp g f⟩⟩ lemma effectiveEpi_of_effectiveEpi_epi_comp {B X Y : C} (f : X ⟶ B) (g : Y ⟶ X) [Epi g] [EffectiveEpi (g ≫ f)] : EffectiveEpi f := have := (effectiveEpi_iff_effectiveEpiFamily (g ≫ f)).mp inferInstance have := effectiveEpiFamily_of_effectiveEpi_epi_comp (X := fun () ↦ X) (Y := fun () ↦ Y) (fun () ↦ f) (fun () ↦ g) inferInstance section CompIso variable {B B' : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) (i : B ⟶ B') theorem effectiveEpiFamilyStructCompIso_aux {W : C} (e : (a : α) → X a ⟶ W) (h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂), g₁ ≫ π a₁ ≫ i = g₂ ≫ π a₂ ≫ i → g₁ ≫ e a₁ = g₂ ≫ e a₂) {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂) (hg : g₁ ≫ π a₁ = g₂ ≫ π a₂) : g₁ ≫ e a₁ = g₂ ≫ e a₂ := by apply h rw [← Category.assoc, hg] simp variable [EffectiveEpiFamily X π] [IsIso i] /-- An effective epi family followed by an iso is an effective epi family. -/ noncomputable def effectiveEpiFamilyStructCompIso : EffectiveEpiFamilyStruct X (fun a ↦ π a ≫ i) where desc e h := inv i ≫ EffectiveEpiFamily.desc X π e (effectiveEpiFamilyStructCompIso_aux X π i e h) fac _ _ _ := by simp uniq e h m hm := by simp only [Category.assoc] at hm simp [← EffectiveEpiFamily.uniq X π e (effectiveEpiFamilyStructCompIso_aux X π i e h) (i ≫ m) hm] instance : EffectiveEpiFamily X (fun a ↦ π a ≫ i) := ⟨⟨effectiveEpiFamilyStructCompIso X π i⟩⟩ end CompIso section IsoComp variable {B : C} {α : Type*} (X Y : α → C) (π : (a : α) → (X a ⟶ B)) [EffectiveEpiFamily X π] (i : (a : α) → Y a ⟶ X a) [∀ a, IsIso (i a)] example : EffectiveEpiFamily Y (fun a ↦ i a ≫ π a) := inferInstance end IsoComp end CategoryTheory
Kronecker.lean
/- Copyright (c) 2021 Filippo A. E. Nuccio. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Filippo A. E. Nuccio, Eric Wieser -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Block import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.LinearAlgebra.TensorProduct.Basic import Mathlib.LinearAlgebra.TensorProduct.Associator import Mathlib.RingTheory.TensorProduct.Basic /-! # Kronecker product of matrices This defines the [Kronecker product](https://en.wikipedia.org/wiki/Kronecker_product). ## Main definitions * `Matrix.kroneckerMap`: A generalization of the Kronecker product: given a map `f : α → β → γ` and matrices `A` and `B` with coefficients in `α` and `β`, respectively, it is defined as the matrix with coefficients in `γ` such that `kroneckerMap f A B (i₁, i₂) (j₁, j₂) = f (A i₁ j₁) (B i₁ j₂)`. * `Matrix.kroneckerMapBilinear`: when `f` is bilinear, so is `kroneckerMap f`. ## Specializations * `Matrix.kronecker`: An alias of `kroneckerMap (*)`. Prefer using the notation. * `Matrix.kroneckerBilinear`: `Matrix.kronecker` is bilinear * `Matrix.kroneckerTMul`: An alias of `kroneckerMap (⊗ₜ)`. Prefer using the notation. * `Matrix.kroneckerTMulBilinear`: `Matrix.kroneckerTMul` is bilinear ## Notations These require `open Kronecker`: * `A ⊗ₖ B` for `kroneckerMap (*) A B`. Lemmas about this notation use the token `kronecker`. * `A ⊗ₖₜ B` and `A ⊗ₖₜ[R] B` for `kroneckerMap (⊗ₜ) A B`. Lemmas about this notation use the token `kroneckerTMul`. -/ namespace Matrix open scoped RightActions variable {R S α α' β β' γ γ' : Type*} variable {l m n p : Type*} {q r : Type*} {l' m' n' p' : Type*} section KroneckerMap /-- Produce a matrix with `f` applied to every pair of elements from `A` and `B`. -/ def kroneckerMap (f : α → β → γ) (A : Matrix l m α) (B : Matrix n p β) : Matrix (l × n) (m × p) γ := of fun (i : l × n) (j : m × p) => f (A i.1 j.1) (B i.2 j.2) -- TODO: set as an equation lemma for `kroneckerMap`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem kroneckerMap_apply (f : α → β → γ) (A : Matrix l m α) (B : Matrix n p β) (i j) : kroneckerMap f A B i j = f (A i.1 j.1) (B i.2 j.2) := rfl theorem kroneckerMap_transpose (f : α → β → γ) (A : Matrix l m α) (B : Matrix n p β) : kroneckerMap f Aᵀ Bᵀ = (kroneckerMap f A B)ᵀ := ext fun _ _ => rfl theorem kroneckerMap_map_left (f : α' → β → γ) (g : α → α') (A : Matrix l m α) (B : Matrix n p β) : kroneckerMap f (A.map g) B = kroneckerMap (fun a b => f (g a) b) A B := ext fun _ _ => rfl theorem kroneckerMap_map_right (f : α → β' → γ) (g : β → β') (A : Matrix l m α) (B : Matrix n p β) : kroneckerMap f A (B.map g) = kroneckerMap (fun a b => f a (g b)) A B := ext fun _ _ => rfl theorem kroneckerMap_map (f : α → β → γ) (g : γ → γ') (A : Matrix l m α) (B : Matrix n p β) : (kroneckerMap f A B).map g = kroneckerMap (fun a b => g (f a b)) A B := ext fun _ _ => rfl @[simp] theorem kroneckerMap_zero_left [Zero α] [Zero γ] (f : α → β → γ) (hf : ∀ b, f 0 b = 0) (B : Matrix n p β) : kroneckerMap f (0 : Matrix l m α) B = 0 := ext fun _ _ => hf _ @[simp] theorem kroneckerMap_zero_right [Zero β] [Zero γ] (f : α → β → γ) (hf : ∀ a, f a 0 = 0) (A : Matrix l m α) : kroneckerMap f A (0 : Matrix n p β) = 0 := ext fun _ _ => hf _ theorem kroneckerMap_add_left [Add α] [Add γ] (f : α → β → γ) (hf : ∀ a₁ a₂ b, f (a₁ + a₂) b = f a₁ b + f a₂ b) (A₁ A₂ : Matrix l m α) (B : Matrix n p β) : kroneckerMap f (A₁ + A₂) B = kroneckerMap f A₁ B + kroneckerMap f A₂ B := ext fun _ _ => hf _ _ _ theorem kroneckerMap_add_right [Add β] [Add γ] (f : α → β → γ) (hf : ∀ a b₁ b₂, f a (b₁ + b₂) = f a b₁ + f a b₂) (A : Matrix l m α) (B₁ B₂ : Matrix n p β) : kroneckerMap f A (B₁ + B₂) = kroneckerMap f A B₁ + kroneckerMap f A B₂ := ext fun _ _ => hf _ _ _ theorem kroneckerMap_smul_left [SMul R α] [SMul R γ] (f : α → β → γ) (r : R) (hf : ∀ a b, f (r • a) b = r • f a b) (A : Matrix l m α) (B : Matrix n p β) : kroneckerMap f (r • A) B = r • kroneckerMap f A B := ext fun _ _ => hf _ _ theorem kroneckerMap_smul_right [SMul R β] [SMul R γ] (f : α → β → γ) (r : R) (hf : ∀ a b, f a (r • b) = r • f a b) (A : Matrix l m α) (B : Matrix n p β) : kroneckerMap f A (r • B) = r • kroneckerMap f A B := ext fun _ _ => hf _ _ theorem kroneckerMap_single_single [Zero α] [Zero β] [Zero γ] [DecidableEq l] [DecidableEq m] [DecidableEq n] [DecidableEq p] (i₁ : l) (j₁ : m) (i₂ : n) (j₂ : p) (f : α → β → γ) (hf₁ : ∀ b, f 0 b = 0) (hf₂ : ∀ a, f a 0 = 0) (a : α) (b : β) : kroneckerMap f (single i₁ j₁ a) (single i₂ j₂ b) = single (i₁, i₂) (j₁, j₂) (f a b) := by ext ⟨i₁', i₂'⟩ ⟨j₁', j₂'⟩ dsimp [single] aesop @[deprecated (since := "2025-05-05")] alias kroneckerMap_stdBasisMatrix_stdBasisMatrix := kroneckerMap_single_single theorem kroneckerMap_diagonal_diagonal [Zero α] [Zero β] [Zero γ] [DecidableEq m] [DecidableEq n] (f : α → β → γ) (hf₁ : ∀ b, f 0 b = 0) (hf₂ : ∀ a, f a 0 = 0) (a : m → α) (b : n → β) : kroneckerMap f (diagonal a) (diagonal b) = diagonal fun mn => f (a mn.1) (b mn.2) := by ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ simp [diagonal, apply_ite f, ite_and, ite_apply, apply_ite (f (a i₁)), hf₁, hf₂] theorem kroneckerMap_diagonal_right [Zero β] [Zero γ] [DecidableEq n] (f : α → β → γ) (hf : ∀ a, f a 0 = 0) (A : Matrix l m α) (b : n → β) : kroneckerMap f A (diagonal b) = blockDiagonal fun i => A.map fun a => f a (b i) := by ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ simp [diagonal, blockDiagonal, apply_ite (f (A i₁ j₁)), hf] theorem kroneckerMap_diagonal_left [Zero α] [Zero γ] [DecidableEq l] (f : α → β → γ) (hf : ∀ b, f 0 b = 0) (a : l → α) (B : Matrix m n β) : kroneckerMap f (diagonal a) B = Matrix.reindex (Equiv.prodComm _ _) (Equiv.prodComm _ _) (blockDiagonal fun i => B.map fun b => f (a i) b) := by ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ simp [diagonal, blockDiagonal, apply_ite f, ite_apply, hf] @[simp] theorem kroneckerMap_one_one [Zero α] [Zero β] [Zero γ] [One α] [One β] [One γ] [DecidableEq m] [DecidableEq n] (f : α → β → γ) (hf₁ : ∀ b, f 0 b = 0) (hf₂ : ∀ a, f a 0 = 0) (hf₃ : f 1 1 = 1) : kroneckerMap f (1 : Matrix m m α) (1 : Matrix n n β) = 1 := (kroneckerMap_diagonal_diagonal _ hf₁ hf₂ _ _).trans <| by simp only [hf₃, diagonal_one] theorem kroneckerMap_reindex (f : α → β → γ) (el : l ≃ l') (em : m ≃ m') (en : n ≃ n') (ep : p ≃ p') (M : Matrix l m α) (N : Matrix n p β) : kroneckerMap f (reindex el em M) (reindex en ep N) = reindex (el.prodCongr en) (em.prodCongr ep) (kroneckerMap f M N) := by ext ⟨i, i'⟩ ⟨j, j'⟩ rfl theorem kroneckerMap_reindex_left (f : α → β → γ) (el : l ≃ l') (em : m ≃ m') (M : Matrix l m α) (N : Matrix n n' β) : kroneckerMap f (Matrix.reindex el em M) N = reindex (el.prodCongr (Equiv.refl _)) (em.prodCongr (Equiv.refl _)) (kroneckerMap f M N) := kroneckerMap_reindex _ _ _ (Equiv.refl _) (Equiv.refl _) _ _ theorem kroneckerMap_reindex_right (f : α → β → γ) (em : m ≃ m') (en : n ≃ n') (M : Matrix l l' α) (N : Matrix m n β) : kroneckerMap f M (reindex em en N) = reindex ((Equiv.refl _).prodCongr em) ((Equiv.refl _).prodCongr en) (kroneckerMap f M N) := kroneckerMap_reindex _ (Equiv.refl _) (Equiv.refl _) _ _ _ _ theorem kroneckerMap_assoc {δ ξ ω ω' : Type*} (f : α → β → γ) (g : γ → δ → ω) (f' : α → ξ → ω') (g' : β → δ → ξ) (A : Matrix l m α) (B : Matrix n p β) (D : Matrix q r δ) (φ : ω ≃ ω') (hφ : ∀ a b d, φ (g (f a b) d) = f' a (g' b d)) : (reindex (Equiv.prodAssoc l n q) (Equiv.prodAssoc m p r)).trans (Equiv.mapMatrix φ) (kroneckerMap g (kroneckerMap f A B) D) = kroneckerMap f' A (kroneckerMap g' B D) := ext fun _ _ => hφ _ _ _ theorem kroneckerMap_assoc₁ {δ ξ ω : Type*} (f : α → β → γ) (g : γ → δ → ω) (f' : α → ξ → ω) (g' : β → δ → ξ) (A : Matrix l m α) (B : Matrix n p β) (D : Matrix q r δ) (h : ∀ a b d, g (f a b) d = f' a (g' b d)) : reindex (Equiv.prodAssoc l n q) (Equiv.prodAssoc m p r) (kroneckerMap g (kroneckerMap f A B) D) = kroneckerMap f' A (kroneckerMap g' B D) := ext fun _ _ => h _ _ _ /-- When `f` is bilinear then `Matrix.kroneckerMap f` is also bilinear. -/ @[simps!] def kroneckerMapBilinear [Semiring S] [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] [Module R α] [Module R γ] [Module S β] [Module S γ] [SMulCommClass S R γ] (f : α →ₗ[R] β →ₗ[S] γ) : Matrix l m α →ₗ[R] Matrix n p β →ₗ[S] Matrix (l × n) (m × p) γ := LinearMap.mk₂' R S (kroneckerMap fun r s => f r s) (kroneckerMap_add_left _ <| f.map_add₂) (fun _ => kroneckerMap_smul_left _ _ <| f.map_smul₂ _) (kroneckerMap_add_right _ fun a => (f a).map_add) fun r => kroneckerMap_smul_right _ _ fun a => (f a).map_smul r /-- `Matrix.kroneckerMapBilinear` commutes with `*` if `f` does. This is primarily used with `R = ℕ` to prove `Matrix.mul_kronecker_mul`. -/ theorem kroneckerMapBilinear_mul_mul [Semiring S] [Semiring R] [Fintype m] [Fintype m'] [NonUnitalNonAssocSemiring α] [NonUnitalNonAssocSemiring β] [NonUnitalNonAssocSemiring γ] [Module R α] [Module R γ] [Module S β] [Module S γ] [SMulCommClass S R γ] (f : α →ₗ[R] β →ₗ[S] γ) (h_comm : ∀ a b a' b', f (a * b) (a' * b') = f a a' * f b b') (A : Matrix l m α) (B : Matrix m n α) (A' : Matrix l' m' β) (B' : Matrix m' n' β) : kroneckerMapBilinear f (A * B) (A' * B') = kroneckerMapBilinear f A A' * kroneckerMapBilinear f B B' := by ext ⟨i, i'⟩ ⟨j, j'⟩ simp only [kroneckerMapBilinear_apply_apply, mul_apply, ← Finset.univ_product_univ, Finset.sum_product, kroneckerMap_apply] simp_rw [map_sum f, LinearMap.sum_apply, map_sum, h_comm] /-- `trace` distributes over `Matrix.kroneckerMapBilinear`. This is primarily used with `R = ℕ` to prove `Matrix.trace_kronecker`. -/ theorem trace_kroneckerMapBilinear [Semiring S] [Semiring R] [Fintype m] [Fintype n] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] [Module R α] [Module R γ] [Module S β] [Module S γ] [SMulCommClass S R γ] (f : α →ₗ[R] β →ₗ[S] γ) (A : Matrix m m α) (B : Matrix n n β) : trace (kroneckerMapBilinear f A B) = f (trace A) (trace B) := by simp_rw [Matrix.trace, Matrix.diag, kroneckerMapBilinear_apply_apply, LinearMap.map_sum₂, map_sum, ← Finset.univ_product_univ, Finset.sum_product, kroneckerMap_apply] /-- `determinant` of `Matrix.kroneckerMapBilinear`. This is primarily used with `R = ℕ` to prove `Matrix.det_kronecker`. -/ theorem det_kroneckerMapBilinear [Semiring S] [Semiring R] [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n] [NonAssocSemiring α] [NonAssocSemiring β] [CommRing γ] [Module R α] [Module S β] [Module R γ] [Module S γ] [SMulCommClass S R γ] (f : α →ₗ[R] β →ₗ[S] γ) (h_comm : ∀ a b a' b', f (a * b) (a' * b') = f a a' * f b b') (A : Matrix m m α) (B : Matrix n n β) : det (kroneckerMapBilinear f A B) = det (A.map fun a => f a 1) ^ Fintype.card n * det (B.map fun b => f 1 b) ^ Fintype.card m := calc det (kroneckerMapBilinear f A B) = det (kroneckerMapBilinear f A 1 * kroneckerMapBilinear f 1 B) := by rw [← kroneckerMapBilinear_mul_mul f h_comm, Matrix.mul_one, Matrix.one_mul] _ = det (blockDiagonal fun (_ : n) => A.map fun a => f a 1) * det (blockDiagonal fun (_ : m) => B.map fun b => f 1 b) := by rw [det_mul, ← diagonal_one, ← diagonal_one, kroneckerMapBilinear_apply_apply, kroneckerMap_diagonal_right _ fun _ => _, kroneckerMapBilinear_apply_apply, kroneckerMap_diagonal_left _ fun _ => _, det_reindex_self] · intro; exact LinearMap.map_zero₂ _ _ · intro; exact map_zero _ _ = _ := by simp_rw [det_blockDiagonal, Finset.prod_const, Finset.card_univ] end KroneckerMap /-! ### Specialization to `Matrix.kroneckerMap (*)` -/ section Kronecker open Matrix /-- The Kronecker product. This is just a shorthand for `kroneckerMap (*)`. Prefer the notation `⊗ₖ` rather than this definition. -/ @[simp] def kronecker [Mul α] : Matrix l m α → Matrix n p α → Matrix (l × n) (m × p) α := kroneckerMap (· * ·) @[inherit_doc Matrix.kroneckerMap] scoped[Kronecker] infixl:100 " ⊗ₖ " => Matrix.kroneckerMap (· * ·) open Kronecker @[simp] theorem kronecker_apply [Mul α] (A : Matrix l m α) (B : Matrix n p α) (i₁ i₂ j₁ j₂) : (A ⊗ₖ B) (i₁, i₂) (j₁, j₂) = A i₁ j₁ * B i₂ j₂ := rfl /-- `Matrix.kronecker` as a bilinear map. -/ def kroneckerBilinear [CommSemiring R] [Semiring α] [Algebra R α] : Matrix l m α →ₗ[R] Matrix n p α →ₗ[R] Matrix (l × n) (m × p) α := kroneckerMapBilinear (Algebra.lmul R α) /-! What follows is a copy, in order, of every `Matrix.kroneckerMap` lemma above that has hypotheses which can be filled by properties of `*`. -/ theorem zero_kronecker [MulZeroClass α] (B : Matrix n p α) : (0 : Matrix l m α) ⊗ₖ B = 0 := kroneckerMap_zero_left _ zero_mul B theorem kronecker_zero [MulZeroClass α] (A : Matrix l m α) : A ⊗ₖ (0 : Matrix n p α) = 0 := kroneckerMap_zero_right _ mul_zero A theorem add_kronecker [Distrib α] (A₁ A₂ : Matrix l m α) (B : Matrix n p α) : (A₁ + A₂) ⊗ₖ B = A₁ ⊗ₖ B + A₂ ⊗ₖ B := kroneckerMap_add_left _ add_mul _ _ _ theorem kronecker_add [Distrib α] (A : Matrix l m α) (B₁ B₂ : Matrix n p α) : A ⊗ₖ (B₁ + B₂) = A ⊗ₖ B₁ + A ⊗ₖ B₂ := kroneckerMap_add_right _ mul_add _ _ _ theorem smul_kronecker [Mul α] [SMul R α] [IsScalarTower R α α] (r : R) (A : Matrix l m α) (B : Matrix n p α) : (r • A) ⊗ₖ B = r • A ⊗ₖ B := kroneckerMap_smul_left _ _ (fun _ _ => smul_mul_assoc _ _ _) _ _ theorem kronecker_smul [Mul α] [SMul R α] [SMulCommClass R α α] (r : R) (A : Matrix l m α) (B : Matrix n p α) : A ⊗ₖ (r • B) = r • A ⊗ₖ B := kroneckerMap_smul_right _ _ (fun _ _ => mul_smul_comm _ _ _) _ _ theorem single_kronecker_single [MulZeroClass α] [DecidableEq l] [DecidableEq m] [DecidableEq n] [DecidableEq p] (ia : l) (ja : m) (ib : n) (jb : p) (a b : α) : single ia ja a ⊗ₖ single ib jb b = single (ia, ib) (ja, jb) (a * b) := kroneckerMap_single_single _ _ _ _ _ zero_mul mul_zero _ _ @[deprecated (since := "2025-05-05")] alias stdBasisMatrix_kronecker_stdBasisMatrix := single_kronecker_single theorem diagonal_kronecker_diagonal [MulZeroClass α] [DecidableEq m] [DecidableEq n] (a : m → α) (b : n → α) : diagonal a ⊗ₖ diagonal b = diagonal fun mn => a mn.1 * b mn.2 := kroneckerMap_diagonal_diagonal _ zero_mul mul_zero _ _ theorem kronecker_diagonal [MulZeroClass α] [DecidableEq n] (A : Matrix l m α) (b : n → α) : A ⊗ₖ diagonal b = blockDiagonal fun i => A <• b i := kroneckerMap_diagonal_right _ mul_zero _ _ theorem diagonal_kronecker [MulZeroClass α] [DecidableEq l] (a : l → α) (B : Matrix m n α) : diagonal a ⊗ₖ B = Matrix.reindex (Equiv.prodComm _ _) (Equiv.prodComm _ _) (blockDiagonal fun i => a i • B) := kroneckerMap_diagonal_left _ zero_mul _ _ @[simp] theorem natCast_kronecker_natCast [NonAssocSemiring α] [DecidableEq m] [DecidableEq n] (a b : ℕ) : (a : Matrix m m α) ⊗ₖ (b : Matrix n n α) = ↑(a * b) := (diagonal_kronecker_diagonal _ _).trans <| by simp_rw [← Nat.cast_mul]; rfl theorem kronecker_natCast [NonAssocSemiring α] [DecidableEq n] (A : Matrix l m α) (b : ℕ) : A ⊗ₖ (b : Matrix n n α) = blockDiagonal fun _ => b • A := kronecker_diagonal _ _ |>.trans <| by congr! 2 ext simp [(Nat.cast_commute b _).eq] theorem natCast_kronecker [NonAssocSemiring α] [DecidableEq l] (a : ℕ) (B : Matrix m n α) : (a : Matrix l l α) ⊗ₖ B = Matrix.reindex (Equiv.prodComm _ _) (Equiv.prodComm _ _) (blockDiagonal fun _ => a • B) := diagonal_kronecker _ _ |>.trans <| by congr! 2 ext simp [(Nat.cast_commute a _).eq] theorem kronecker_ofNat [NonAssocSemiring α] [DecidableEq n] (A : Matrix l m α) (b : ℕ) [b.AtLeastTwo] : A ⊗ₖ (ofNat(b) : Matrix n n α) = blockDiagonal fun _ => A <• (ofNat(b) : α) := kronecker_diagonal _ _ theorem ofNat_kronecker [NonAssocSemiring α] [DecidableEq l] (a : ℕ) [a.AtLeastTwo] (B : Matrix m n α) : (ofNat(a) : Matrix l l α) ⊗ₖ B = Matrix.reindex (.prodComm _ _) (.prodComm _ _) (blockDiagonal fun _ => (ofNat(a) : α) • B) := diagonal_kronecker _ _ theorem one_kronecker_one [MulZeroOneClass α] [DecidableEq m] [DecidableEq n] : (1 : Matrix m m α) ⊗ₖ (1 : Matrix n n α) = 1 := kroneckerMap_one_one _ zero_mul mul_zero (one_mul _) theorem kronecker_one [MulZeroOneClass α] [DecidableEq n] (A : Matrix l m α) : A ⊗ₖ (1 : Matrix n n α) = blockDiagonal fun _ => A := (kronecker_diagonal _ _).trans <| congr_arg _ <| funext fun _ => Matrix.ext fun _ _ => mul_one _ theorem one_kronecker [MulZeroOneClass α] [DecidableEq l] (B : Matrix m n α) : (1 : Matrix l l α) ⊗ₖ B = Matrix.reindex (Equiv.prodComm _ _) (Equiv.prodComm _ _) (blockDiagonal fun _ => B) := (diagonal_kronecker _ _).trans <| congr_arg _ <| congr_arg _ <| funext fun _ => Matrix.ext fun _ _ => one_mul _ theorem mul_kronecker_mul [Fintype m] [Fintype m'] [CommSemiring α] (A : Matrix l m α) (B : Matrix m n α) (A' : Matrix l' m' α) (B' : Matrix m' n' α) : (A * B) ⊗ₖ (A' * B') = A ⊗ₖ A' * B ⊗ₖ B' := kroneckerMapBilinear_mul_mul (Algebra.lmul ℕ α).toLinearMap mul_mul_mul_comm A B A' B' -- simp-normal form is `kronecker_assoc'` theorem kronecker_assoc [Semigroup α] (A : Matrix l m α) (B : Matrix n p α) (C : Matrix q r α) : reindex (Equiv.prodAssoc l n q) (Equiv.prodAssoc m p r) (A ⊗ₖ B ⊗ₖ C) = A ⊗ₖ (B ⊗ₖ C) := kroneckerMap_assoc₁ _ _ _ _ A B C mul_assoc @[simp] theorem kronecker_assoc' [Semigroup α] (A : Matrix l m α) (B : Matrix n p α) (C : Matrix q r α) : submatrix (A ⊗ₖ B ⊗ₖ C) (Equiv.prodAssoc l n q).symm (Equiv.prodAssoc m p r).symm = A ⊗ₖ (B ⊗ₖ C) := kroneckerMap_assoc₁ _ _ _ _ A B C mul_assoc theorem trace_kronecker [Fintype m] [Fintype n] [Semiring α] (A : Matrix m m α) (B : Matrix n n α) : trace (A ⊗ₖ B) = trace A * trace B := trace_kroneckerMapBilinear (Algebra.lmul ℕ α).toLinearMap _ _ theorem det_kronecker [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n] [CommRing R] (A : Matrix m m R) (B : Matrix n n R) : det (A ⊗ₖ B) = det A ^ Fintype.card n * det B ^ Fintype.card m := by refine (det_kroneckerMapBilinear (Algebra.lmul ℕ R).toLinearMap mul_mul_mul_comm _ _).trans ?_ congr 3 · ext i j exact mul_one _ · ext i j exact one_mul _ end Kronecker /-! ### Specialization to `Matrix.kroneckerMap (⊗ₜ)` -/ section KroneckerTmul variable (R) open TensorProduct open Matrix TensorProduct section Module variable [CommSemiring R] variable [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The Kronecker tensor product. This is just a shorthand for `kroneckerMap (⊗ₜ)`. Prefer the notation `⊗ₖₜ` rather than this definition. -/ @[simp] def kroneckerTMul : Matrix l m α → Matrix n p β → Matrix (l × n) (m × p) (α ⊗[R] β) := kroneckerMap (· ⊗ₜ ·) @[inherit_doc kroneckerTMul] scoped[Kronecker] infixl:100 " ⊗ₖₜ " => Matrix.kroneckerMap (· ⊗ₜ ·) @[inherit_doc kroneckerTMul] scoped[Kronecker] notation:100 x " ⊗ₖₜ[" R "] " y:100 => Matrix.kroneckerMap (TensorProduct.tmul R) x y open Kronecker @[simp] theorem kroneckerTMul_apply (A : Matrix l m α) (B : Matrix n p β) (i₁ i₂ j₁ j₂) : (A ⊗ₖₜ B) (i₁, i₂) (j₁, j₂) = A i₁ j₁ ⊗ₜ[R] B i₂ j₂ := rfl variable (S) in /-- `Matrix.kronecker` as a bilinear map. -/ def kroneckerTMulBilinear [Semiring S] [Module S α] [SMulCommClass R S α] : Matrix l m α →ₗ[S] Matrix n p β →ₗ[R] Matrix (l × n) (m × p) (α ⊗[R] β) := kroneckerMapBilinear (AlgebraTensorModule.mk _ _ α β) @[simp] theorem kroneckerTMulBilinear_apply [Semiring S] [Module S α] [SMulCommClass R S α] (A : Matrix l m α) (B : Matrix n p β) : kroneckerTMulBilinear R S A B = A ⊗ₖₜ[R] B := rfl /-! What follows is a copy, in order, of every `Matrix.kroneckerMap` lemma above that has hypotheses which can be filled by properties of `⊗ₜ`. -/ theorem zero_kroneckerTMul (B : Matrix n p β) : (0 : Matrix l m α) ⊗ₖₜ[R] B = 0 := kroneckerMap_zero_left _ (zero_tmul α) B theorem kroneckerTMul_zero (A : Matrix l m α) : A ⊗ₖₜ[R] (0 : Matrix n p β) = 0 := kroneckerMap_zero_right _ (tmul_zero β) A theorem add_kroneckerTMul (A₁ A₂ : Matrix l m α) (B : Matrix n p α) : (A₁ + A₂) ⊗ₖₜ[R] B = A₁ ⊗ₖₜ B + A₂ ⊗ₖₜ B := kroneckerMap_add_left _ add_tmul _ _ _ theorem kroneckerTMul_add (A : Matrix l m α) (B₁ B₂ : Matrix n p β) : A ⊗ₖₜ[R] (B₁ + B₂) = A ⊗ₖₜ B₁ + A ⊗ₖₜ B₂ := kroneckerMap_add_right _ tmul_add _ _ _ theorem smul_kroneckerTMul [Monoid S] [DistribMulAction S α] [SMulCommClass R S α] (r : S) (A : Matrix l m α) (B : Matrix n p β) : (r • A) ⊗ₖₜ[R] B = r • A ⊗ₖₜ[R] B := kroneckerMap_smul_left _ _ (fun _ _ => smul_tmul' _ _ _) _ _ theorem kroneckerTMul_smul [Monoid S] [DistribMulAction S α] [DistribMulAction S β] [SMul S R] [SMulCommClass R S α] [IsScalarTower S R α] [IsScalarTower S R β] (r : S) (A : Matrix l m α) (B : Matrix n p β) : A ⊗ₖₜ[R] (r • B) = r • A ⊗ₖₜ[R] B := kroneckerMap_smul_right _ _ (fun _ _ => tmul_smul _ _ _) _ _ theorem single_kroneckerTMul_single [DecidableEq l] [DecidableEq m] [DecidableEq n] [DecidableEq p] (i₁ : l) (j₁ : m) (i₂ : n) (j₂ : p) (a : α) (b : β) : single i₁ j₁ a ⊗ₖₜ[R] single i₂ j₂ b = single (i₁, i₂) (j₁, j₂) (a ⊗ₜ b) := kroneckerMap_single_single _ _ _ _ _ (zero_tmul _) (tmul_zero _) _ _ @[deprecated (since := "2025-05-05")] alias stdBasisMatrix_kroneckerTMul_stdBasisMatrix := single_kroneckerTMul_single theorem diagonal_kroneckerTMul_diagonal [DecidableEq m] [DecidableEq n] (a : m → α) (b : n → β) : diagonal a ⊗ₖₜ[R] diagonal b = diagonal fun mn => a mn.1 ⊗ₜ b mn.2 := kroneckerMap_diagonal_diagonal _ (zero_tmul _) (tmul_zero _) _ _ theorem kroneckerTMul_diagonal [DecidableEq n] (A : Matrix l m α) (b : n → β) : A ⊗ₖₜ[R] diagonal b = blockDiagonal fun i => A.map fun a => a ⊗ₜ[R] b i := kroneckerMap_diagonal_right _ (tmul_zero _) _ _ theorem diagonal_kroneckerTMul [DecidableEq l] (a : l → α) (B : Matrix m n β) : diagonal a ⊗ₖₜ[R] B = Matrix.reindex (Equiv.prodComm _ _) (Equiv.prodComm _ _) (blockDiagonal fun i => B.map fun b => a i ⊗ₜ[R] b) := kroneckerMap_diagonal_left _ (zero_tmul _) _ _ -- simp-normal form is `kroneckerTMul_assoc'` theorem kroneckerTMul_assoc (A : Matrix l m α) (B : Matrix n p β) (C : Matrix q r γ) : reindex (Equiv.prodAssoc l n q) (Equiv.prodAssoc m p r) (((A ⊗ₖₜ[R] B) ⊗ₖₜ[R] C).map (TensorProduct.assoc R α β γ)) = A ⊗ₖₜ[R] B ⊗ₖₜ[R] C := ext fun _ _ => assoc_tmul _ _ _ @[simp] theorem kroneckerTMul_assoc' (A : Matrix l m α) (B : Matrix n p β) (C : Matrix q r γ) : submatrix (((A ⊗ₖₜ[R] B) ⊗ₖₜ[R] C).map (TensorProduct.assoc R α β γ)) (Equiv.prodAssoc l n q).symm (Equiv.prodAssoc m p r).symm = A ⊗ₖₜ[R] B ⊗ₖₜ[R] C := ext fun _ _ => assoc_tmul _ _ _ theorem trace_kroneckerTMul [Fintype m] [Fintype n] (A : Matrix m m α) (B : Matrix n n β) : trace (A ⊗ₖₜ[R] B) = trace A ⊗ₜ[R] trace B := trace_kroneckerMapBilinear (TensorProduct.mk R α β) _ _ end Module section Algebra open Kronecker open Algebra.TensorProduct section Semiring variable [CommSemiring R] @[simp] theorem one_kroneckerTMul_one [AddCommMonoidWithOne α] [AddCommMonoidWithOne β] [Module R α] [Module R β] [DecidableEq m] [DecidableEq n] : (1 : Matrix m m α) ⊗ₖₜ[R] (1 : Matrix n n β) = 1 := kroneckerMap_one_one _ (zero_tmul _) (tmul_zero _) rfl unseal mul in theorem mul_kroneckerTMul_mul [NonUnitalSemiring α] [NonUnitalSemiring β] [Module R α] [Module R β] [IsScalarTower R α α] [SMulCommClass R α α] [IsScalarTower R β β] [SMulCommClass R β β] [Fintype m] [Fintype m'] (A : Matrix l m α) (B : Matrix m n α) (A' : Matrix l' m' β) (B' : Matrix m' n' β) : (A * B) ⊗ₖₜ[R] (A' * B') = A ⊗ₖₜ[R] A' * B ⊗ₖₜ[R] B' := kroneckerMapBilinear_mul_mul (TensorProduct.mk R α β) tmul_mul_tmul A B A' B' end Semiring section CommRing variable [CommRing R] [CommRing α] [CommRing β] [Algebra R α] [Algebra R β] unseal mul in theorem det_kroneckerTMul [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n] (A : Matrix m m α) (B : Matrix n n β) : det (A ⊗ₖₜ[R] B) = (det A ^ Fintype.card n) ⊗ₜ[R] (det B ^ Fintype.card m) := by refine (det_kroneckerMapBilinear (TensorProduct.mk R α β) tmul_mul_tmul _ _).trans ?_ simp -eta only [mk_apply, ← includeLeft_apply (S := R), ← includeRight_apply] simp only [← AlgHom.mapMatrix_apply, ← AlgHom.map_det] simp only [includeLeft_apply, includeRight_apply, tmul_pow, tmul_mul_tmul, one_pow, _root_.mul_one, _root_.one_mul] end CommRing end Algebra -- insert lemmas specific to `kroneckerTMul` below this line end KroneckerTmul end Matrix
all_fingroup.v
From mathcomp Require Export action. From mathcomp Require Export automorphism. From mathcomp Require Export fingroup. From mathcomp Require Export gproduct. From mathcomp Require Export morphism. From mathcomp Require Export perm. From mathcomp Require Export presentation. From mathcomp Require Export quotient.
Finite.lean
/- Copyright (c) 2021 Jordan Brown, Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jordan Brown, Thomas Browning, Patrick Lutz -/ import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.GroupTheory.Commutator.Basic import Mathlib.GroupTheory.Rank import Mathlib.GroupTheory.Index /-! The commutator of a finite direct product is contained in the direct product of the commutators. -/ variable {G : Type*} [Group G] namespace Subgroup /-- The commutator of a finite direct product is contained in the direct product of the commutators. -/ theorem commutator_pi_pi_of_finite {η : Type*} [Finite η] {Gs : η → Type*} [∀ i, Group (Gs i)] (H K : ∀ i, Subgroup (Gs i)) : ⁅Subgroup.pi Set.univ H, Subgroup.pi Set.univ K⁆ = Subgroup.pi Set.univ fun i => ⁅H i, K i⁆ := by classical apply le_antisymm (commutator_pi_pi_le H K) rw [pi_le_iff] intro i hi rw [map_commutator] apply commutator_mono <;> · rw [le_pi_iff] intro j _hj rintro _ ⟨_, ⟨x, hx, rfl⟩, rfl⟩ by_cases h : j = i · subst h simpa using hx · simp [h, one_mem] variable [Finite (commutatorSet G)] instance : Group.FG (_root_.commutator G) := by rw [commutator_eq_closure]; apply Group.closure_finite_fg variable (G) in lemma rank_commutator_le_card : Group.rank (_root_.commutator G) ≤ Nat.card (commutatorSet G) := by rw [Subgroup.rank_congr (commutator_eq_closure G)] apply Subgroup.rank_closure_finite_le_nat_card variable [Group.FG G] instance finiteIndex_center : FiniteIndex (center G) := by obtain ⟨S, -, hS⟩ := Group.rank_spec G exact ⟨mt (Finite.card_eq_zero_of_embedding (quotientCenterEmbedding hS)) Finite.card_pos.ne'⟩ variable (G) in lemma index_center_le_pow : (center G).index ≤ Nat.card (commutatorSet G) ^ Group.rank G := by obtain ⟨S, hS1, hS2⟩ := Group.rank_spec G rw [← hS1, ← Fintype.card_coe, ← Nat.card_eq_fintype_card, ← Finset.coe_sort_coe, ← Nat.card_fun] exact Finite.card_le_of_embedding (quotientCenterEmbedding hS2) end Subgroup section commutatorRepresentatives open Subgroup lemma card_commutatorSet_closureCommutatorRepresentatives : Nat.card (commutatorSet (closureCommutatorRepresentatives G)) = Nat.card (commutatorSet G) := by rw [← image_commutatorSet_closureCommutatorRepresentatives G] exact Nat.card_congr (Equiv.Set.image _ _ (subtype_injective _)) lemma card_commutator_closureCommutatorRepresentatives : Nat.card (commutator (closureCommutatorRepresentatives G)) = Nat.card (commutator G) := by rw [commutator_eq_closure G, ← image_commutatorSet_closureCommutatorRepresentatives, ← MonoidHom.map_closure, ← commutator_eq_closure] exact Nat.card_congr (Equiv.Set.image _ _ (subtype_injective _)) variable [Finite (commutatorSet G)] instance : Finite (commutatorRepresentatives G) := Set.finite_coe_iff.mpr (Set.finite_range _) instance closureCommutatorRepresentatives_fg : Group.FG (closureCommutatorRepresentatives G) := Group.closure_finite_fg _ variable (G) in lemma rank_closureCommutatorRepresentatives_le : Group.rank (closureCommutatorRepresentatives G) ≤ 2 * Nat.card (commutatorSet G) := by rw [two_mul] exact (Subgroup.rank_closure_finite_le_nat_card _).trans ((Set.card_union_le _ _).trans (add_le_add ((Finite.card_image_le _).trans (Finite.card_range_le _)) ((Finite.card_image_le _).trans (Finite.card_range_le _)))) instance : Finite (commutatorSet (closureCommutatorRepresentatives G)) := by apply Nat.finite_of_card_ne_zero rw [card_commutatorSet_closureCommutatorRepresentatives] exact Finite.card_pos.ne' end commutatorRepresentatives
Monoid.lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Mitchell Lee -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Group.ULift import Mathlib.Order.Filter.Pointwise import Mathlib.Topology.Algebra.MulAction import Mathlib.Topology.ContinuousMap.Defs import Mathlib.Topology.Algebra.Monoid.Defs /-! # Theory of topological monoids In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many applications the underlying type is a monoid (multiplicative or additive), we do not require this in the definitions. -/ universe u v open Set Filter TopologicalSpace Topology open scoped Topology Pointwise variable {ι α M N X : Type*} [TopologicalSpace X] @[to_additive (attr := continuity, fun_prop)] theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X → M) := @continuous_const _ _ _ _ 1 section ContinuousMul variable [TopologicalSpace M] [Mul M] [ContinuousMul M] @[to_additive] instance : ContinuousMul Mᵒᵈ := ‹ContinuousMul M› @[to_additive] instance : ContinuousMul (ULift.{u} M) := by constructor apply continuous_uliftUp.comp exact continuous_mul.comp₂ (continuous_uliftDown.comp continuous_fst) (continuous_uliftDown.comp continuous_snd) @[to_additive] instance ContinuousMul.to_continuousSMul : ContinuousSMul M M := ⟨continuous_mul⟩ @[to_additive] instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mᵐᵒᵖ M := ⟨show Continuous ((fun p : M × M => p.1 * p.2) ∘ Prod.swap ∘ Prod.map MulOpposite.unop id) from continuous_mul.comp <| continuous_swap.comp <| Continuous.prodMap MulOpposite.continuous_unop continuous_id⟩ @[to_additive] theorem ContinuousMul.induced {α : Type*} {β : Type*} {F : Type*} [FunLike F α β] [Mul α] [Mul β] [MulHomClass F α β] [tβ : TopologicalSpace β] [ContinuousMul β] (f : F) : @ContinuousMul α (tβ.induced f) _ := by let tα := tβ.induced f refine ⟨continuous_induced_rng.2 ?_⟩ simp only [Function.comp_def, map_mul] fun_prop @[to_additive (attr := continuity)] theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b := continuous_const.mul continuous_id @[to_additive (attr := continuity)] theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a := continuous_id.mul continuous_const @[to_additive] theorem tendsto_mul {a b : M} : Tendsto (fun p : M × M => p.fst * p.snd) (𝓝 (a, b)) (𝓝 (a * b)) := continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b) @[to_additive] theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : α → M} {l : Filter α} (h : Tendsto (fun k : α => f k) l (𝓝 c)) : Tendsto (fun k : α => b * f k) l (𝓝 (b * c)) := tendsto_const_nhds.mul h @[to_additive] theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : α → M} {l : Filter α} (h : Tendsto (fun k : α => f k) l (𝓝 c)) : Tendsto (fun k : α => f k * b) l (𝓝 (c * b)) := h.mul tendsto_const_nhds @[to_additive] theorem le_nhds_mul (a b : M) : 𝓝 a * 𝓝 b ≤ 𝓝 (a * b) := by rw [← map₂_mul, ← map_uncurry_prod, ← nhds_prod_eq] exact continuous_mul.tendsto _ @[to_additive (attr := simp)] theorem nhds_one_mul_nhds {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : 𝓝 (1 : M) * 𝓝 a = 𝓝 a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (one_mul a)).antisymm <| le_mul_of_one_le_left' <| pure_le_nhds 1 @[to_additive (attr := simp)] theorem nhds_mul_nhds_one {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : 𝓝 a * 𝓝 1 = 𝓝 a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (mul_one a)).antisymm <| le_mul_of_one_le_right' <| pure_le_nhds 1 section tendsto_nhds variable {𝕜 : Type*} [Preorder 𝕜] [Zero 𝕜] [Mul 𝕜] [TopologicalSpace 𝕜] [ContinuousMul 𝕜] {l : Filter α} {f : α → 𝕜} {b c : 𝕜} (hb : 0 < b) include hb theorem Filter.TendstoNhdsWithinIoi.const_mul [PosMulStrictMono 𝕜] [PosMulReflectLT 𝕜] (h : Tendsto f l (𝓝[>] c)) : Tendsto (fun a => b * f a) l (𝓝[>] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr theorem Filter.TendstoNhdsWithinIio.const_mul [PosMulStrictMono 𝕜] [PosMulReflectLT 𝕜] (h : Tendsto f l (𝓝[<] c)) : Tendsto (fun a => b * f a) l (𝓝[<] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr theorem Filter.TendstoNhdsWithinIoi.mul_const [MulPosStrictMono 𝕜] [MulPosReflectLT 𝕜] (h : Tendsto f l (𝓝[>] c)) : Tendsto (fun a => f a * b) l (𝓝[>] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr theorem Filter.TendstoNhdsWithinIio.mul_const [MulPosStrictMono 𝕜] [MulPosReflectLT 𝕜] (h : Tendsto f l (𝓝[<] c)) : Tendsto (fun a => f a * b) l (𝓝[<] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr end tendsto_nhds @[to_additive] protected theorem Specializes.mul {a b c d : M} (hab : a ⤳ b) (hcd : c ⤳ d) : (a * c) ⤳ (b * d) := hab.smul hcd @[to_additive] protected theorem Inseparable.mul {a b c d : M} (hab : Inseparable a b) (hcd : Inseparable c d) : Inseparable (a * c) (b * d) := hab.smul hcd @[to_additive] protected theorem Specializes.pow {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {a b : M} (h : a ⤳ b) (n : ℕ) : (a ^ n) ⤳ (b ^ n) := Nat.recOn n (by simp only [pow_zero, specializes_rfl]) fun _ ihn ↦ by simpa only [pow_succ] using ihn.mul h @[to_additive] protected theorem Inseparable.pow {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {a b : M} (h : Inseparable a b) (n : ℕ) : Inseparable (a ^ n) (b ^ n) := (h.specializes.pow n).antisymm (h.specializes'.pow n) /-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) /-- Construct an additive unit from limits of additive units and their negatives. -/] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ι → Nˣ} {r₁ r₂ : N} {l : Filter ι} [l.NeBot] (h₁ : Tendsto (fun x => ↑(f x)) l (𝓝 r₁)) (h₂ : Tendsto (fun x => ↑(f x)⁻¹) l (𝓝 r₂)) : Nˣ where val := r₁ inv := r₂ val_inv := by symm simpa using h₁.mul h₂ inv_val := by symm simpa using h₂.mul h₁ @[to_additive] instance Prod.continuousMul [TopologicalSpace N] [Mul N] [ContinuousMul N] : ContinuousMul (M × N) := ⟨by apply Continuous.prodMk <;> fun_prop⟩ @[to_additive] instance Pi.continuousMul {C : ι → Type*} [∀ i, TopologicalSpace (C i)] [∀ i, Mul (C i)] [∀ i, ContinuousMul (C i)] : ContinuousMul (∀ i, C i) where continuous_mul := continuous_pi fun i => (continuous_apply i).fst'.mul (continuous_apply i).snd' /-- A version of `Pi.continuousMul` for non-dependent functions. It is needed because sometimes Lean 3 fails to use `Pi.continuousMul` for non-dependent functions. -/ @[to_additive /-- A version of `Pi.continuousAdd` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousAdd` for non-dependent functions. -/] instance Pi.continuousMul' : ContinuousMul (ι → M) := Pi.continuousMul @[to_additive] instance (priority := 100) continuousMul_of_discreteTopology [TopologicalSpace N] [Mul N] [DiscreteTopology N] : ContinuousMul N := ⟨continuous_of_discreteTopology⟩ open Filter open Function @[to_additive] theorem ContinuousMul.of_nhds_one {M : Type u} [Monoid M] [TopologicalSpace M] (hmul : Tendsto (uncurry ((· * ·) : M → M → M)) (𝓝 1 ×ˢ 𝓝 1) <| 𝓝 1) (hleft : ∀ x₀ : M, 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1)) (hright : ∀ x₀ : M, 𝓝 x₀ = map (fun x => x * x₀) (𝓝 1)) : ContinuousMul M := ⟨by rw [continuous_iff_continuousAt] rintro ⟨x₀, y₀⟩ have key : (fun p : M × M => x₀ * p.1 * (p.2 * y₀)) = ((fun x => x₀ * x) ∘ fun x => x * y₀) ∘ uncurry (· * ·) := by ext p simp [uncurry, mul_assoc] have key₂ : ((fun x => x₀ * x) ∘ fun x => y₀ * x) = fun x => x₀ * y₀ * x := by ext x simp [mul_assoc] calc map (uncurry (· * ·)) (𝓝 (x₀, y₀)) = map (uncurry (· * ·)) (𝓝 x₀ ×ˢ 𝓝 y₀) := by rw [nhds_prod_eq] _ = map (fun p : M × M => x₀ * p.1 * (p.2 * y₀)) (𝓝 1 ×ˢ 𝓝 1) := by -- Porting note: `rw` was able to prove this -- Now it fails with `failed to rewrite using equation theorems for 'Function.uncurry'` -- and `failed to rewrite using equation theorems for 'Function.comp'`. -- Removing those two lemmas, the `rw` would succeed, but then needs a `rfl`. simp +unfoldPartialApp only [uncurry] simp_rw [hleft x₀, hright y₀, prod_map_map_eq, Filter.map_map, Function.comp_def] _ = map ((fun x => x₀ * x) ∘ fun x => x * y₀) (map (uncurry (· * ·)) (𝓝 1 ×ˢ 𝓝 1)) := by rw [key, ← Filter.map_map] _ ≤ map ((fun x : M => x₀ * x) ∘ fun x => x * y₀) (𝓝 1) := map_mono hmul _ = 𝓝 (x₀ * y₀) := by rw [← Filter.map_map, ← hright, hleft y₀, Filter.map_map, key₂, ← hleft]⟩ @[to_additive] theorem continuousMul_of_comm_of_nhds_one (M : Type u) [CommMonoid M] [TopologicalSpace M] (hmul : Tendsto (uncurry ((· * ·) : M → M → M)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : M, 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1)) : ContinuousMul M := by apply ContinuousMul.of_nhds_one hmul hleft intro x₀ simp_rw [mul_comm, hleft x₀] end ContinuousMul section PointwiseLimits variable (M₁ M₂ : Type*) [TopologicalSpace M₂] [T2Space M₂] @[to_additive] theorem isClosed_setOf_map_one [One M₁] [One M₂] : IsClosed { f : M₁ → M₂ | f 1 = 1 } := isClosed_eq (continuous_apply 1) continuous_const @[to_additive] theorem isClosed_setOf_map_mul [Mul M₁] [Mul M₂] [ContinuousMul M₂] : IsClosed { f : M₁ → M₂ | ∀ x y, f (x * y) = f x * f y } := by simp only [setOf_forall] exact isClosed_iInter fun x ↦ isClosed_iInter fun y ↦ isClosed_eq (continuous_apply _) (by fun_prop) section Semigroup variable {M₁ M₂} [Mul M₁] [Mul M₂] [ContinuousMul M₂] {F : Type*} [FunLike F M₁ M₂] [MulHomClass F M₁ M₂] {l : Filter α} /-- Construct a bundled semigroup homomorphism `M₁ →ₙ* M₂` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ →ₙ* M₂` (or another type of bundled homomorphisms that has a `MulHomClass` instance) to `M₁ → M₂`. -/ @[to_additive (attr := simps -fullyApplied) /-- Construct a bundled additive semigroup homomorphism `M₁ →ₙ+ M₂` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ →ₙ+ M₂` (or another type of bundled homomorphisms that has an `AddHomClass` instance) to `M₁ → M₂`. -/] def mulHomOfMemClosureRangeCoe (f : M₁ → M₂) (hf : f ∈ closure (range fun (f : F) (x : M₁) => f x)) : M₁ →ₙ* M₂ where toFun := f map_mul' := (isClosed_setOf_map_mul M₁ M₂).closure_subset_iff.2 (range_subset_iff.2 map_mul) hf /-- Construct a bundled semigroup homomorphism from a pointwise limit of semigroup homomorphisms. -/ @[to_additive (attr := simps! -fullyApplied) /-- Construct a bundled additive semigroup homomorphism from a pointwise limit of additive semigroup homomorphisms -/] def mulHomOfTendsto (f : M₁ → M₂) (g : α → F) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ →ₙ* M₂ := mulHomOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| Eventually.of_forall fun _ => mem_range_self _ variable (M₁ M₂) @[to_additive] theorem MulHom.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ →ₙ* M₂) → M₁ → M₂)) := isClosed_of_closure_subset fun f hf => ⟨mulHomOfMemClosureRangeCoe f hf, rfl⟩ end Semigroup section Monoid variable {M₁ M₂} [MulOneClass M₁] [MulOneClass M₂] [ContinuousMul M₂] {F : Type*} [FunLike F M₁ M₂] [MonoidHomClass F M₁ M₂] {l : Filter α} /-- Construct a bundled monoid homomorphism `M₁ →* M₂` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ →* M₂` (or another type of bundled homomorphisms that has a `MonoidHomClass` instance) to `M₁ → M₂`. -/ @[to_additive (attr := simps -fullyApplied) /-- Construct a bundled additive monoid homomorphism `M₁ →+ M₂` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ →+ M₂` (or another type of bundled homomorphisms that has an `AddMonoidHomClass` instance) to `M₁ → M₂`. -/] def monoidHomOfMemClosureRangeCoe (f : M₁ → M₂) (hf : f ∈ closure (range fun (f : F) (x : M₁) => f x)) : M₁ →* M₂ where toFun := f map_one' := (isClosed_setOf_map_one M₁ M₂).closure_subset_iff.2 (range_subset_iff.2 map_one) hf map_mul' := (isClosed_setOf_map_mul M₁ M₂).closure_subset_iff.2 (range_subset_iff.2 map_mul) hf /-- Construct a bundled monoid homomorphism from a pointwise limit of monoid homomorphisms. -/ @[to_additive (attr := simps! -fullyApplied) /-- Construct a bundled additive monoid homomorphism from a pointwise limit of additive monoid homomorphisms -/] def monoidHomOfTendsto (f : M₁ → M₂) (g : α → F) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ →* M₂ := monoidHomOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| Eventually.of_forall fun _ => mem_range_self _ variable (M₁ M₂) @[to_additive] theorem MonoidHom.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ →* M₂) → M₁ → M₂)) := isClosed_of_closure_subset fun f hf => ⟨monoidHomOfMemClosureRangeCoe f hf, rfl⟩ end Monoid end PointwiseLimits @[to_additive] theorem Topology.IsInducing.continuousMul {M N F : Type*} [Mul M] [Mul N] [FunLike F M N] [MulHomClass F M N] [TopologicalSpace M] [TopologicalSpace N] [ContinuousMul N] (f : F) (hf : IsInducing f) : ContinuousMul M := ⟨(hf.continuousSMul hf.continuous (map_mul f _ _)).1⟩ @[to_additive] theorem continuousMul_induced {M N F : Type*} [Mul M] [Mul N] [FunLike F M N] [MulHomClass F M N] [TopologicalSpace N] [ContinuousMul N] (f : F) : @ContinuousMul M (induced f ‹_›) _ := letI := induced f ‹_› IsInducing.continuousMul f ⟨rfl⟩ @[to_additive] instance Subsemigroup.continuousMul [TopologicalSpace M] [Semigroup M] [ContinuousMul M] (S : Subsemigroup M) : ContinuousMul S := IsInducing.continuousMul ({ toFun := (↑), map_mul' := fun _ _ => rfl} : MulHom S M) ⟨rfl⟩ @[to_additive] instance Submonoid.continuousMul [TopologicalSpace M] [Monoid M] [ContinuousMul M] (S : Submonoid M) : ContinuousMul S := S.toSubsemigroup.continuousMul section MulZeroClass open Filter variable {α β : Type*} variable [TopologicalSpace M] [MulZeroClass M] [ContinuousMul M] theorem exists_mem_nhds_zero_mul_subset {K U : Set M} (hK : IsCompact K) (hU : U ∈ 𝓝 0) : ∃ V ∈ 𝓝 0, K * V ⊆ U := by refine hK.induction_on ?_ ?_ ?_ ?_ · exact ⟨univ, by simp⟩ · rintro s t hst ⟨V, hV, hV'⟩ exact ⟨V, hV, (mul_subset_mul_right hst).trans hV'⟩ · rintro s t ⟨V, V_in, hV'⟩ ⟨W, W_in, hW'⟩ use V ∩ W, inter_mem V_in W_in rw [union_mul] exact union_subset ((mul_subset_mul_left V.inter_subset_left).trans hV') ((mul_subset_mul_left V.inter_subset_right).trans hW') · intro x hx have := tendsto_mul (show U ∈ 𝓝 (x * 0) by simpa using hU) rw [nhds_prod_eq, mem_map, mem_prod_iff] at this rcases this with ⟨t, ht, s, hs, h⟩ rw [← image_subset_iff, image_mul_prod] at h exact ⟨t, mem_nhdsWithin_of_mem_nhds ht, s, hs, h⟩ /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M` which is disjoint from the cocompact filter. Then, the multiplication map `M × M → M` tends to zero on the filter product `𝓝 0 ×ˢ l`. -/ theorem tendsto_mul_nhds_zero_prod_of_disjoint_cocompact {l : Filter M} (hl : Disjoint l (cocompact M)) : Tendsto (fun x : M × M ↦ x.1 * x.2) (𝓝 0 ×ˢ l) (𝓝 0) := calc map (fun x : M × M ↦ x.1 * x.2) (𝓝 0 ×ˢ l) _ ≤ map (fun x : M × M ↦ x.1 * x.2) (𝓝ˢ ({0} ×ˢ Set.univ)) := map_mono <| nhds_prod_le_of_disjoint_cocompact 0 hl _ ≤ 𝓝 0 := continuous_mul.tendsto_nhdsSet_nhds fun _ ⟨hx, _⟩ ↦ mul_eq_zero_of_left hx _ /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M` which is disjoint from the cocompact filter. Then, the multiplication map `M × M → M` tends to zero on the filter product `l ×ˢ 𝓝 0`. -/ theorem tendsto_mul_prod_nhds_zero_of_disjoint_cocompact {l : Filter M} (hl : Disjoint l (cocompact M)) : Tendsto (fun x : M × M ↦ x.1 * x.2) (l ×ˢ 𝓝 0) (𝓝 0) := calc map (fun x : M × M ↦ x.1 * x.2) (l ×ˢ 𝓝 0) _ ≤ map (fun x : M × M ↦ x.1 * x.2) (𝓝ˢ (Set.univ ×ˢ {0})) := map_mono <| prod_nhds_le_of_disjoint_cocompact 0 hl _ ≤ 𝓝 0 := continuous_mul.tendsto_nhdsSet_nhds fun _ ⟨_, hx⟩ ↦ mul_eq_zero_of_right _ hx /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M × M` which is disjoint from the cocompact filter. Then, the multiplication map `M × M → M` tends to zero on `(𝓝 0).coprod (𝓝 0) ⊓ l`. -/ theorem tendsto_mul_coprod_nhds_zero_inf_of_disjoint_cocompact {l : Filter (M × M)} (hl : Disjoint l (cocompact (M × M))) : Tendsto (fun x : M × M ↦ x.1 * x.2) ((𝓝 0).coprod (𝓝 0) ⊓ l) (𝓝 0) := by have := calc (𝓝 0).coprod (𝓝 0) ⊓ l _ ≤ (𝓝 0).coprod (𝓝 0) ⊓ map Prod.fst l ×ˢ map Prod.snd l := inf_le_inf_left _ le_prod_map_fst_snd _ ≤ 𝓝 0 ×ˢ map Prod.snd l ⊔ map Prod.fst l ×ˢ 𝓝 0 := coprod_inf_prod_le _ _ _ _ apply (Tendsto.sup _ _).mono_left this · apply tendsto_mul_nhds_zero_prod_of_disjoint_cocompact exact disjoint_map_cocompact continuous_snd hl · apply tendsto_mul_prod_nhds_zero_of_disjoint_cocompact exact disjoint_map_cocompact continuous_fst hl /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M × M` which is both disjoint from the cocompact filter and less than or equal to `(𝓝 0).coprod (𝓝 0)`. Then the multiplication map `M × M → M` tends to zero on `l`. -/ theorem tendsto_mul_nhds_zero_of_disjoint_cocompact {l : Filter (M × M)} (hl : Disjoint l (cocompact (M × M))) (h'l : l ≤ (𝓝 0).coprod (𝓝 0)) : Tendsto (fun x : M × M ↦ x.1 * x.2) l (𝓝 0) := by simpa [inf_eq_right.mpr h'l] using tendsto_mul_coprod_nhds_zero_inf_of_disjoint_cocompact hl /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `f : α → M` and `g : α → M` be functions. If `f` tends to zero on a filter `l` and the image of `l` under `g` is disjoint from the cocompact filter on `M`, then `fun x : α ↦ f x * g x` also tends to zero on `l`. -/ theorem Tendsto.tendsto_mul_zero_of_disjoint_cocompact_right {f g : α → M} {l : Filter α} (hf : Tendsto f l (𝓝 0)) (hg : Disjoint (map g l) (cocompact M)) : Tendsto (fun x ↦ f x * g x) l (𝓝 0) := tendsto_mul_nhds_zero_prod_of_disjoint_cocompact hg |>.comp (hf.prodMk tendsto_map) /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `f : α → M` and `g : α → M` be functions. If `g` tends to zero on a filter `l` and the image of `l` under `f` is disjoint from the cocompact filter on `M`, then `fun x : α ↦ f x * g x` also tends to zero on `l`. -/ theorem Tendsto.tendsto_mul_zero_of_disjoint_cocompact_left {f g : α → M} {l : Filter α} (hf : Disjoint (map f l) (cocompact M)) (hg : Tendsto g l (𝓝 0)) : Tendsto (fun x ↦ f x * g x) l (𝓝 0) := tendsto_mul_prod_nhds_zero_of_disjoint_cocompact hf |>.comp (tendsto_map.prodMk hg) /-- If `f : α → M` and `g : β → M` are continuous and both tend to zero on the cocompact filter, then `fun i : α × β ↦ f i.1 * g i.2` also tends to zero on the cocompact filter. -/ theorem tendsto_mul_cocompact_nhds_zero [TopologicalSpace α] [TopologicalSpace β] {f : α → M} {g : β → M} (f_cont : Continuous f) (g_cont : Continuous g) (hf : Tendsto f (cocompact α) (𝓝 0)) (hg : Tendsto g (cocompact β) (𝓝 0)) : Tendsto (fun i : α × β ↦ f i.1 * g i.2) (cocompact (α × β)) (𝓝 0) := by set l : Filter (M × M) := map (Prod.map f g) (cocompact (α × β)) with l_def set K : Set (M × M) := (insert 0 (range f)) ×ˢ (insert 0 (range g)) have K_compact : IsCompact K := .prod (hf.isCompact_insert_range_of_cocompact f_cont) (hg.isCompact_insert_range_of_cocompact g_cont) have K_mem_l : K ∈ l := eventually_map.mpr <| .of_forall fun ⟨x, y⟩ ↦ ⟨mem_insert_of_mem _ (mem_range_self _), mem_insert_of_mem _ (mem_range_self _)⟩ have l_compact : Disjoint l (cocompact (M × M)) := by rw [disjoint_cocompact_right] exact ⟨K, K_mem_l, K_compact⟩ have l_le_coprod : l ≤ (𝓝 0).coprod (𝓝 0) := by rw [l_def, ← coprod_cocompact] exact hf.prodMap_coprod hg exact tendsto_mul_nhds_zero_of_disjoint_cocompact l_compact l_le_coprod |>.comp tendsto_map /-- If `f : α → M` and `g : β → M` both tend to zero on the cofinite filter, then so does `fun i : α × β ↦ f i.1 * g i.2`. -/ theorem tendsto_mul_cofinite_nhds_zero {f : α → M} {g : β → M} (hf : Tendsto f cofinite (𝓝 0)) (hg : Tendsto g cofinite (𝓝 0)) : Tendsto (fun i : α × β ↦ f i.1 * g i.2) cofinite (𝓝 0) := by letI : TopologicalSpace α := ⊥ haveI : DiscreteTopology α := discreteTopology_bot α letI : TopologicalSpace β := ⊥ haveI : DiscreteTopology β := discreteTopology_bot β rw [← cocompact_eq_cofinite] at * exact tendsto_mul_cocompact_nhds_zero continuous_of_discreteTopology continuous_of_discreteTopology hf hg end MulZeroClass section GroupWithZero lemma GroupWithZero.isOpen_singleton_zero [GroupWithZero M] [TopologicalSpace M] [ContinuousMul M] [CompactSpace M] [T1Space M] : IsOpen {(0 : M)} := by obtain ⟨U, hU, h0U, h1U⟩ := t1Space_iff_exists_open.mp ‹_› zero_ne_one obtain ⟨W, hW, hW'⟩ := exists_mem_nhds_zero_mul_subset isCompact_univ (hU.mem_nhds h0U) by_cases H : ∃ x ≠ 0, x ∈ W · obtain ⟨x, hx, hxW⟩ := H cases h1U (hW' (by simpa [hx] using Set.mul_mem_mul (Set.mem_univ x⁻¹) hxW)) · obtain rfl : W = {0} := subset_antisymm (by simpa [not_imp_not] using H) (by simpa using mem_of_mem_nhds hW) simpa [isOpen_iff_mem_nhds] end GroupWithZero section MulOneClass variable [TopologicalSpace M] [MulOneClass M] [ContinuousMul M] @[to_additive exists_open_nhds_zero_half] theorem exists_open_nhds_one_split {s : Set M} (hs : s ∈ 𝓝 (1 : M)) : ∃ V : Set M, IsOpen V ∧ (1 : M) ∈ V ∧ ∀ v ∈ V, ∀ w ∈ V, v * w ∈ s := by have : (fun a : M × M => a.1 * a.2) ⁻¹' s ∈ 𝓝 ((1, 1) : M × M) := tendsto_mul (by simpa only [one_mul] using hs) simpa only [prod_subset_iff] using exists_nhds_square this @[to_additive exists_nhds_zero_half] theorem exists_nhds_one_split {s : Set M} (hs : s ∈ 𝓝 (1 : M)) : ∃ V ∈ 𝓝 (1 : M), ∀ v ∈ V, ∀ w ∈ V, v * w ∈ s := let ⟨V, Vo, V1, hV⟩ := exists_open_nhds_one_split hs ⟨V, IsOpen.mem_nhds Vo V1, hV⟩ /-- Given a neighborhood `U` of `1` there is an open neighborhood `V` of `1` such that `V * V ⊆ U`. -/ @[to_additive /-- Given an open neighborhood `U` of `0` there is an open neighborhood `V` of `0` such that `V + V ⊆ U`. -/] theorem exists_open_nhds_one_mul_subset {U : Set M} (hU : U ∈ 𝓝 (1 : M)) : ∃ V : Set M, IsOpen V ∧ (1 : M) ∈ V ∧ V * V ⊆ U := by simpa only [mul_subset_iff] using exists_open_nhds_one_split hU @[to_additive] theorem Filter.HasBasis.mul_self {p : ι → Prop} {s : ι → Set M} (h : (𝓝 1).HasBasis p s) : (𝓝 1).HasBasis p fun i => s i * s i := by rw [← nhds_mul_nhds_one, ← map₂_mul, ← map_uncurry_prod] simpa only [← image_mul_prod] using h.prod_self.map _ end MulOneClass section ContinuousMul section Semigroup variable [TopologicalSpace M] [Semigroup M] [ContinuousMul M] @[to_additive] theorem Subsemigroup.top_closure_mul_self_subset (s : Subsemigroup M) : _root_.closure (s : Set M) * _root_.closure s ⊆ _root_.closure s := image2_subset_iff.2 fun _ hx _ hy => map_mem_closure₂ continuous_mul hx hy fun _ ha _ hb => s.mul_mem ha hb /-- The (topological-space) closure of a subsemigroup of a space `M` with `ContinuousMul` is itself a subsemigroup. -/ @[to_additive /-- The (topological-space) closure of an additive submonoid of a space `M` with `ContinuousAdd` is itself an additive submonoid. -/] def Subsemigroup.topologicalClosure (s : Subsemigroup M) : Subsemigroup M where carrier := _root_.closure (s : Set M) mul_mem' ha hb := s.top_closure_mul_self_subset ⟨_, ha, _, hb, rfl⟩ @[to_additive] theorem Subsemigroup.coe_topologicalClosure (s : Subsemigroup M) : (s.topologicalClosure : Set M) = _root_.closure (s : Set M) := rfl @[to_additive] theorem Subsemigroup.le_topologicalClosure (s : Subsemigroup M) : s ≤ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Subsemigroup.isClosed_topologicalClosure (s : Subsemigroup M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure @[to_additive] theorem Subsemigroup.topologicalClosure_minimal (s : Subsemigroup M) {t : Subsemigroup M} (h : s ≤ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≤ t := closure_minimal h ht /-- If a subsemigroup of a topological semigroup is commutative, then so is its topological closure. See note [reducible non-instances] -/ @[to_additive /-- If a submonoid of an additive topological monoid is commutative, then so is its topological closure. See note [reducible non-instances] -/] abbrev Subsemigroup.commSemigroupTopologicalClosure [T2Space M] (s : Subsemigroup M) (hs : ∀ x y : s, x * y = y * x) : CommSemigroup s.topologicalClosure := { MulMemClass.toSemigroup s.topologicalClosure with mul_comm := have : ∀ x ∈ s, ∀ y ∈ s, x * y = y * x := fun x hx y hy => congr_arg Subtype.val (hs ⟨x, hx⟩ ⟨y, hy⟩) fun ⟨x, hx⟩ ⟨y, hy⟩ => Subtype.ext <| eqOn_closure₂ this continuous_mul (continuous_snd.mul continuous_fst) x hx y hy } @[to_additive] theorem IsCompact.mul {s t : Set M} (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s * t) := by rw [← image_mul_prod] exact (hs.prod ht).image continuous_mul end Semigroup variable [TopologicalSpace M] [Monoid M] [ContinuousMul M] @[to_additive] theorem Submonoid.top_closure_mul_self_subset (s : Submonoid M) : _root_.closure (s : Set M) * _root_.closure s ⊆ _root_.closure s := image2_subset_iff.2 fun _ hx _ hy => map_mem_closure₂ continuous_mul hx hy fun _ ha _ hb => s.mul_mem ha hb @[to_additive] theorem Submonoid.top_closure_mul_self_eq (s : Submonoid M) : _root_.closure (s : Set M) * _root_.closure s = _root_.closure s := Subset.antisymm s.top_closure_mul_self_subset fun x hx => ⟨x, hx, 1, _root_.subset_closure s.one_mem, mul_one _⟩ /-- The (topological-space) closure of a submonoid of a space `M` with `ContinuousMul` is itself a submonoid. -/ @[to_additive /-- The (topological-space) closure of an additive submonoid of a space `M` with `ContinuousAdd` is itself an additive submonoid. -/] def Submonoid.topologicalClosure (s : Submonoid M) : Submonoid M where carrier := _root_.closure (s : Set M) one_mem' := _root_.subset_closure s.one_mem mul_mem' ha hb := s.top_closure_mul_self_subset ⟨_, ha, _, hb, rfl⟩ @[to_additive] theorem Submonoid.coe_topologicalClosure (s : Submonoid M) : (s.topologicalClosure : Set M) = _root_.closure (s : Set M) := rfl @[to_additive] theorem Submonoid.le_topologicalClosure (s : Submonoid M) : s ≤ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Submonoid.isClosed_topologicalClosure (s : Submonoid M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure @[to_additive] theorem Submonoid.topologicalClosure_minimal (s : Submonoid M) {t : Submonoid M} (h : s ≤ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≤ t := closure_minimal h ht /-- If a submonoid of a topological monoid is commutative, then so is its topological closure. -/ @[to_additive /-- If a submonoid of an additive topological monoid is commutative, then so is its topological closure. See note [reducible non-instances]. -/] abbrev Submonoid.commMonoidTopologicalClosure [T2Space M] (s : Submonoid M) (hs : ∀ x y : s, x * y = y * x) : CommMonoid s.topologicalClosure := { s.topologicalClosure.toMonoid, s.toSubsemigroup.commSemigroupTopologicalClosure hs with } @[to_additive exists_nhds_zero_quarter] theorem exists_nhds_one_split4 {u : Set M} (hu : u ∈ 𝓝 (1 : M)) : ∃ V ∈ 𝓝 (1 : M), ∀ {v w s t}, v ∈ V → w ∈ V → s ∈ V → t ∈ V → v * w * s * t ∈ u := by rcases exists_nhds_one_split hu with ⟨W, W1, h⟩ rcases exists_nhds_one_split W1 with ⟨V, V1, h'⟩ use V, V1 intro v w s t v_in w_in s_in t_in simpa only [mul_assoc] using h _ (h' v v_in w w_in) _ (h' s s_in t t_in) @[to_additive] theorem tendsto_list_prod {f : ι → α → M} {x : Filter α} {a : ι → M} : ∀ l : List ι, (∀ i ∈ l, Tendsto (f i) x (𝓝 (a i))) → Tendsto (fun b => (l.map fun c => f c b).prod) x (𝓝 (l.map a).prod) | [], _ => by simp [tendsto_const_nhds] | f::l, h => by simp only [List.map_cons, List.prod_cons] exact (h f List.mem_cons_self).mul (tendsto_list_prod l fun c hc => h c (List.mem_cons_of_mem _ hc)) @[to_additive (attr := continuity)] theorem continuous_list_prod {f : ι → X → M} (l : List ι) (h : ∀ i ∈ l, Continuous (f i)) : Continuous fun a => (l.map fun i => f i a).prod := continuous_iff_continuousAt.2 fun x => tendsto_list_prod l fun c hc => continuous_iff_continuousAt.1 (h c hc) x @[to_additive] theorem continuousOn_list_prod {f : ι → X → M} (l : List ι) {t : Set X} (h : ∀ i ∈ l, ContinuousOn (f i) t) : ContinuousOn (fun a => (l.map fun i => f i a).prod) t := by intro x hx rw [continuousWithinAt_iff_continuousAt_restrict _ hx] refine tendsto_list_prod _ fun i hi => ?_ specialize h i hi x hx rw [continuousWithinAt_iff_continuousAt_restrict _ hx] at h exact h @[to_additive (attr := continuity)] theorem continuous_pow : ∀ n : ℕ, Continuous fun a : M => a ^ n | 0 => by simpa using continuous_const | k + 1 => by simp only [pow_succ'] exact continuous_id.mul (continuous_pow _) instance AddMonoid.continuousConstSMul_nat {A} [AddMonoid A] [TopologicalSpace A] [ContinuousAdd A] : ContinuousConstSMul ℕ A := ⟨continuous_nsmul⟩ instance AddMonoid.continuousSMul_nat {A} [AddMonoid A] [TopologicalSpace A] [ContinuousAdd A] : ContinuousSMul ℕ A := ⟨continuous_prod_of_discrete_left.mpr continuous_nsmul⟩ -- We register `Continuous.pow` as a `continuity` lemma with low penalty (so -- `continuity` will try it before other `continuity` lemmas). This is a -- workaround for goals of the form `Continuous fun x => x ^ 2`, where -- `continuity` applies `Continuous.mul` since the goal is defeq to -- `Continuous fun x => x * x`. -- -- To properly fix this, we should make sure that `continuity` applies its -- lemmas with reducible transparency, preventing the unfolding of `^`. But this -- is quite an invasive change. @[to_additive (attr := aesop safe -100 (rule_sets := [Continuous]), fun_prop)] theorem Continuous.pow {f : X → M} (h : Continuous f) (n : ℕ) : Continuous fun b => f b ^ n := (continuous_pow n).comp h @[to_additive] theorem continuousOn_pow {s : Set M} (n : ℕ) : ContinuousOn (fun (x : M) => x ^ n) s := (continuous_pow n).continuousOn @[to_additive] theorem continuousAt_pow (x : M) (n : ℕ) : ContinuousAt (fun (x : M) => x ^ n) x := (continuous_pow n).continuousAt @[to_additive] theorem Filter.Tendsto.pow {l : Filter α} {f : α → M} {x : M} (hf : Tendsto f l (𝓝 x)) (n : ℕ) : Tendsto (fun x => f x ^ n) l (𝓝 (x ^ n)) := (continuousAt_pow _ _).tendsto.comp hf @[to_additive] theorem ContinuousWithinAt.pow {f : X → M} {x : X} {s : Set X} (hf : ContinuousWithinAt f s x) (n : ℕ) : ContinuousWithinAt (fun x => f x ^ n) s x := Filter.Tendsto.pow hf n @[to_additive (attr := fun_prop)] theorem ContinuousAt.pow {f : X → M} {x : X} (hf : ContinuousAt f x) (n : ℕ) : ContinuousAt (fun x => f x ^ n) x := Filter.Tendsto.pow hf n @[to_additive (attr := fun_prop)] theorem ContinuousOn.pow {f : X → M} {s : Set X} (hf : ContinuousOn f s) (n : ℕ) : ContinuousOn (fun x => f x ^ n) s := fun x hx => (hf x hx).pow n /-- Left-multiplication by a left-invertible element of a topological monoid is proper, i.e., inverse images of compact sets are compact. -/ theorem Filter.tendsto_cocompact_mul_left {a b : M} (ha : b * a = 1) : Filter.Tendsto (fun x : M => a * x) (Filter.cocompact M) (Filter.cocompact M) := by refine Filter.Tendsto.of_tendsto_comp ?_ (Filter.comap_cocompact_le (continuous_mul_left b)) convert Filter.tendsto_id ext x simp [← mul_assoc, ha] /-- Right-multiplication by a right-invertible element of a topological monoid is proper, i.e., inverse images of compact sets are compact. -/ theorem Filter.tendsto_cocompact_mul_right {a b : M} (ha : a * b = 1) : Filter.Tendsto (fun x : M => x * a) (Filter.cocompact M) (Filter.cocompact M) := by refine Filter.Tendsto.of_tendsto_comp ?_ (Filter.comap_cocompact_le (continuous_mul_right b)) simp only [comp_mul_right, ha, mul_one] exact Filter.tendsto_id /-- If `R` acts on `A` via `A`, then continuous multiplication implies continuous scalar multiplication by constants. Notably, this instances applies when `R = A`, or when `[Algebra R A]` is available. -/ @[to_additive /-- If `R` acts on `A` via `A`, then continuous addition implies continuous affine addition by constants. -/] instance (priority := 100) IsScalarTower.continuousConstSMul {R A : Type*} [Monoid A] [SMul R A] [IsScalarTower R A A] [TopologicalSpace A] [ContinuousMul A] : ContinuousConstSMul R A where continuous_const_smul q := by simp +singlePass only [← smul_one_mul q (_ : A)] exact continuous_const.mul continuous_id /-- If the action of `R` on `A` commutes with left-multiplication, then continuous multiplication implies continuous scalar multiplication by constants. Notably, this instances applies when `R = Aᵐᵒᵖ`. -/ @[to_additive /-- If the action of `R` on `A` commutes with left-addition, then continuous addition implies continuous affine addition by constants. Notably, this instances applies when `R = Aᵃᵒᵖ`. -/] instance (priority := 100) SMulCommClass.continuousConstSMul {R A : Type*} [Monoid A] [SMul R A] [SMulCommClass R A A] [TopologicalSpace A] [ContinuousMul A] : ContinuousConstSMul R A where continuous_const_smul q := by simp +singlePass only [← mul_smul_one q (_ : A)] exact continuous_id.mul continuous_const end ContinuousMul namespace MulOpposite /-- If multiplication is continuous in `α`, then it also is in `αᵐᵒᵖ`. -/ @[to_additive /-- If addition is continuous in `α`, then it also is in `αᵃᵒᵖ`. -/] instance [TopologicalSpace α] [Mul α] [ContinuousMul α] : ContinuousMul αᵐᵒᵖ := ⟨continuous_op.comp (continuous_unop.snd'.mul continuous_unop.fst')⟩ end MulOpposite namespace Units open MulOpposite variable [TopologicalSpace α] [Monoid α] [ContinuousMul α] /-- If multiplication on a monoid is continuous, then multiplication on the units of the monoid, with respect to the induced topology, is continuous. Inversion is also continuous, but we register this in a later file, `Topology.Algebra.Group`, because the predicate `ContinuousInv` has not yet been defined. -/ @[to_additive /-- If addition on an additive monoid is continuous, then addition on the additive units of the monoid, with respect to the induced topology, is continuous. Negation is also continuous, but we register this in a later file, `Topology.Algebra.Group`, because the predicate `ContinuousNeg` has not yet been defined. -/] instance : ContinuousMul αˣ := isInducing_embedProduct.continuousMul (embedProduct α) end Units @[to_additive (attr := fun_prop)] theorem Continuous.units_map [Monoid M] [Monoid N] [TopologicalSpace M] [TopologicalSpace N] (f : M →* N) (hf : Continuous f) : Continuous (Units.map f) := Units.continuous_iff.2 ⟨hf.comp Units.continuous_val, hf.comp Units.continuous_coe_inv⟩ section variable [TopologicalSpace M] [CommMonoid M] @[to_additive] theorem Submonoid.mem_nhds_one (S : Submonoid M) (oS : IsOpen (S : Set M)) : (S : Set M) ∈ 𝓝 (1 : M) := IsOpen.mem_nhds oS S.one_mem variable [ContinuousMul M] @[to_additive] theorem tendsto_multiset_prod {f : ι → α → M} {x : Filter α} {a : ι → M} (s : Multiset ι) : (∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) → Tendsto (fun b => (s.map fun c => f c b).prod) x (𝓝 (s.map a).prod) := by rcases s with ⟨l⟩ simpa using tendsto_list_prod l @[to_additive] theorem tendsto_finset_prod {f : ι → α → M} {x : Filter α} {a : ι → M} (s : Finset ι) : (∀ i ∈ s, Tendsto (f i) x (𝓝 (a i))) → Tendsto (fun b => ∏ c ∈ s, f c b) x (𝓝 (∏ c ∈ s, a c)) := tendsto_multiset_prod _ @[to_additive (attr := continuity)] theorem continuous_multiset_prod {f : ι → X → M} (s : Multiset ι) : (∀ i ∈ s, Continuous (f i)) → Continuous fun a => (s.map fun i => f i a).prod := by rcases s with ⟨l⟩ simpa using continuous_list_prod l @[to_additive] theorem continuousOn_multiset_prod {f : ι → X → M} (s : Multiset ι) {t : Set X} : (∀ i ∈ s, ContinuousOn (f i) t) → ContinuousOn (fun a => (s.map fun i => f i a).prod) t := by rcases s with ⟨l⟩ simpa using continuousOn_list_prod l @[to_additive (attr := continuity, fun_prop)] theorem continuous_finset_prod {f : ι → X → M} (s : Finset ι) : (∀ i ∈ s, Continuous (f i)) → Continuous fun a => ∏ i ∈ s, f i a := continuous_multiset_prod _ @[to_additive] theorem continuousOn_finset_prod {f : ι → X → M} (s : Finset ι) {t : Set X} : (∀ i ∈ s, ContinuousOn (f i) t) → ContinuousOn (fun a => ∏ i ∈ s, f i a) t := continuousOn_multiset_prod _ @[to_additive] theorem eventuallyEq_prod {X M : Type*} [CommMonoid M] {s : Finset ι} {l : Filter X} {f g : ι → X → M} (hs : ∀ i ∈ s, f i =ᶠ[l] g i) : ∏ i ∈ s, f i =ᶠ[l] ∏ i ∈ s, g i := by replace hs : ∀ᶠ x in l, ∀ i ∈ s, f i x = g i x := by rwa [eventually_all_finset] filter_upwards [hs] with x hx simp only [Finset.prod_apply, Finset.prod_congr rfl hx] open Function @[to_additive] theorem LocallyFinite.exists_finset_mulSupport {M : Type*} [One M] {f : ι → X → M} (hf : LocallyFinite fun i => mulSupport <| f i) (x₀ : X) : ∃ I : Finset ι, ∀ᶠ x in 𝓝 x₀, (mulSupport fun i => f i x) ⊆ I := by rcases hf x₀ with ⟨U, hxU, hUf⟩ refine ⟨hUf.toFinset, mem_of_superset hxU fun y hy i hi => ?_⟩ rw [hUf.coe_toFinset] exact ⟨y, hi, hy⟩ @[to_additive] theorem finprod_eventually_eq_prod {M : Type*} [CommMonoid M] {f : ι → X → M} (hf : LocallyFinite fun i => mulSupport (f i)) (x : X) : ∃ s : Finset ι, ∀ᶠ y in 𝓝 x, ∏ᶠ i, f i y = ∏ i ∈ s, f i y := let ⟨I, hI⟩ := hf.exists_finset_mulSupport x ⟨I, hI.mono fun _ hy => finprod_eq_prod_of_mulSupport_subset _ fun _ hi => hy hi⟩ @[to_additive] theorem continuous_finprod {f : ι → X → M} (hc : ∀ i, Continuous (f i)) (hf : LocallyFinite fun i => mulSupport (f i)) : Continuous fun x => ∏ᶠ i, f i x := by refine continuous_iff_continuousAt.2 fun x => ?_ rcases finprod_eventually_eq_prod hf x with ⟨s, hs⟩ refine ContinuousAt.congr ?_ (EventuallyEq.symm hs) exact tendsto_finset_prod _ fun i _ => (hc i).continuousAt @[to_additive] theorem continuous_finprod_cond {f : ι → X → M} {p : ι → Prop} (hc : ∀ i, p i → Continuous (f i)) (hf : LocallyFinite fun i => mulSupport (f i)) : Continuous fun x => ∏ᶠ (i) (_ : p i), f i x := by simp only [← finprod_subtype_eq_finprod_cond] exact continuous_finprod (fun i => hc i i.2) (hf.comp_injective Subtype.coe_injective) end instance [TopologicalSpace M] [Mul M] [ContinuousMul M] : ContinuousAdd (Additive M) where continuous_add := @continuous_mul M _ _ _ instance [TopologicalSpace M] [Add M] [ContinuousAdd M] : ContinuousMul (Multiplicative M) where continuous_mul := @continuous_add M _ _ _ section LatticeOps variable {ι' : Sort*} [Mul M] @[to_additive] theorem continuousMul_sInf {ts : Set (TopologicalSpace M)} (h : ∀ t ∈ ts, @ContinuousMul M t _) : @ContinuousMul M (sInf ts) _ := letI := sInf ts { continuous_mul := continuous_sInf_rng.2 fun t ht => continuous_sInf_dom₂ ht ht (@ContinuousMul.continuous_mul M t _ (h t ht)) } @[to_additive] theorem continuousMul_iInf {ts : ι' → TopologicalSpace M} (h' : ∀ i, @ContinuousMul M (ts i) _) : @ContinuousMul M (⨅ i, ts i) _ := by rw [← sInf_range] exact continuousMul_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem continuousMul_inf {t₁ t₂ : TopologicalSpace M} (h₁ : @ContinuousMul M t₁ _) (h₂ : @ContinuousMul M t₂ _) : @ContinuousMul M (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine continuousMul_iInf fun b => ?_ cases b <;> assumption end LatticeOps namespace ContinuousMap variable [Mul X] [ContinuousMul X] /-- The continuous map `fun y => y * x` -/ @[to_additive /-- The continuous map `fun y => y + x` -/] protected def mulRight (x : X) : C(X, X) := mk _ (continuous_mul_right x) @[to_additive (attr := simp)] theorem coe_mulRight (x : X) : ⇑(ContinuousMap.mulRight x) = fun y => y * x := rfl /-- The continuous map `fun y => x * y` -/ @[to_additive /-- The continuous map `fun y => x + y` -/] protected def mulLeft (x : X) : C(X, X) := mk _ (continuous_mul_left x) @[to_additive (attr := simp)] theorem coe_mulLeft (x : X) : ⇑(ContinuousMap.mulLeft x) = fun y => x * y := rfl end ContinuousMap
Basic.lean
import Mathlib.Tactic.CategoryTheory.Monoidal.Basic open CategoryTheory Mathlib.Tactic BicategoryLike open MonoidalCategory universe v u variable {C : Type u} [Category.{v} C] [MonoidalCategory C] variable {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) example (f : U ⟶ V ⊗ (W ⊗ X)) (g : (V ⊗ W) ⊗ X ⟶ Y) : f ⊗≫ g = f ≫ (α_ _ _ _).inv ≫ g := by monoidal example (f : Z ⟶ W) : (X ⊗ Y) ◁ f = (α_ _ _ _).hom ≫ X ◁ Y ◁ f ≫ (α_ _ _ _).inv := by monoidal example : f ≫ g = f ≫ g := by monoidal example : (f ⊗ₘ g) ▷ X = (α_ _ _ _).hom ≫ (f ⊗ₘ g ▷ X) ≫ (α_ _ _ _).inv := by monoidal example {V₁ V₂ V₃ : C} (R : ∀ V₁ V₂ : C, V₁ ⊗ V₂ ⟶ V₂ ⊗ V₁) : R V₁ V₂ ▷ V₃ ⊗≫ V₂ ◁ R V₁ V₃ = R V₁ V₂ ▷ V₃ ≫ (α_ _ _ _).hom ⊗≫ 𝟙 _ ≫ V₂ ◁ R V₁ V₃ := by monoidal
FinCoercions.lean
-- We verify that after importing Mathlib, -- we have not introduced a global coercion from `Nat` to `Fin n`. -- Such coercions introduce unexpected invisible wrap-around arithmetic. -- `open Fin.CommRing ...` *does* introduce such a coercion. import Mathlib set_option pp.mvars false -- We first verify that there is no global coercion from `Nat` to `Fin n`. -- Such a coercion would frequently introduce unexpected modular arithmetic. /-- error: Type mismatch n has type ℕ but is expected to have type Fin 3 --- info: fun n => sorry : (n : ℕ) → ?_ n -/ #guard_msgs in #check fun (n : Nat) => (n : Fin 3) -- This coercion is available via `open Fin.CommRing in ...` section open Fin.CommRing variable (m : Nat) (n : Fin 3) /-- info: n < ↑m : Prop -/ #guard_msgs in #check n < m end example (x : Fin (n + 1)) (h : x < n) : Fin (n + 1) := x.succ.castLT (by simp [h])
Isometries.lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.QuadraticForm.TensorProduct import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv /-! # Linear equivalences of tensor products as isometries These results are separate from the definition of `QuadraticForm.tmul` as that file is very slow. ## Main definitions * `QuadraticForm.Isometry.tmul`: `TensorProduct.map` as a `QuadraticForm.Isometry` * `QuadraticForm.tensorComm`: `TensorProduct.comm` as a `QuadraticForm.IsometryEquiv` * `QuadraticForm.tensorAssoc`: `TensorProduct.assoc` as a `QuadraticForm.IsometryEquiv` * `QuadraticForm.tensorRId`: `TensorProduct.rid` as a `QuadraticForm.IsometryEquiv` * `QuadraticForm.tensorLId`: `TensorProduct.lid` as a `QuadraticForm.IsometryEquiv` -/ universe uR uM₁ uM₂ uM₃ uM₄ variable {R : Type uR} {M₁ : Type uM₁} {M₂ : Type uM₂} {M₃ : Type uM₃} {M₄ : Type uM₄} open scoped TensorProduct open QuadraticMap namespace QuadraticForm variable [CommRing R] variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃] [AddCommGroup M₄] variable [Module R M₁] [Module R M₂] [Module R M₃] [Module R M₄] [Invertible (2 : R)] @[simp] theorem tmul_comp_tensorMap {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) : (Q₂.tmul Q₄).comp (TensorProduct.map f.toLinearMap g.toLinearMap) = Q₁.tmul Q₃ := by have h₁ : Q₁ = Q₂.comp f.toLinearMap := QuadraticMap.ext fun x => (f.map_app x).symm have h₃ : Q₃ = Q₄.comp g.toLinearMap := QuadraticMap.ext fun x => (g.map_app x).symm refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₃ m₁' m₃' simp [-associated_apply, h₁, h₃, associated_tmul] @[simp] theorem tmul_tensorMap_apply {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) (x : M₁ ⊗[R] M₃) : Q₂.tmul Q₄ (TensorProduct.map f.toLinearMap g.toLinearMap x) = Q₁.tmul Q₃ x := DFunLike.congr_fun (tmul_comp_tensorMap f g) x namespace Isometry /-- `TensorProduct.map` for `QuadraticForm.Isometry`s -/ def _root_.QuadraticMap.Isometry.tmul {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) : (Q₁.tmul Q₃) →qᵢ (Q₂.tmul Q₄) where toLinearMap := TensorProduct.map f.toLinearMap g.toLinearMap map_app' := tmul_tensorMap_apply f g @[simp] theorem _root_.QuadraticMap.Isometry.tmul_apply {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} {Q₄ : QuadraticForm R M₄} (f : Q₁ →qᵢ Q₂) (g : Q₃ →qᵢ Q₄) (x : M₁ ⊗[R] M₃) : f.tmul g x = TensorProduct.map f.toLinearMap g.toLinearMap x := rfl end Isometry section tensorComm @[simp] theorem tmul_comp_tensorComm (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) : (Q₂.tmul Q₁).comp (TensorProduct.comm R M₁ M₂) = Q₁.tmul Q₂ := by refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₂ m₁' m₂' dsimp [-associated_apply] simp only [associated_tmul, QuadraticMap.associated_comp] exact mul_comm _ _ @[simp] theorem tmul_tensorComm_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (x : M₁ ⊗[R] M₂) : Q₂.tmul Q₁ (TensorProduct.comm R M₁ M₂ x) = Q₁.tmul Q₂ x := DFunLike.congr_fun (tmul_comp_tensorComm Q₁ Q₂) x /-- `TensorProduct.comm` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorComm (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) : (Q₁.tmul Q₂).IsometryEquiv (Q₂.tmul Q₁) where toLinearEquiv := TensorProduct.comm R M₁ M₂ map_app' := tmul_tensorComm_apply Q₁ Q₂ @[simp] lemma tensorComm_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (x : M₁ ⊗[R] M₂) : tensorComm Q₁ Q₂ x = TensorProduct.comm R M₁ M₂ x := rfl @[simp] lemma tensorComm_symm (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) : (tensorComm Q₁ Q₂).symm = tensorComm Q₂ Q₁ := rfl end tensorComm section tensorAssoc @[simp] theorem tmul_comp_tensorAssoc (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) : (Q₁.tmul (Q₂.tmul Q₃)).comp (TensorProduct.assoc R M₁ M₂ M₃) = (Q₁.tmul Q₂).tmul Q₃ := by refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₂ m₁' m₂' m₁'' m₂'' dsimp [-associated_apply] simp only [associated_tmul, QuadraticMap.associated_comp] exact mul_assoc _ _ _ @[simp] theorem tmul_tensorAssoc_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) (x : (M₁ ⊗[R] M₂) ⊗[R] M₃) : Q₁.tmul (Q₂.tmul Q₃) (TensorProduct.assoc R M₁ M₂ M₃ x) = (Q₁.tmul Q₂).tmul Q₃ x := DFunLike.congr_fun (tmul_comp_tensorAssoc Q₁ Q₂ Q₃) x /-- `TensorProduct.assoc` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorAssoc (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) : ((Q₁.tmul Q₂).tmul Q₃).IsometryEquiv (Q₁.tmul (Q₂.tmul Q₃)) where toLinearEquiv := TensorProduct.assoc R M₁ M₂ M₃ map_app' := tmul_tensorAssoc_apply Q₁ Q₂ Q₃ @[simp] lemma tensorAssoc_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) (x : (M₁ ⊗[R] M₂) ⊗[R] M₃) : tensorAssoc Q₁ Q₂ Q₃ x = TensorProduct.assoc R M₁ M₂ M₃ x := rfl @[simp] lemma tensorAssoc_symm_apply (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Q₃ : QuadraticForm R M₃) (x : M₁ ⊗[R] (M₂ ⊗[R] M₃)) : (tensorAssoc Q₁ Q₂ Q₃).symm x = (TensorProduct.assoc R M₁ M₂ M₃).symm x := rfl end tensorAssoc section tensorRId theorem comp_tensorRId_eq (Q₁ : QuadraticForm R M₁) : Q₁.comp (TensorProduct.rid R M₁) = Q₁.tmul (sq (R := R)) := by refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₁ m₁' dsimp [-associated_apply] simp only [associated_tmul, QuadraticMap.associated_comp] simp [-associated_apply, one_mul] @[simp] theorem tmul_tensorRId_apply (Q₁ : QuadraticForm R M₁) (x : M₁ ⊗[R] R) : Q₁ (TensorProduct.rid R M₁ x) = Q₁.tmul (sq (R := R)) x := DFunLike.congr_fun (comp_tensorRId_eq Q₁) x /-- `TensorProduct.rid` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorRId (Q₁ : QuadraticForm R M₁) : (Q₁.tmul (sq (R := R))).IsometryEquiv Q₁ where toLinearEquiv := TensorProduct.rid R M₁ map_app' := tmul_tensorRId_apply Q₁ @[simp] lemma tensorRId_apply (Q₁ : QuadraticForm R M₁) (x : M₁ ⊗[R] R) : tensorRId Q₁ x = TensorProduct.rid R M₁ x := rfl @[simp] lemma tensorRId_symm_apply (Q₁ : QuadraticForm R M₁) (x : M₁) : (tensorRId Q₁).symm x = (TensorProduct.rid R M₁).symm x := rfl end tensorRId section tensorLId theorem comp_tensorLId_eq (Q₂ : QuadraticForm R M₂) : Q₂.comp (TensorProduct.lid R M₂) = QuadraticForm.tmul (sq (R := R)) Q₂ := by refine (QuadraticMap.associated_rightInverse R).injective ?_ ext m₂ m₂' dsimp [-associated_apply] simp only [associated_tmul, QuadraticMap.associated_comp] simp [-associated_apply, mul_one] @[simp] theorem tmul_tensorLId_apply (Q₂ : QuadraticForm R M₂) (x : R ⊗[R] M₂) : Q₂ (TensorProduct.lid R M₂ x) = QuadraticForm.tmul (sq (R := R)) Q₂ x := DFunLike.congr_fun (comp_tensorLId_eq Q₂) x /-- `TensorProduct.lid` preserves tensor products of quadratic forms. -/ @[simps toLinearEquiv] def tensorLId (Q₂ : QuadraticForm R M₂) : (QuadraticForm.tmul (sq (R := R)) Q₂).IsometryEquiv Q₂ where toLinearEquiv := TensorProduct.lid R M₂ map_app' := tmul_tensorLId_apply Q₂ @[simp] lemma tensorLId_apply (Q₂ : QuadraticForm R M₂) (x : R ⊗[R] M₂) : tensorLId Q₂ x = TensorProduct.lid R M₂ x := rfl @[simp] lemma tensorLId_symm_apply (Q₂ : QuadraticForm R M₂) (x : M₂) : (tensorLId Q₂).symm x = (TensorProduct.lid R M₂).symm x := rfl end tensorLId end QuadraticForm
Spaces.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Sites.Grothendieck import Mathlib.CategoryTheory.Sites.Pretopology import Mathlib.CategoryTheory.Limits.Lattice import Mathlib.Topology.Sets.Opens /-! # Grothendieck topology on a topological space Define the Grothendieck topology and the pretopology associated to a topological space, and show that the pretopology induces the topology. The covering (pre)sieves on `X` are those for which the union of domains contains `X`. ## Tags site, Grothendieck topology, space ## References * [nLab, *Grothendieck topology*](https://ncatlab.org/nlab/show/Grothendieck+topology) * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92] ## Implementation notes We define the two separately, rather than defining the Grothendieck topology as that generated by the pretopology for the purpose of having nice definitional properties for the sieves. -/ universe u namespace Opens variable (T : Type u) [TopologicalSpace T] open CategoryTheory TopologicalSpace CategoryTheory.Limits /-- The Grothendieck topology associated to a topological space. -/ def grothendieckTopology : GrothendieckTopology (Opens T) where sieves X S := ∀ x ∈ X, ∃ (U : _) (f : U ⟶ X), S f ∧ x ∈ U top_mem' _ _ hx := ⟨_, 𝟙 _, trivial, hx⟩ pullback_stable' X Y S f hf y hy := by rcases hf y (f.le hy) with ⟨U, g, hg, hU⟩ refine ⟨U ⊓ Y, homOfLE inf_le_right, ?_, hU, hy⟩ apply S.downward_closed hg (homOfLE inf_le_left) transitive' X S hS R hR x hx := by rcases hS x hx with ⟨U, f, hf, hU⟩ rcases hR hf _ hU with ⟨V, g, hg, hV⟩ exact ⟨_, g ≫ f, hg, hV⟩ /-- The Grothendieck pretopology associated to a topological space. -/ def pretopology : Pretopology (Opens T) where coverings X R := ∀ x ∈ X, ∃ (U : _) (f : U ⟶ X), R f ∧ x ∈ U has_isos _ _ f _ _ hx := ⟨_, _, Presieve.singleton_self _, (inv f).le hx⟩ pullbacks X Y f S hS x hx := by rcases hS _ (f.le hx) with ⟨U, g, hg, hU⟩ refine ⟨_, _, Presieve.pullbackArrows.mk _ _ hg, ?_⟩ have : U ⊓ Y ≤ pullback g f := leOfHom (pullback.lift (homOfLE inf_le_left) (homOfLE inf_le_right) rfl) apply this ⟨hU, hx⟩ transitive X S Ti hS hTi x hx := by rcases hS x hx with ⟨U, f, hf, hU⟩ rcases hTi f hf x hU with ⟨V, g, hg, hV⟩ exact ⟨_, _, ⟨_, g, f, hf, hg, rfl⟩, hV⟩ /-- The pretopology associated to a space is the largest pretopology that generates the Grothendieck topology associated to the space. -/ @[simp] theorem pretopology_ofGrothendieck : Pretopology.ofGrothendieck _ (Opens.grothendieckTopology T) = Opens.pretopology T := by apply le_antisymm · intro X R hR x hx rcases hR x hx with ⟨U, f, ⟨V, g₁, g₂, hg₂, _⟩, hU⟩ exact ⟨V, g₂, hg₂, g₁.le hU⟩ · intro X R hR x hx rcases hR x hx with ⟨U, f, hf, hU⟩ exact ⟨U, f, Sieve.le_generate R U hf, hU⟩ /-- The pretopology associated to a space induces the Grothendieck topology associated to the space. -/ @[simp] theorem pretopology_toGrothendieck : Pretopology.toGrothendieck _ (Opens.pretopology T) = Opens.grothendieckTopology T := by rw [← pretopology_ofGrothendieck] apply (Pretopology.gi (Opens T)).l_u_eq end Opens
Finsupp.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson -/ import Mathlib.Data.Finsupp.Multiset import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors /-! # Factors as finsupp ## Main definitions * `UniqueFactorizationMonoid.factorization`: the multiset of irreducible factors as a `Finsupp`. -/ variable {α : Type*} local infixl:50 " ~ᵤ " => Associated section Finsupp variable [CancelCommMonoidWithZero α] [UniqueFactorizationMonoid α] variable [NormalizationMonoid α] [DecidableEq α] open UniqueFactorizationMonoid /-- This returns the multiset of irreducible factors as a `Finsupp`. -/ noncomputable def factorization (n : α) : α →₀ ℕ := Multiset.toFinsupp (normalizedFactors n) theorem factorization_eq_count {n p : α} : factorization n p = Multiset.count p (normalizedFactors n) := by simp [factorization] @[simp] theorem factorization_zero : factorization (0 : α) = 0 := by simp [factorization] @[simp] theorem factorization_one : factorization (1 : α) = 0 := by simp [factorization] /-- The support of `factorization n` is exactly the Finset of normalized factors -/ @[simp] theorem support_factorization {n : α} : (factorization n).support = (normalizedFactors n).toFinset := by simp [factorization, Multiset.toFinsupp_support] /-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/ @[simp] theorem factorization_mul {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) : factorization (a * b) = factorization a + factorization b := by simp [factorization, normalizedFactors_mul ha hb] /-- For any `p`, the power of `p` in `x^n` is `n` times the power in `x` -/ theorem factorization_pow {x : α} {n : ℕ} : factorization (x ^ n) = n • factorization x := by ext simp [factorization] theorem associated_of_factorization_eq (a b : α) (ha : a ≠ 0) (hb : b ≠ 0) (h : factorization a = factorization b) : Associated a b := by simp_rw [factorization, AddEquiv.apply_eq_iff_eq] at h rwa [associated_iff_normalizedFactors_eq_normalizedFactors ha hb] end Finsupp
FindSyntax.lean
/- Copyright (c) 2024 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Lean.Elab.Command import Mathlib.Init /-! # The `#find_syntax` command The `#find_syntax` command takes as input a string `str` and retrieves from the environment all the candidates for `syntax` terms that contain the string `str`. It also makes a very crude effort at regenerating what the syntax looks like, by inspecting the `Expr`ession tree of the corresponding parser. -/ namespace Mathlib.FindSyntax open Lean Elab Command /-- `extractSymbols expr` takes as input an `Expr`ession `expr`, assuming that it is the `value` of a "parser". It returns the array of all subterms of `expr` that are the `Expr.lit` argument to `Lean.ParserDescr.symbol` and `Lean.ParserDescr.nonReservedSymbol` applications. The output array serves as a way of regenerating what the syntax tree of the input parser is. -/ def extractSymbols : Expr → Array Expr | .app a b => let rest := extractSymbols a ++ extractSymbols b match a.constName with | ``Lean.ParserDescr.symbol | ``Lean.ParserDescr.nonReservedSymbol => rest.push b | _ => rest | .letE _ a b c _ => extractSymbols a ++ extractSymbols b ++ extractSymbols c | .lam _ a b _ => extractSymbols a ++ extractSymbols b | .forallE _ a b _ => extractSymbols a ++ extractSymbols b | .mdata _ a => extractSymbols a | .proj _ _ a => extractSymbols a | _ => #[] /-- `litToString expr` converts the input `Expr`ession `expr` into the "natural" string that it corresponds to, in case `expr` is a `String`/`Nat`-literal, returning the empty string `""` otherwise. -/ def litToString : Expr → String | .lit (.natVal v) => s!"{v}" | .lit (.strVal v) => v | _ => "" /-- The `#find_syntax` command takes as input a string `str` and retrieves from the environment all the candidates for `syntax` terms that contain the string `str`. It also makes a very crude effort at regenerating what the syntax looks like: this is supposed to be just indicative of what the syntax may look like, but there is no guarantee or expectation of correctness. The optional trailing `approx`, as in `#find_syntax "∘" approx`, is only intended to make tests more stable: rather than outputting the exact count of the overall number of existing syntax declarations, it returns its round-down to the previous multiple of 100. -/ elab "#find_syntax " id:str d:(&" approx")? : command => do let prsr : Array Expr := #[.const ``ParserDescr [], .const ``TrailingParserDescr []] let mut symbs : Std.HashSet (Name × Array Expr) := {} -- We scan the environment in search of "parsers" whose name is not internal and that -- contain some `symbol` information and we store them in `symbs` for (declName, cinfo) in (← getEnv).constants do if prsr.contains cinfo.type && cinfo.hasValue then let ls := extractSymbols cinfo.value! if !declName.isInternal && !ls.isEmpty then symbs := symbs.insert (declName, ls) -- From among the parsers in `symbs`, we extract the ones whose `symbols` contain the input `str` let mut match_results : NameMap (Array (Name × String)) := {} for (nm, ar) in symbs.toList do let rem : String := " _ ".intercalate (ar.map litToString).toList -- If either the name of the parser or the regenerated syntax stub contains the input string, -- then we include an entry into the final message. if 2 ≤ (nm.toString.splitOn id.getString).length || 2 ≤ (rem.splitOn id.getString).length then let mod := (← findModuleOf? nm).getD (← getMainModule) match_results := match_results.insert mod <| (match_results.getD mod #[]).push (nm, rem.trim) -- We sort the messages to produce a more stable output. let sorted_results := match_results.toArray.qsort (·.1.lt ·.1) let sorted_results := sorted_results.map fun (mod, msgs) => (mod, msgs.qsort (·.1.lt ·.1)) let mods := (sorted_results.toList).map fun (mod, msgs) => m!"In `{mod}`:" ++ (MessageData.nest 2 <| m!"".joinSep <| msgs.toList.map fun (decl, patt) => m!"\n{MessageData.ofConstName decl}: '{patt}'") let uses := (sorted_results.toList.map fun (_, msgs) => msgs.size).sum let numSymbs := if d.isSome then s!"over {(symbs.size / 100) * 100}" else s!"{symbs.size}" let head := m!"Found {uses} use{if uses == 1 then "" else "s"} \ among {numSymbs} syntax declarations" logInfo <| head ++ m!"\n" ++ m!"\n\n".joinSep mods end Mathlib.FindSyntax
PUnit.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.PUnit import Mathlib.Algebra.Order.AddGroupWithTop /-! # Instances on PUnit This file collects facts about ordered algebraic structures on the one-element type. -/ namespace PUnit instance canonicallyOrderedAdd : CanonicallyOrderedAdd PUnit where exists_add_of_le {_ _} _ := ⟨unit, by subsingleton⟩ le_self_add _ _ := trivial instance isOrderedCancelAddMonoid : IsOrderedCancelAddMonoid PUnit where le_of_add_le_add_left _ _ _ _ := trivial add_le_add_left := by intros; rfl instance : LinearOrderedAddCommMonoidWithTop PUnit where top := () le_top _ := le_rfl top_add' _ := rfl end PUnit
rat.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import prime fintype finfun bigop order tuple ssralg. From mathcomp Require Import countalg div ssrnum ssrint archimedean poly zmodp. From mathcomp Require Import polydiv intdiv matrix mxalgebra vector. (******************************************************************************) (* This file defines a datatype for rational numbers and equips it with a *) (* structure of archimedean, real field, with int and nat declared as closed *) (* subrings. *) (* rat == the type of rational number, with single constructor Rat *) (* <number> == <number> as a rat with <number> a decimal constant. *) (* This notation is in rat_scope (delimited with %Q). *) (* n%:Q == explicit cast from int to rat, ie. the specialization to *) (* rationals of the generic ring morphism n%:~R *) (* numq r == numerator of (r : rat) *) (* denq r == denominator of (r : rat) *) (* ratr r == generic embedding of (r : rat) into an arbitrary unit ring.*) (* [rat x // y] == smart constructor for rationals, definitionally equal *) (* to x / y for concrete values, intended for printing only *) (* of normal forms. The parsable notation is for debugging. *) (* inIntSpan X v <-> v is an integral linear combination of elements of *) (* X : seq V, where V is a zmodType. We prove that this is a *) (* decidable property for Q-vector spaces. *) (******************************************************************************) Import Order.TTheory GRing.Theory Num.Theory. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "[ 'rat' x // y ]" (format "[ 'rat' x // y ]"). Reserved Notation "n %:Q" (left associativity, format "n %:Q"). Local Open Scope ring_scope. Local Notation sgr := Num.sg. Record rat : Set := Rat { valq : (int * int); _ : (0 < valq.2) && coprime `|valq.1| `|valq.2| }. Bind Scope ring_scope with rat. Delimit Scope rat_scope with Q. Definition ratz (n : int) := @Rat (n, 1) (coprimen1 _). (* Coercion ratz (n : int) := @Rat (n, 1) (coprimen1 _). *) Definition rat_isSub := Eval hnf in [isSub for valq]. HB.instance Definition _ := rat_isSub. #[hnf] HB.instance Definition _ := [Equality of rat by <:]. HB.instance Definition _ := [Countable of rat by <:]. Definition numq x := (valq x).1. Definition denq x := (valq x).2. Arguments numq : simpl never. Arguments denq : simpl never. Lemma denq_gt0 x : 0 < denq x. Proof. by rewrite /denq; case: x=> [[a b] /= /andP []]. Qed. #[global] Hint Resolve denq_gt0 : core. Definition denq_ge0 x := ltW (denq_gt0 x). Lemma denq_lt0 x : (denq x < 0) = false. Proof. by rewrite lt_gtF. Qed. Lemma denq_neq0 x : denq x != 0. Proof. by rewrite /denq gt_eqF ?denq_gt0. Qed. #[global] Hint Resolve denq_neq0 : core. Lemma denq_eq0 x : (denq x == 0) = false. Proof. exact: negPf (denq_neq0 _). Qed. Lemma coprime_num_den x : coprime `|numq x| `|denq x|. Proof. by rewrite /numq /denq; case: x=> [[a b] /= /andP []]. Qed. Fact RatK x P : @Rat (numq x, denq x) P = x. Proof. by move: x P => [[a b] P'] P; apply: val_inj. Qed. Definition fracq_subdef x := if x.2 != 0 then let g := gcdn `|x.1| `|x.2| in ((-1) ^ ((x.2 < 0) (+) (x.1 < 0)) * (`|x.1| %/ g)%:Z, (`|x.2| %/ g)%:Z) else (0, 1). Arguments fracq_subdef /. Definition fracq_opt_subdef (x : int * int) := if (0 < x.2) && coprime `|x.1| `|x.2| then x else fracq_subdef x. Lemma fracq_opt_subdefE x : fracq_opt_subdef x = fracq_subdef x. Proof. rewrite /fracq_opt_subdef; case: ifP => //; case: x => n d /= /andP[d_gt0 cnd]. rewrite /fracq_subdef gt_eqF//= lt_gtF//= (eqP cnd) !divn1 abszEsg gtz0_abs//. rewrite mulrA sgz_def mulrnAr -signr_addb addbb expr0. by have [->|] := eqVneq n 0; rewrite (mulr0, mul1r). Qed. Fact fracq_subproof x (y := fracq_opt_subdef x) : (0 < y.2) && (coprime `|y.1| `|y.2|). Proof. rewrite {}/y fracq_opt_subdefE /=; have [] //= := eqVneq x.2 0. case: x => [/= n d]; rewrite -absz_gt0 => dN0. have ggt0 : (0 < gcdn `|n| `|d|)%N by rewrite gcdn_gt0 dN0 orbT. rewrite ltz_nat divn_gt0// dvdn_leq ?dvdn_gcdr//=. rewrite abszM abszX abszN1 exp1n mul1n absz_nat. rewrite /coprime -(@eqn_pmul2r (gcdn `|n| `|d|))// mul1n. by rewrite muln_gcdl !divnK ?(dvdn_gcdl, dvdn_gcdr). Qed. Lemma fracq_opt_subdef_id x : fracq_opt_subdef (fracq_opt_subdef x) = fracq_subdef x. Proof. rewrite [fracq_opt_subdef (_ x)]/fracq_opt_subdef. by rewrite fracq_subproof fracq_opt_subdefE. Qed. (* We use a match expression in order to "lock" the definition of fracq. *) (* Indeed, the kernel will try to reduce a fracq only when applied to *) (* a term which has "enough" constructors: i.e. it reduces to a pair of *) (* a Posz or Negz on the first component, and a Posz of 0 or S, or a Negz *) (* on the second component. See issue #698. *) (* Additionally, we use fracq_opt_subdef to precompute the normal form *) (* before we use fracq_subproof in order to make sure the proof will be *) (* independent from the input of fracq. This ensure reflexivity of any *) (* computation involving rationals as long as all operators use fracq. *) (* As a consequence val (fracq x) = fracq_opt_subdef (fracq_opt_subdef x)) *) Definition fracq '((n', d')) : rat := match d', n' with | Posz 0 as d, _ as n => Rat (fracq_subproof (1, 0)) | _ as d, Posz _ as n | _ as d, _ as n => Rat (fracq_subproof (fracq_opt_subdef (n, d))) end. Arguments fracq : simpl never. (* Define a Number Notation for rat in rat_scope *) (* Since rat values obtained from fracq contain fracq_subdef, which is not *) (* an inductive constructor, we need to go through an intermediate *) (* inductive type. *) Variant Irat_prf := Ifracq_subproof : (int * int) -> Irat_prf. Variant Irat := IRat : (int * int) -> Irat_prf -> Irat. Definition parse (x : Number.number) : option Irat := let parse_pos i f := let nf := Decimal.nb_digits f in let d := (10 ^ nf)%nat in let n := (Nat.of_uint i * d + Nat.of_uint f)%nat in valq (fracq (Posz n, Posz d)) in let parse i f := match i with | Decimal.Pos i => parse_pos i f | Decimal.Neg i => let (n, d) := parse_pos i f in ((- n)%R, d) end in match x with | Number.Decimal (Decimal.Decimal i f) => let nd := parse i f in Some (IRat nd (Ifracq_subproof nd)) | Number.Decimal (Decimal.DecimalExp _ _ _) => None | Number.Hexadecimal _ => None end. Definition print (r : Irat) : option Number.number := let print_pos n d := if d == 1%nat then Some (Nat.to_uint n, Decimal.Nil) else let d2d5 := match prime_decomp d with | [:: (2, d2); (5, d5)] => Some (d2, d5) | [:: (2, d2)] => Some (d2, O) | [:: (5, d5)] => Some (O, d5) | _ => None end in match d2d5 with | Some (d2, d5) => let f := (2 ^ (d5 - d2) * 5 ^ (d2 - d5))%nat in let (i, f) := edivn (n * f) (d * f) in Some (Nat.to_uint i, Nat.to_uint f) | None => None end in let print_IRat nd := match nd with | (Posz n, Posz d) => match print_pos n d with | Some (i, f) => Some (Decimal.Pos i, f) | None => None end | (Negz n, Posz d) => match print_pos n.+1 d with | Some (i, f) => Some (Decimal.Neg i, f) | None => None end | (_, Negz _) => None end in match r with | IRat nd _ => match print_IRat nd with | Some (i, f) => Some (Number.Decimal (Decimal.Decimal i f)) | None => None end end. Number Notation rat parse print (via Irat mapping [Rat => IRat, fracq_subproof => Ifracq_subproof]) : rat_scope. (* Now, the following should parse as rat (and print unchanged) *) (* Check 12%Q. *) (* Check 3.14%Q. *) (* Check (-3.14)%Q. *) (* Check 0.5%Q. *) (* Check 0.2%Q. *) Lemma val_fracq x : val (fracq x) = fracq_subdef x. Proof. by case: x => [[n|n] [[|[|d]]|d]]//=; rewrite !fracq_opt_subdef_id. Qed. Lemma num_fracq x : numq (fracq x) = if x.2 != 0 then (-1) ^ ((x.2 < 0) (+) (x.1 < 0)) * (`|x.1| %/ gcdn `|x.1| `|x.2|)%:Z else 0. Proof. by rewrite /numq val_fracq/=; case: ifP. Qed. Lemma den_fracq x : denq (fracq x) = if x.2 != 0 then (`|x.2| %/ gcdn `|x.1| `|x.2|)%:Z else 1. Proof. by rewrite /denq val_fracq/=; case: ifP. Qed. Fact ratz_frac n : ratz n = fracq (n, 1). Proof. by apply: val_inj; rewrite val_fracq/= gcdn1 !divn1 abszE mulr_sign_norm. Qed. Fact valqK x : fracq (valq x) = x. Proof. move: x => [[n d] /= Pnd]; apply: val_inj; rewrite ?val_fracq/=. move: Pnd; rewrite /coprime /fracq /= => /andP[] hd -/eqP hnd. by rewrite lt_gtF ?gt_eqF //= hnd !divn1 mulz_sign_abs abszE gtr0_norm. Qed. Definition scalq '(n, d) := sgr d * (gcdn `|n| `|d|)%:Z. Lemma scalq_def x : scalq x = sgr x.2 * (gcdn `|x.1| `|x.2|)%:Z. Proof. by case: x. Qed. Fact scalq_eq0 x : (scalq x == 0) = (x.2 == 0). Proof. case: x => n d; rewrite scalq_def /= mulf_eq0 sgr_eq0 /= eqz_nat. rewrite -[gcdn _ _ == 0]negbK -lt0n gcdn_gt0 ?absz_gt0 [X in ~~ X]orbC. by case: sgrP. Qed. Lemma sgr_scalq x : sgr (scalq x) = sgr x.2. Proof. rewrite scalq_def sgrM sgr_id -[(gcdn _ _)%:Z]intz sgr_nat. by rewrite -lt0n gcdn_gt0 ?absz_gt0 orbC; case: sgrP; rewrite // mul0r. Qed. Lemma signr_scalq x : (scalq x < 0) = (x.2 < 0). Proof. by rewrite -!sgr_cp0 sgr_scalq. Qed. Lemma scalqE x : x.2 != 0 -> scalq x = (-1) ^+ (x.2 < 0)%R * (gcdn `|x.1| `|x.2|)%:Z. Proof. by rewrite scalq_def; case: sgrP. Qed. Fact valq_frac x : x.2 != 0 -> x = (scalq x * numq (fracq x), scalq x * denq (fracq x)). Proof. move=> x2_neq0; rewrite scalqE//; move: x2_neq0. case: x => [n d] /= d_neq0; rewrite num_fracq den_fracq/= ?d_neq0. rewrite mulr_signM -mulrA -!PoszM addKb. do 2!rewrite muln_divCA ?(dvdn_gcdl, dvdn_gcdr) // divnn. by rewrite gcdn_gt0 !absz_gt0 d_neq0 orbT !muln1 !mulz_sign_abs. Qed. Definition zeroq := 0%Q. Definition oneq := 1%Q. Fact frac0q x : fracq (0, x) = zeroq. Proof. apply: val_inj; rewrite //= val_fracq/= div0n !gcd0n !mulr0 !divnn. by have [//|x_neq0] := eqVneq; rewrite absz_gt0 x_neq0. Qed. Fact fracq0 x : fracq (x, 0) = zeroq. Proof. exact/eqP. Qed. Variant fracq_spec (x : int * int) : int * int -> rat -> Type := | FracqSpecN of x.2 = 0 : fracq_spec x (x.1, 0) zeroq | FracqSpecP k fx of k != 0 : fracq_spec x (k * numq fx, k * denq fx) fx. Fact fracqP x : fracq_spec x x (fracq x). Proof. case: x => n d /=; have [d_eq0 | d_neq0] := eqVneq d 0. by rewrite d_eq0 fracq0; constructor. by rewrite {2}[(_, _)]valq_frac //; constructor; rewrite scalq_eq0. Qed. Lemma rat_eqE x y : (x == y) = (numq x == numq y) && (denq x == denq y). Proof. rewrite -val_eqE [val x]surjective_pairing [val y]surjective_pairing /=. by rewrite xpair_eqE. Qed. Lemma sgr_denq x : sgr (denq x) = 1. Proof. by apply/eqP; rewrite sgr_cp0. Qed. Lemma normr_denq x : `|denq x| = denq x. Proof. by rewrite gtr0_norm. Qed. Lemma absz_denq x : `|denq x|%N = denq x :> int. Proof. by rewrite abszE normr_denq. Qed. Lemma rat_eq x y : (x == y) = (numq x * denq y == numq y * denq x). Proof. symmetry; rewrite rat_eqE andbC. have [->|] /= := eqVneq (denq _); first by rewrite (inj_eq (mulIf _)). apply: contraNF => /eqP hxy; rewrite -absz_denq -[eqbRHS]absz_denq. rewrite eqz_nat /= eqn_dvd. rewrite -(@Gauss_dvdr _ `|numq x|) 1?coprime_sym ?coprime_num_den // andbC. rewrite -(@Gauss_dvdr _ `|numq y|) 1?coprime_sym ?coprime_num_den //. by rewrite -!abszM hxy -{1}hxy !abszM !dvdn_mull ?dvdnn. Qed. Fact fracq_eq x y : x.2 != 0 -> y.2 != 0 -> (fracq x == fracq y) = (x.1 * y.2 == y.1 * x.2). Proof. case: fracqP=> //= u fx u_neq0 _; case: fracqP=> //= v fy v_neq0 _; symmetry. rewrite [eqbRHS]mulrC mulrACA [eqbRHS]mulrACA. by rewrite [denq _ * _]mulrC (inj_eq (mulfI _)) ?mulf_neq0 // rat_eq. Qed. Fact fracq_eq0 x : (fracq x == zeroq) = (x.1 == 0) || (x.2 == 0). Proof. move: x=> [n d] /=; have [->|d0] := eqVneq d 0. by rewrite fracq0 eqxx orbT. by rewrite -[zeroq]valqK orbF fracq_eq ?d0 //= mulr1 mul0r. Qed. Fact fracqMM x n d : x != 0 -> fracq (x * n, x * d) = fracq (n, d). Proof. move=> x_neq0; apply/eqP. have [->|d_neq0] := eqVneq d 0; first by rewrite mulr0 !fracq0. by rewrite fracq_eq ?mulf_neq0 //= mulrCA mulrA. Qed. (* We "lock" the definition of addq, oppq, mulq and invq, using a match on *) (* the constructor Rat for both arguments, so that it may only be reduced *) (* when applied to explicit rationals. Since fracq is also "locked" in a *) (* similar way, fracq will not reduce to a Rat x xP unless it is also applied *) (* to "enough" constructors. This preserves the reduction on gound elements *) (* while it suspends it when applied to at least one variable at the leaf of *) (* the arithmetic operation. *) (* Moreover we optimize addition when one or both arguments are integers, *) (* in which case we presimplify the output, this shortens the size of the hnf *) (* of terms of the form N%:Q when N is a concrete natural number. *) Definition addq_subdef (x y : int * int) := let: (x1, x2) := x in let: (y1, y2) := y in match x2, y2 with | Posz 1, Posz 1 => match x1, y1 with | Posz 0, _ => (y1, 1) | _, Posz 0 => (x1, 1) | Posz n, Posz 1 => (Posz n.+1, 1) | Posz 1, Posz n => (Posz n.+1, 1) | _, _ => (x1 + y1, 1) end | Posz 1, _ => (x1 * y2 + y1, y2) | _, Posz 1 => (x1 + y1 * x2, x2) | _, _ => (x1 * y2 + y1 * x2, x2 * y2) end. Definition addq '(Rat x xP) '(Rat y yP) := fracq (addq_subdef x y). Lemma addq_def x y : addq x y = fracq (addq_subdef (valq x) (valq y)). Proof. by case: x; case: y. Qed. Lemma addq_subdefE x y : addq_subdef x y = (x.1 * y.2 + y.1 * x.2, x.2 * y.2). Proof. case: x y => [x1 [[|[|x2]]|x2]] [y1 [[|[|y2]]|y2]]/=; rewrite ?Monoid.simpm//. by case: x1 y1 => [[|[|m]]|m] [[|[|n]]|n]; rewrite ?Monoid.simpm// -PoszD addn1. Qed. Definition oppq_subdef (x : int * int) := (- x.1, x.2). Definition oppq '(Rat x xP) := fracq (oppq_subdef x). Definition oppq_def x : oppq x = fracq (oppq_subdef (valq x)). Proof. by case: x. Qed. Fact addq_subdefC : commutative addq_subdef. Proof. by move=> x y; rewrite !addq_subdefE addrC [x.2 * _]mulrC. Qed. Fact addq_subdefA : associative addq_subdef. Proof. move=> x y z; rewrite !addq_subdefE. by rewrite !mulrA !mulrDl addrA ![_ * x.2]mulrC !mulrA. Qed. Fact addq_frac x y : x.2 != 0 -> y.2 != 0 -> (addq (fracq x) (fracq y)) = fracq (addq_subdef x y). Proof. case: fracqP => // u fx u_neq0 _; case: fracqP => // v fy v_neq0 _. rewrite addq_def !addq_subdefE /=. rewrite ![(_ * numq _) * _]mulrACA [(_ * denq _) * _]mulrACA. by rewrite [v * _]mulrC -mulrDr fracqMM ?mulf_neq0. Qed. Fact ratzD : {morph ratz : x y / x + y >-> addq x y}. Proof. by move=> x y; rewrite !ratz_frac addq_frac// addq_subdefE/= !mulr1. Qed. Fact oppq_frac x : oppq (fracq x) = fracq (oppq_subdef x). Proof. rewrite /oppq_subdef; case: fracqP => /= [|u fx u_neq0]. by rewrite fracq0. by rewrite oppq_def -mulrN fracqMM. Qed. Fact ratzN : {morph ratz : x / - x >-> oppq x}. Proof. by move=> x /=; rewrite !ratz_frac // /add /= !mulr1. Qed. Fact addqC : commutative addq. Proof. by move=> x y; rewrite !addq_def /= addq_subdefC. Qed. Fact addqA : associative addq. Proof. move=> x y z; rewrite -[x]valqK -[y]valqK -[z]valqK. by rewrite ?addq_frac ?addq_subdefA// ?addq_subdefE ?mulf_neq0 ?denq_neq0. Qed. Fact add0q : left_id zeroq addq. Proof. move=> x; rewrite -[x]valqK -[zeroq]valqK addq_frac ?denq_neq0 // !addq_subdefE. by rewrite mul0r add0r mulr1 mul1r -surjective_pairing. Qed. Fact addNq : left_inverse (fracq (0, 1)) oppq addq. Proof. move=> x; rewrite -[x]valqK !(addq_frac, oppq_frac) ?denq_neq0 //. rewrite !addq_subdefE /oppq_subdef //= mulNr addNr; apply/eqP. by rewrite fracq_eq ?mulf_neq0 ?denq_neq0 //= !mul0r. Qed. HB.instance Definition _ := GRing.isZmodule.Build rat addqA addqC add0q addNq. Definition mulq_subdef (x y : int * int) := let: (x1, x2) := x in let: (y1, y2) := y in match x2, y2 with | Posz 1, Posz 1 => (x1 * y1, 1) | Posz 1, _ => (x1 * y1, y2) | _, Posz 1 => (x1 * y1, x2) | _, _ => (x1 * y1, x2 * y2) end. Definition mulq '(Rat x xP) '(Rat y yP) := fracq (mulq_subdef x y). Lemma mulq_def x y : mulq x y = fracq (mulq_subdef (valq x) (valq y)). Proof. by case: x; case: y. Qed. Lemma mulq_subdefE x y : mulq_subdef x y = (x.1 * y.1, x.2 * y.2). Proof. by case: x y => [x1 [[|[|x2]]|x2]] [y1 [[|[|y2]]|y2]]/=; rewrite ?Monoid.simpm. Qed. Fact mulq_subdefC : commutative mulq_subdef. Proof. by move=> x y; rewrite !mulq_subdefE mulrC [_ * x.2]mulrC. Qed. Fact mul_subdefA : associative mulq_subdef. Proof. by move=> x y z; rewrite !mulq_subdefE !mulrA. Qed. Definition invq_subdef (x : int * int) := (x.2, x.1). Definition invq '(Rat x xP) := fracq (invq_subdef x). Lemma invq_def x : invq x = fracq (invq_subdef (valq x)). Proof. by case: x. Qed. Fact mulq_frac x y : (mulq (fracq x) (fracq y)) = fracq (mulq_subdef x y). Proof. rewrite mulq_def !mulq_subdefE; case: (fracqP x) => /= [|u fx u_neq0]. by rewrite !mul0r !mul1r fracq0 frac0q. case: (fracqP y) => /= [|v fy v_neq0]. by rewrite !mulr0 !mulr1 fracq0 frac0q. by rewrite ![_ * (v * _)]mulrACA [RHS]fracqMM ?mulf_neq0. Qed. Fact ratzM : {morph ratz : x y / x * y >-> mulq x y}. Proof. by move=> x y /=; rewrite !ratz_frac //= !mulr1. Qed. Fact invq_frac x : x.1 != 0 -> x.2 != 0 -> invq (fracq x) = fracq (invq_subdef x). Proof. by rewrite invq_def; case: (fracqP x) => // k ? k0; rewrite fracqMM. Qed. Fact mulqC : commutative mulq. Proof. by move=> x y; rewrite !mulq_def mulq_subdefC. Qed. Fact mulqA : associative mulq. Proof. by move=> x y z; rewrite -[x]valqK -[y]valqK -[z]valqK !mulq_frac mul_subdefA. Qed. Fact mul1q : left_id oneq mulq. Proof. move=> x; rewrite -[x]valqK -[oneq]valqK; rewrite mulq_frac !mulq_subdefE. by rewrite !mul1r -surjective_pairing. Qed. Fact mulq_addl : left_distributive mulq addq. Proof. move=> x y z; rewrite -[x]valqK -[y]valqK -[z]valqK /=. rewrite !(mulq_frac, addq_frac, mulq_subdefE, addq_subdefE) ?mulf_neq0 ?denq_neq0 //=. apply/eqP; rewrite fracq_eq ?mulf_neq0 ?denq_neq0 //= !mulrDl; apply/eqP. by rewrite !mulrA ![_ * (valq z).1]mulrC !mulrA ![_ * (valq x).2]mulrC !mulrA. Qed. Fact nonzero1q : oneq != zeroq. Proof. by []. Qed. HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build rat mulqA mulqC mul1q mulq_addl nonzero1q. Fact mulVq x : x != 0 -> mulq (invq x) x = 1. Proof. rewrite -[x]valqK -[0]valqK fracq_eq ?denq_neq0 //= mulr1 mul0r=> nx0. rewrite !(mulq_frac, invq_frac, mulq_subdefE) ?denq_neq0 // -[1]valqK. by apply/eqP; rewrite fracq_eq ?mulf_neq0 ?denq_neq0 //= mulr1 mul1r mulrC. Qed. Fact invq0 : invq 0 = 0. Proof. exact/eqP. Qed. HB.instance Definition _ := GRing.ComNzRing_isField.Build rat mulVq invq0. Lemma numq_eq0 x : (numq x == 0) = (x == 0). Proof. rewrite -[x]valqK fracq_eq0; case: fracqP=> /= [|k {}x k0]. by rewrite eqxx orbT. by rewrite !mulf_eq0 (negPf k0) /= denq_eq0 orbF. Qed. Notation "n %:Q" := ((n : int)%:~R : rat) : ring_scope. #[global] Hint Resolve denq_neq0 denq_gt0 denq_ge0 : core. Definition subq (x y : rat) : rat := (addq x (oppq y)). Definition divq (x y : rat) : rat := (mulq x (invq y)). Infix "+" := addq : rat_scope. Notation "- x" := (oppq x) : rat_scope. Infix "*" := mulq : rat_scope. Notation "x ^-1" := (invq x) : rat_scope. Infix "-" := subq : rat_scope. Infix "/" := divq : rat_scope. (* ratz should not be used, %:Q should be used instead *) Lemma ratzE n : ratz n = n%:Q. Proof. elim: n=> [|n ihn|n ihn]; first by rewrite mulr0z ratz_frac. by rewrite intS mulrzDr ratzD ihn. by rewrite intS opprD mulrzDr ratzD ihn. Qed. Lemma numq_int n : numq n%:Q = n. Proof. by rewrite -ratzE. Qed. Lemma denq_int n : denq n%:Q = 1. Proof. by rewrite -ratzE. Qed. Lemma rat0 : 0%:Q = 0. Proof. by []. Qed. Lemma rat1 : 1%:Q = 1. Proof. by []. Qed. Lemma numqN x : numq (- x) = - numq x. Proof. rewrite [- _]oppq_def/= num_fracq. case: x => -[a b]; rewrite /numq/= => /andP[b_gt0]. rewrite /coprime => /eqP cab. by rewrite lt_gtF ?gt_eqF // {2}abszN cab divn1 mulz_sign_abs. Qed. Lemma denqN x : denq (- x) = denq x. Proof. rewrite [- _]oppq_def den_fracq. case: x => -[a b]; rewrite /denq/= => /andP[b_gt0]. by rewrite /coprime=> /eqP cab; rewrite gt_eqF // abszN cab divn1 gtz0_abs. Qed. (* Will be subsumed by pnatr_eq0 *) Fact intq_eq0 n : (n%:~R == 0 :> rat) = (n == 0)%N. Proof. by rewrite -ratzE /ratz rat_eqE/= /numq /denq/= eqxx andbT. Qed. (* fracq should never appear, its canonical form is _%:Q / _%:Q *) Lemma fracqE x : fracq x = x.1%:Q / x.2%:Q. Proof. move: x => [m n] /=; apply/val_inj; rewrite val_fracq/=. case: eqVneq => //= [->|n_neq0]; first by rewrite rat0 invr0 mulr0. rewrite -[m%:Q]valqK -[n%:Q]valqK. rewrite [_^-1]invq_frac ?denq_neq0 ?numq_eq0 ?intq_eq0//=. rewrite [X in valq X]mulq_frac val_fracq /invq_subdef !mulq_subdefE/=. by rewrite -!/(numq _) -!/(denq _) !numq_int !denq_int mul1r mulr1 n_neq0. Qed. Lemma divq_num_den x : (numq x)%:Q / (denq x)%:Q = x. Proof. by rewrite -{3}[x]valqK [valq _]surjective_pairing /= fracqE. Qed. Variant divq_spec (n d : int) : int -> int -> rat -> Type := | DivqSpecN of d = 0 : divq_spec n d n 0 0 | DivqSpecP k x of k != 0 : divq_spec n d (k * numq x) (k * denq x) x. (* replaces fracqP *) Lemma divqP n d : divq_spec n d n d (n%:Q / d%:Q). Proof. set x := (n, d); rewrite -[n]/x.1 -[d]/x.2 -fracqE. by case: fracqP => [_|k fx k_neq0] /=; constructor. Qed. Variant rat_spec (* (x : rat) *) : rat -> int -> int -> Type := Rat_spec (n : int) (d : nat) & coprime `|n| d.+1 : rat_spec (* x *) (n%:Q / d.+1%:Q) n d.+1. Lemma ratP x : rat_spec x (numq x) (denq x). Proof. rewrite -{1}[x](divq_num_den); case hd: denq => [p|n]. have: 0 < p%:Z by rewrite -hd denq_gt0. case: p hd=> //= n hd; constructor; rewrite -?hd ?divq_num_den //. by rewrite -[n.+1]/`|n.+1|%N -hd coprime_num_den. by move: (denq_gt0 x); rewrite hd. Qed. Lemma coprimeq_num n d : coprime `|n| `|d| -> numq (n%:~R / d%:~R) = sgr d * n. Proof. move=> cnd /=; have <- := fracqE (n, d). rewrite num_fracq/= (eqP (cnd : _ == 1)) divn1. have [|d_gt0|d_lt0] := sgrP d; by rewrite (mul0r, mul1r, mulN1r) //= ?[_ ^ _]signrN ?mulNr mulz_sign_abs. Qed. Lemma coprimeq_den n d : coprime `|n| `|d| -> denq (n%:~R / d%:~R) = (if d == 0 then 1 else `|d|). Proof. move=> cnd; have <- := fracqE (n, d). by rewrite den_fracq/= (eqP (cnd : _ == 1)) divn1; case: d {cnd}; case. Qed. Lemma denqVz (i : int) : i != 0 -> denq (i%:~R^-1) = `|i|. Proof. move=> h; rewrite -div1r -[1]/(1%:~R). by rewrite coprimeq_den /= ?coprime1n // (negPf h). Qed. Lemma numqE x : (numq x)%:~R = x * (denq x)%:~R. Proof. by rewrite -{2}[x]divq_num_den divfK // intq_eq0 denq_eq0. Qed. Lemma denqP x : {d | denq x = d.+1}. Proof. by rewrite /denq; case: x => [[_ [[|d]|]] //= _]; exists d. Qed. Definition normq '(Rat x _) : rat := `|x.1|%:~R / (x.2)%:~R. Definition le_rat '(Rat x _) '(Rat y _) := x.1 * y.2 <= y.1 * x.2. Definition lt_rat '(Rat x _) '(Rat y _) := x.1 * y.2 < y.1 * x.2. Lemma normqE x : normq x = `|numq x|%:~R / (denq x)%:~R. Proof. by case: x. Qed. Lemma le_ratE x y : le_rat x y = (numq x * denq y <= numq y * denq x). Proof. by case: x; case: y. Qed. Lemma lt_ratE x y : lt_rat x y = (numq x * denq y < numq y * denq x). Proof. by case: x; case: y. Qed. Lemma gt_rat0 x : lt_rat 0 x = (0 < numq x). Proof. by rewrite lt_ratE mul0r mulr1. Qed. Lemma lt_rat0 x : lt_rat x 0 = (numq x < 0). Proof. by rewrite lt_ratE mul0r mulr1. Qed. Lemma ge_rat0 x : le_rat 0 x = (0 <= numq x). Proof. by rewrite le_ratE mul0r mulr1. Qed. Lemma le_rat0 x : le_rat x 0 = (numq x <= 0). Proof. by rewrite le_ratE mul0r mulr1. Qed. Fact le_rat0D x y : le_rat 0 x -> le_rat 0 y -> le_rat 0 (x + y). Proof. rewrite !ge_rat0 => hnx hny. have hxy: (0 <= numq x * denq y + numq y * denq x). by rewrite addr_ge0 ?mulr_ge0. rewrite [_ + _]addq_def /numq /= -!/(denq _) ?mulf_eq0 ?denq_eq0. rewrite val_fracq/=; case: ifP => //=. by rewrite ?addq_subdefE !mulr_ge0// !le_gtF ?mulr_ge0 ?denq_ge0//=. Qed. Fact le_rat0M x y : le_rat 0 x -> le_rat 0 y -> le_rat 0 (x * y). Proof. rewrite !ge_rat0 => hnx hny. have hxy: (0 <= numq x * denq y + numq y * denq x). by rewrite addr_ge0 ?mulr_ge0. rewrite [_ * _]mulq_def /numq /= -!/(denq _) ?mulf_eq0 ?denq_eq0. rewrite val_fracq/=; case: ifP => //=. by rewrite ?mulq_subdefE !mulr_ge0// !le_gtF ?mulr_ge0 ?denq_ge0//=. Qed. Fact le_rat0_anti x : le_rat 0 x -> le_rat x 0 -> x = 0. Proof. by move=> hx hy; apply/eqP; rewrite -numq_eq0 eq_le -ge_rat0 -le_rat0 hx hy. Qed. Lemma sgr_numq_div (n d : int) : sgr (numq (n%:Q / d%:Q)) = sgr n * sgr d. Proof. set x := (n, d); rewrite -[n]/x.1 -[d]/x.2 -fracqE. case: fracqP => [|k fx k_neq0] /=; first by rewrite mulr0. by rewrite !sgrM mulrACA -expr2 sqr_sg k_neq0 sgr_denq mulr1 mul1r. Qed. Fact subq_ge0 x y : le_rat 0 (y - x) = le_rat x y. Proof. symmetry; rewrite ge_rat0 !le_ratE -subr_ge0. case: ratP => nx dx cndx; case: ratP => ny dy cndy. rewrite -!mulNr addf_div ?intq_eq0 // !mulNr -!rmorphM -rmorphB /=. symmetry; rewrite !leNgt -sgr_cp0 sgr_numq_div mulrC gtr0_sg //. by rewrite mul1r sgr_cp0. Qed. Fact le_rat_total : total le_rat. Proof. by move=> x y; rewrite !le_ratE; apply: le_total. Qed. Fact numq_sign_mul (b : bool) x : numq ((-1) ^+ b * x) = (-1) ^+ b * numq x. Proof. by case: b; rewrite ?(mul1r, mulN1r) // numqN. Qed. Fact numq_div_lt0 n d : n != 0 -> d != 0 -> (numq (n%:~R / d%:~R) < 0)%R = (n < 0)%R (+) (d < 0)%R. Proof. move=> n0 d0; rewrite -sgr_cp0 sgr_numq_div !sgr_def n0 d0. by rewrite !mulr1n -signr_addb; case: (_ (+) _). Qed. Lemma normr_num_div n d : `|numq (n%:~R / d%:~R)| = numq (`|n|%:~R / `|d|%:~R). Proof. rewrite (normrEsg n) (normrEsg d) !rmorphM /= invfM mulrACA !sgr_def. have [->|n_neq0] := eqVneq; first by rewrite mul0r mulr0. have [->|d_neq0] := eqVneq; first by rewrite invr0 !mulr0. rewrite !intr_sign invr_sign -signr_addb numq_sign_mul -numq_div_lt0 //. by apply: (canRL (signrMK _)); rewrite mulz_sign_abs. Qed. Fact norm_ratN x : normq (- x) = normq x. Proof. by rewrite !normqE numqN denqN normrN. Qed. Fact ge_rat0_norm x : le_rat 0 x -> normq x = x. Proof. rewrite ge_rat0; case: ratP=> [] // n d cnd n_ge0. by rewrite normqE /= normr_num_div ?ger0_norm // divq_num_den. Qed. Fact lt_rat_def x y : (lt_rat x y) = (y != x) && (le_rat x y). Proof. by rewrite lt_ratE le_ratE lt_def rat_eq. Qed. HB.instance Definition _ := Num.IntegralDomain_isLeReal.Build rat le_rat0D le_rat0M le_rat0_anti subq_ge0 (@le_rat_total 0) norm_ratN ge_rat0_norm lt_rat_def. Lemma numq_ge0 x : (0 <= numq x) = (0 <= x). Proof. by case: ratP => n d cnd; rewrite ?pmulr_lge0 ?invr_gt0 (ler0z, ltr0z). Qed. Lemma numq_le0 x : (numq x <= 0) = (x <= 0). Proof. by rewrite -oppr_ge0 -numqN numq_ge0 oppr_ge0. Qed. Lemma numq_gt0 x : (0 < numq x) = (0 < x). Proof. by rewrite !ltNge numq_le0. Qed. Lemma numq_lt0 x : (numq x < 0) = (x < 0). Proof. by rewrite !ltNge numq_ge0. Qed. Lemma sgr_numq x : sgz (numq x) = sgz x. Proof. apply/eqP; case: (sgzP x); rewrite sgz_cp0 ?(numq_gt0, numq_lt0) //. by move->. Qed. Lemma denq_mulr_sign (b : bool) x : denq ((-1) ^+ b * x) = denq x. Proof. by case: b; rewrite ?(mul1r, mulN1r) // denqN. Qed. Lemma denq_norm x : denq `|x| = denq x. Proof. by rewrite normrEsign denq_mulr_sign. Qed. Module ratArchimedean. Section ratArchimedean. Implicit Types x : rat. Definition floor x : int := (numq x %/ denq x)%Z. Definition ceil x : int := - (- numq x %/ denq x)%Z. Definition truncn x : nat := if 0 <= x then (`|numq x| %/ `|denq x|)%N else 0%N. Let is_int x := denq x == 1. Let is_nat x := (0 <= x) && (denq x == 1). Fact floorP x : if x \is Num.real then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0. Proof. rewrite num_real /floor; case: (ratP x) => n d _ {x}; rewrite ler_pdivlMr//. by rewrite ltr_pdivrMr// -!intrM ler_int ltr_int lez_floor ?ltz_ceil. Qed. Fact ceilP x : ceil x = - floor (- x). Proof. by rewrite /ceil /floor numqN denqN. Qed. Fact truncnP x : truncn x = if floor x is Posz n then n else 0. Proof. rewrite /truncn /floor; case: (ratP x) => n d _ {x} /=. by rewrite !ler_pdivlMr// mul0r; case: n => n; rewrite ler0z//= mul1n. Qed. Fact intrP x : reflect (exists n, x = n%:~R) (is_int x). Proof. apply: (iffP idP) => [/eqP d1 | [i ->]]; [|by rewrite /is_int denq_int]. by exists (numq x); case: (ratP x) d1 => n d _ ->; rewrite divr1. Qed. Fact natrP x : reflect (exists n, x = n%:R) (is_nat x). Proof. apply: (iffP idP) => [/andP[]/[swap]/intrP[i ->]|[n ->]]. by rewrite ler0z; case: i => [n _|//]; exists n. by rewrite /is_nat pmulrn ler0z denq_int. Qed. End ratArchimedean. End ratArchimedean. HB.instance Definition _ := Num.NumDomain_hasFloorCeilTruncn.Build rat ratArchimedean.floorP ratArchimedean.ceilP ratArchimedean.truncnP ratArchimedean.intrP ratArchimedean.natrP. Lemma floorErat (x : rat) : Num.floor x = (numq x %/ denq x)%Z. Proof. by []. Qed. Lemma ceilErat (x : rat) : Num.ceil x = - (- numq x %/ denq x)%Z. Proof. by []. Qed. Lemma Qint_def (x : rat) : (x \is a Num.int) = (denq x == 1). Proof. by []. Qed. Lemma numqK : {in Num.int, cancel (fun x => numq x) intr}. Proof. by move=> _ /intrP [x ->]; rewrite numq_int. Qed. Lemma natq_div m n : (n %| m)%N -> (m %/ n)%:R = m%:R / n%:R :> rat. Proof. exact/pchar0_natf_div/pchar_num. Qed. Section InRing. Variable R : unitRingType. Definition ratr x : R := (numq x)%:~R / (denq x)%:~R. Lemma ratr_int z : ratr z%:~R = z%:~R. Proof. by rewrite /ratr numq_int denq_int divr1. Qed. Lemma ratr_nat n : ratr n%:R = n%:R. Proof. exact: ratr_int n. Qed. Lemma rpred_rat (S : divringClosed R) a : ratr a \in S. Proof. by rewrite rpred_div ?rpred_int. Qed. End InRing. Section Fmorph. Implicit Type rR : unitRingType. Lemma fmorph_rat (aR : fieldType) rR (f : {rmorphism aR -> rR}) a : f (ratr _ a) = ratr _ a. Proof. by rewrite fmorph_div !rmorph_int. Qed. Lemma fmorph_eq_rat rR (f : {rmorphism rat -> rR}) : f =1 ratr _. Proof. by move=> a; rewrite -{1}[a]divq_num_den fmorph_div !rmorph_int. Qed. End Fmorph. Section Linear. Implicit Types (U V : lmodType rat) (A B : lalgType rat). Lemma rat_linear U V (f : U -> V) : zmod_morphism f -> scalable f. Proof. move=> fB a u. pose aM := GRing.isZmodMorphism.Build U V f fB. pose phi : {additive U -> V} := HB.pack f aM. rewrite -[f]/(phi : _ -> _) -{2}[a]divq_num_den mulrC -scalerA. apply: canRL (scalerK _) _; first by rewrite intr_eq0 denq_neq0. rewrite 2!scaler_int -3!raddfMz /=. by rewrite -scalerMzr scalerMzl -mulrzr -numqE scaler_int. Qed. End Linear. Section InPrealField. Variable F : numFieldType. Fact ratr_is_zmod_morphism : zmod_morphism (@ratr F). Proof. have injZtoQ: @injective rat int intr by apply: intr_inj. have nz_den x: (denq x)%:~R != 0 :> F by rewrite intr_eq0 denq_eq0. move=> x y. apply: (canLR (mulfK (nz_den _))); apply: (mulIf (nz_den x)). rewrite mulrAC mulrBl divfK ?nz_den // mulrAC -!rmorphM. apply: (mulIf (nz_den y)); rewrite mulrAC mulrBl divfK ?nz_den //. rewrite -!(rmorphM, rmorphB); congr _%:~R; apply: injZtoQ. rewrite !(rmorphM, rmorphB) /= [_ - _]lock /= -lock !numqE. by rewrite (mulrAC y) -!mulrBl -mulrA mulrAC !mulrA. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ratr_is_additive` instead")] Definition ratr_is_additive := ratr_is_zmod_morphism. Fact ratr_is_monoid_morphism : monoid_morphism (@ratr F). Proof. have injZtoQ: @injective rat int intr by apply: intr_inj. have nz_den x: (denq x)%:~R != 0 :> F by rewrite intr_eq0 denq_eq0. split=> [|x y]; first by rewrite /ratr divr1. rewrite /ratr mulrC mulrAC; apply: canLR (mulKf (nz_den _)) _; rewrite !mulrA. do 2!apply: canRL (mulfK (nz_den _)) _; rewrite -!rmorphM; congr _%:~R. apply: injZtoQ; rewrite !rmorphM [x * y]lock /= !numqE -lock. by rewrite -!mulrA mulrA mulrCA -!mulrA (mulrCA y). Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ratr_is_monoid_morphism` instead")] Definition ratr_is_multiplicative := (fun g => (g.2,g.1)) ratr_is_monoid_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build rat F (@ratr F) ratr_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build rat F (@ratr F) ratr_is_monoid_morphism. Lemma ler_rat : {mono (@ratr F) : x y / x <= y}. Proof. move=> x y /=; case: (ratP x) => nx dx cndx; case: (ratP y) => ny dy cndy. rewrite !fmorph_div /= !ratr_int !ler_pdivlMr ?ltr0z //. by rewrite ![_ / _ * _]mulrAC !ler_pdivrMr ?ltr0z // -!rmorphM /= !ler_int. Qed. Lemma ltr_rat : {mono (@ratr F) : x y / x < y}. Proof. exact: leW_mono ler_rat. Qed. Lemma ler0q x : (0 <= ratr F x) = (0 <= x). Proof. by rewrite (_ : 0 = ratr F 0) ?ler_rat ?rmorph0. Qed. Lemma lerq0 x : (ratr F x <= 0) = (x <= 0). Proof. by rewrite (_ : 0 = ratr F 0) ?ler_rat ?rmorph0. Qed. Lemma ltr0q x : (0 < ratr F x) = (0 < x). Proof. by rewrite (_ : 0 = ratr F 0) ?ltr_rat ?rmorph0. Qed. Lemma ltrq0 x : (ratr F x < 0) = (x < 0). Proof. by rewrite (_ : 0 = ratr F 0) ?ltr_rat ?rmorph0. Qed. Lemma ratr_sg x : ratr F (sgr x) = sgr (ratr F x). Proof. by rewrite !sgr_def fmorph_eq0 ltrq0 rmorphMn /= rmorph_sign. Qed. Lemma ratr_norm x : ratr F `|x| = `|ratr F x|. Proof. by rewrite {2}[x]numEsign rmorphMsign normrMsign [`|ratr F _|]ger0_norm ?ler0q. Qed. Lemma minr_rat : {morph ratr F : x y / Num.min x y}. Proof. by move=> x y; rewrite !minEle ler_rat; case: leP. Qed. Lemma maxr_rat : {morph ratr F : x y / Num.max x y}. Proof. by move=> x y; rewrite !maxEle ler_rat; case: leP. Qed. End InPrealField. Section InParchiField. Variable F : archiNumFieldType. Lemma floor_rat : {mono (@ratr F) : x / Num.floor x}. Proof. move=> x; apply: floor_def; apply/andP; split. - by rewrite -ratr_int ler_rat floor_le_tmp. - by rewrite -ratr_int ltr_rat floorD1_gt. Qed. Lemma ceil_rat : {mono (@ratr F) : x / Num.ceil x}. Proof. by move=> x; rewrite !ceilNfloor -rmorphN floor_rat. Qed. End InParchiField. Arguments ratr {R}. Lemma Qint_dvdz (m d : int) : (d %| m)%Z -> (m%:~R / d%:~R : rat) \is a Num.int. Proof. case/dvdzP=> z ->; rewrite rmorphM /=; have [->|dn0] := eqVneq d 0. by rewrite mulr0 mul0r. by rewrite mulfK ?intr_eq0. Qed. Lemma Qnat_dvd (m d : nat) : (d %| m)%N -> (m%:R / d%:R : rat) \is a Num.nat. Proof. by move=> h; rewrite natrEint divr_ge0 ?ler0n // !pmulrn Qint_dvdz. Qed. Section ZpolyScale. Local Notation pZtoQ := (map_poly (intr : int -> rat)). Lemma size_rat_int_poly p : size (pZtoQ p) = size p. Proof. by apply: size_map_inj_poly; first apply: intr_inj. Qed. Lemma rat_poly_scale (p : {poly rat}) : {q : {poly int} & {a | a != 0 & p = a%:~R^-1 *: pZtoQ q}}. Proof. pose a := \prod_(i < size p) denq p`_i. have nz_a: a != 0 by apply/prodf_neq0=> i _; apply: denq_neq0. exists (map_poly numq (a%:~R *: p)), a => //. apply: canRL (scalerK _) _; rewrite ?intr_eq0 //. apply/polyP=> i; rewrite !(coefZ, coef_map_id0) // numqK // Qint_def mulrC. have [ltip | /(nth_default 0)->] := ltnP i (size p); last by rewrite mul0r. by rewrite [a](bigD1 (Ordinal ltip)) // rmorphM mulrA -numqE -rmorphM denq_int. Qed. Lemma dvdp_rat_int p q : (pZtoQ p %| pZtoQ q) = (p %| q). Proof. apply/dvdpP/Pdiv.Idomain.dvdpP=> [[/= r1 Dq] | [[/= a r] nz_a Dq]]; last first. exists (a%:~R^-1 *: pZtoQ r). by rewrite -scalerAl -rmorphM -Dq /= linearZ/= scalerK ?intr_eq0. have [r [a nz_a Dr1]] := rat_poly_scale r1; exists (a, r) => //=. apply: (map_inj_poly _ _ : injective pZtoQ) => //; first exact: intr_inj. by rewrite linearZ /= Dq Dr1 -scalerAl -rmorphM scalerKV ?intr_eq0. Qed. Lemma dvdpP_rat_int p q : p %| pZtoQ q -> {p1 : {poly int} & {a | a != 0 & p = a *: pZtoQ p1} & {r | q = p1 * r}}. Proof. have{p} [p [a nz_a ->]] := rat_poly_scale p. rewrite dvdpZl ?invr_eq0 ?intr_eq0 // dvdp_rat_int => dv_p_q. exists (zprimitive p); last exact: dvdpP_int. have [-> | nz_p] := eqVneq p 0. by exists 1; rewrite ?oner_eq0 // zprimitive0 map_poly0 !scaler0. exists ((zcontents p)%:~R / a%:~R). by rewrite mulf_neq0 ?invr_eq0 ?intr_eq0 ?zcontents_eq0. by rewrite mulrC -scalerA -map_polyZ -zpolyEprim. Qed. Lemma irreducible_rat_int p : irreducible_poly (pZtoQ p) <-> irreducible_poly p. Proof. rewrite /irreducible_poly size_rat_int_poly; split=> -[] p1 p_irr; split=> //. move=> q q1; rewrite /eqp -!dvdp_rat_int => rq. by apply/p_irr => //; rewrite size_rat_int_poly. move=> q + /dvdpP_rat_int [] r [] c c0 qE [] s sE. rewrite qE size_scale// size_rat_int_poly => r1. apply/(eqp_trans (eqp_scale _ c0)). rewrite /eqp !dvdp_rat_int; apply/p_irr => //. by rewrite sE dvdp_mulIl. Qed. End ZpolyScale. (* Integral spans. *) Definition inIntSpan (V : zmodType) m (s : m.-tuple V) v := exists a : int ^ m, v = \sum_(i < m) s`_i *~ a i. Lemma solve_Qint_span (vT : vectType rat) m (s : m.-tuple vT) v : {b : int ^ m & {p : seq (int ^ m) & forall a : int ^ m, v = \sum_(i < m) s`_i *~ a i <-> exists c : seq int, a = b + \sum_(i < size p) p`_i *~ c`_i}} + (~ inIntSpan s v). Proof. have s_s (i : 'I_m): s`_i \in <<s>>%VS by rewrite memv_span ?memt_nth. have s_Zs a: \sum_(i < m) s`_i *~ a i \in <<s>>%VS. by apply/rpred_sum => i _; apply/rpredMz. case s_v: (v \in <<s>>%VS); last by right=> [[a Dv]]; rewrite Dv s_Zs in s_v. move SE : (\matrix_(i < m, j < _) coord (vbasis <<s>>) j s`_i) => S. move rE : (\rank S) => r; move kE : (m - r)%N => k. have Dm: (m = k + r)%N by rewrite -kE -rE subnK ?rank_leq_row. rewrite Dm in s s_s s_Zs s_v S SE rE kE *. move=> {Dm m}; pose m := (k + r)%N. have [K kerK]: {K : 'M_(k, m) | map_mx intr K == kermx S}%MS. move: (mxrank_ker S); rewrite rE kE => krk. pose B := row_base (kermx S); pose d := \prod_ij denq (B ij.1 ij.2). exists (castmx (krk, erefl m) (map_mx numq (intr d *: B))). rewrite map_castmx !eqmx_cast -map_mx_comp map_mx_id_in => [|i j]; last first. rewrite mxE mulrC [d](bigD1 (i, j)) //= rmorphM mulrA. by rewrite -numqE -rmorphM numq_int. suff nz_d: d%:Q != 0 by rewrite !eqmx_scale // !eq_row_base andbb. by rewrite intr_eq0; apply/prodf_neq0 => i _; apply: denq_neq0. have [L _ [G uG [D _ defK]]] := int_Smith_normal_form K. have {K L D defK kerK} [kerGu kerS_sub_Gu]: map_mx intr (usubmx G) *m S = 0 /\ (kermx S <= map_mx intr (usubmx G))%MS. pose Kl : 'M[rat]_k := map_mx intr (lsubmx (K *m invmx G)). have {}defK: map_mx intr K = Kl *m map_mx intr (usubmx G). rewrite /Kl -map_mxM; congr map_mx. rewrite -[LHS](mulmxKV uG) -{2}[G]vsubmxK -{1}[K *m _]hsubmxK. rewrite mul_row_col -[RHS]addr0; congr (_ + _). rewrite defK mulmxK //= -[RHS](mul0mx _ (dsubmx G)); congr (_ *m _). apply/matrixP => i j; rewrite !mxE big1 //= => j1 _. rewrite mxE /= eqn_leq andbC. by rewrite leqNgt (leq_trans (valP j1)) ?mulr0 ?leq_addr. split; last by rewrite -(eqmxP kerK); apply/submxP; exists Kl. suff /row_full_inj: row_full Kl. by apply; rewrite mulmx0 mulmxA (sub_kermxP _) // -(eqmxP kerK) defK. rewrite /row_full eqn_leq rank_leq_row /= -{1}kE -{2}rE -(mxrank_ker S). by rewrite -(eqmxP kerK) defK mxrankM_maxl. pose T := map_mx intr (dsubmx G) *m S. have defS: map_mx intr (rsubmx (invmx G)) *m T = S. rewrite mulmxA -map_mxM /=; move: (mulVmx uG). rewrite -{2}[G]vsubmxK -{1}[invmx G]hsubmxK mul_row_col. move/(canRL (addKr _)) ->; rewrite -mulNmx raddfD /= map_mx1 map_mxM /=. by rewrite mulmxDl -mulmxA kerGu mulmx0 add0r mul1mx. pose vv := \row_j coord (vbasis <<s>>) j v. have uS: row_full S. apply/row_fullP; exists (\matrix_(i, j) coord s j (vbasis <<s>>)`_i). apply/matrixP => j1 j2; rewrite !mxE. rewrite -(coord_free _ _ (basis_free (vbasisP _))). rewrite -!tnth_nth (coord_span (vbasis_mem (mem_tnth j1 _))) linear_sum. by apply: eq_bigr => /= i _; rewrite -SE !mxE (tnth_nth 0) !linearZ. have eqST: (S :=: T)%MS by apply/eqmxP; rewrite -{1}defS !submxMl. case Zv: (map_mx denq (vv *m pinvmx T) == const_mx 1); last first. right=> [[a Dv]]; case/eqP: Zv; apply/rowP. have ->: vv = map_mx intr (\row_i a i) *m S. apply/rowP => j; rewrite !mxE Dv linear_sum. by apply: eq_bigr => i _; rewrite -SE -scaler_int linearZ !mxE. rewrite -defS -2!mulmxA; have ->: T *m pinvmx T = 1%:M. have uT: row_free T by rewrite /row_free -eqST rE. by apply: (row_free_inj uT); rewrite mul1mx mulmxKpV. by move=> i; rewrite mulmx1 -map_mxM 2!mxE denq_int mxE. pose b := map_mx numq (vv *m pinvmx T) *m dsubmx G. left; exists [ffun j => b 0 j], [seq [ffun j => (usubmx G) i j] | i : 'I_k]. rewrite size_image card_ord => a; rewrite -[a](addNKr [ffun j => b 0 j]). move: (_ + a) => h; under eq_bigr => i _ do rewrite !ffunE mulrzDr. rewrite big_split /=. have <-: v = \sum_(i < m) s`_i *~ b 0 i. transitivity (\sum_j (map_mx intr b *m S) 0 j *: (vbasis <<s>>)`_j). rewrite {1}(coord_vbasis s_v); apply: eq_bigr => j _; congr (_ *: _). suff ->: map_mx intr b = vv *m pinvmx T *m map_mx intr (dsubmx G). by rewrite -(mulmxA _ _ S) mulmxKpV ?mxE // -eqST submx_full. rewrite map_mxM /=; congr (_ *m _); apply/rowP => i; rewrite 2!mxE numqE. by have /eqP/rowP/(_ i)/[!mxE] -> := Zv; rewrite mulr1. rewrite (coord_vbasis (s_Zs _)); apply: eq_bigr => j _; congr (_ *: _). rewrite linear_sum mxE; apply: eq_bigr => i _. by rewrite -SE -scaler_int linearZ [b]lock !mxE. split. rewrite -[LHS]addr0 => /addrI hP; pose c := \row_i h i *m lsubmx (invmx G). exists [seq c 0 i | i : 'I_k]; congr (_ + _). have/sub_kermxP: map_mx intr (\row_i h i) *m S = 0. transitivity (\row_j coord (vbasis <<s>>) j (\sum_(i < m) s`_i *~ h i)). apply/rowP => j; rewrite !mxE linear_sum; apply: eq_bigr => i _. by rewrite -SE !mxE -scaler_int linearZ. by apply/rowP => j; rewrite !mxE -hP linear0. case/submx_trans/(_ kerS_sub_Gu)/submxP => c' /[dup]. move/(congr1 (mulmx^~ (map_mx intr (lsubmx (invmx G))))). rewrite -mulmxA -!map_mxM [in RHS]mulmx_lsub mul_usub_mx -/c mulmxV //=. rewrite scalar_mx_block -/(ulsubmx _) block_mxKul map_scalar_mx mulmx1. move=> <- {c'}; rewrite -map_mxM /= => defh; apply/ffunP => j. move/rowP/(_ j): defh; rewrite sum_ffunE !mxE => /intr_inj ->. apply: eq_bigr => i _; rewrite ffunMzE mulrzz mulrC. rewrite (nth_map i) ?size_enum_ord // nth_ord_enum ffunE. by rewrite (nth_map i) ?size_enum_ord // nth_ord_enum. case=> c /addrI -> {h}; rewrite -[LHS]addr0; congr (_ + _). pose h := \row_(j < k) c`_j *m usubmx G. transitivity (\sum_j (map_mx intr h *m S) 0 j *: (vbasis <<s>>)`_j). by rewrite map_mxM -mulmxA kerGu mulmx0 big1 // => j _; rewrite mxE scale0r. rewrite (coord_vbasis (s_Zs _)); apply: eq_bigr => i _; congr (_ *: _). rewrite linear_sum -SE mxE; apply: eq_bigr => j _. rewrite -scaler_int linearZ !mxE sum_ffunE; congr (_%:~R * _). apply: {i} eq_bigr => i _; rewrite mxE ffunMzE mulrzz mulrC. by rewrite (nth_map i) ?size_enum_ord // ffunE nth_ord_enum. Qed. Lemma dec_Qint_span (vT : vectType rat) m (s : m.-tuple vT) v : decidable (inIntSpan s v). Proof. have [[b [p aP]]|] := solve_Qint_span s v; last by right. left; exists b; apply/(aP b); exists [::]; rewrite big1 ?addr0 // => i _. by rewrite nth_nil mulr0z. Qed. Lemma eisenstein_crit (p : nat) (q : {poly int}) : prime p -> (size q != 1)%N -> ~~ (p %| lead_coef q)%Z -> ~~ (p ^+ 2 %| q`_0)%Z -> (forall i, (i < (size q).-1)%N -> p %| q`_i)%Z -> irreducible_poly q. Proof. move=> p_prime qN1 Ndvd_pql Ndvd_pq0 dvd_pq. apply/irreducible_rat_int. have qN0 : q != 0 by rewrite -lead_coef_eq0; apply: contraNneq Ndvd_pql => ->. split. rewrite size_map_poly_id0 ?intr_eq0 ?lead_coef_eq0//. by rewrite ltn_neqAle eq_sym qN1 size_poly_gt0. move=> f' +/dvdpP_rat_int[f [d dN0 feq]]; rewrite {f'}feq size_scale// => fN1. move=> /= [g q_eq]; rewrite q_eq (eqp_trans (eqp_scale _ _))//. have fN0 : f != 0 by apply: contra_neq qN0; rewrite q_eq => ->; rewrite mul0r. have gN0 : g != 0 by apply: contra_neq qN0; rewrite q_eq => ->; rewrite mulr0. rewrite size_map_poly_id0 ?intr_eq0 ?lead_coef_eq0// in fN1. have [/eqP/size_poly1P[c cN0 ->]|gN1] := eqVneq (size g) 1%N. by rewrite mulrC mul_polyC map_polyZ/= eqp_sym eqp_scale// intr_eq0. have c_neq0 : (lead_coef q)%:~R != 0 :> 'F_p by rewrite -(dvdz_pcharf (pchar_Fp _)). have : map_poly (intr : int -> 'F_p) q = (lead_coef q)%:~R *: 'X^((size q).-1). apply/val_inj/(@eq_from_nth _ 0) => [|i]; rewrite size_map_poly_id0//. by rewrite size_scale// size_polyXn -polySpred. move=> i_small; rewrite coef_poly i_small coefZ coefXn lead_coefE. move: i_small; rewrite polySpred// ltnS/=. case: ltngtP => // [i_lt|->]; rewrite (mulr1, mulr0)//= => _. by apply/eqP; rewrite -(dvdz_pcharf (pchar_Fp _))// dvd_pq. rewrite [in LHS]q_eq rmorphM/=. set c := (X in X *: _); set n := (_.-1). set pf := map_poly _ f; set pg := map_poly _ g => pfMpg. have dvdXn (r : {poly _}) : size r != 1%N -> r %| c *: 'X^n -> r`_0 = 0. move=> rN1; rewrite (eqp_dvdr _ (eqp_scale _ _))//. rewrite -['X]subr0; move=> /dvdp_exp_XsubCP[k lekn]; rewrite subr0. move=> /eqpP[u /andP[u1N0 u2N0]]; have [->|k_gt0] := posnP k. move=> /(congr1 (size \o val))/eqP. by rewrite /= !size_scale// size_polyXn (negPf rN1). move=> /(congr1 (fun p : {poly _} => p`_0))/eqP. by rewrite !coefZ coefXn [0 == _]ltn_eqF// mulr0 mulf_eq0 (negPf u1N0)=> /eqP. suff : ((p : int) ^+ 2 %| q`_0)%Z by rewrite (negPf Ndvd_pq0). have := c_neq0; rewrite q_eq coefM big_ord1. rewrite lead_coefM rmorphM mulf_eq0 negb_or => /andP[lpfN0 qfN0]. have pfN1 : size pf != 1%N by rewrite size_map_poly_id0. have pgN1 : size pg != 1%N by rewrite size_map_poly_id0. have /(dvdXn _ pgN1) /eqP : pg %| c *: 'X^n by rewrite -pfMpg dvdp_mull. have /(dvdXn _ pfN1) /eqP : pf %| c *: 'X^n by rewrite -pfMpg dvdp_mulr. by rewrite !coef_map// -!(dvdz_pcharf (pchar_Fp _))//; apply: dvdz_mul. Qed. (* Connecting rationals to the ring and field tactics *) Ltac rat_to_ring := rewrite -?[0%Q]/(0 : rat)%R -?[1%Q]/(1 : rat)%R -?[(_ - _)%Q]/(_ - _ : rat)%R -?[(_ / _)%Q]/(_ / _ : rat)%R -?[(_ + _)%Q]/(_ + _ : rat)%R -?[(_ * _)%Q]/(_ * _ : rat)%R -?[(- _)%Q]/(- _ : rat)%R -?[(_ ^-1)%Q]/(_ ^-1 : rat)%R /=. Ltac ring_to_rat := rewrite -?[0%R]/0%Q -?[1%R]/1%Q -?[(_ - _)%R]/(_ - _)%Q -?[(_ / _)%R]/(_ / _)%Q -?[(_ + _)%R]/(_ + _)%Q -?[(_ * _)%R]/(_ * _)%Q -?[(- _)%R]/(- _)%Q -?[(_ ^-1)%R]/(_ ^-1)%Q /=. (* Pretty printing or normal element of rat. *) Notation "[ 'rat' x // y ]" := (@Rat (x, y) _) (only printing) : ring_scope. (* For debugging purposes we provide the parsable version *) Notation "[ 'rat' x // y ]" := (@Rat (x : int, y : int) (fracq_subproof (x : int, y : int))) : ring_scope. (* A specialization of vm_compute rewrite rule for pattern _%:Q *) Lemma rat_vm_compute n (x : rat) : vm_compute_eq n%:Q x -> n%:Q = x. Proof. exact. Qed.
mxrepresentation.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime. From mathcomp Require Import ssralg poly polydiv finset fingroup morphism. From mathcomp Require Import perm automorphism quotient finalg action zmodp. From mathcomp Require Import commutator cyclic center pgroup matrix mxalgebra. From mathcomp Require Import mxalgebra mxpoly. (******************************************************************************) (* This file provides linkage between classic Group Theory and commutative *) (* algebra -- representation theory. Since general abstract linear algebra is *) (* still being sorted out, we develop the required theory here on the *) (* assumption that all vector spaces are matrix spaces, indeed that most are *) (* row matrix spaces; our representation theory is specialized to the latter *) (* case. We provide many definitions and results of representation theory: *) (* enveloping algebras, reducible, irreducible and absolutely irreducible *) (* representations, representation centralisers, submodules and kernels, *) (* simple and semisimple modules, the Schur lemmas, Maschke's theorem, *) (* components, socles, homomorphisms and isomorphisms, the Jacobson density *) (* theorem, similar representations, the Jordan-Holder theorem, Clifford's *) (* theorem and Wedderburn components, regular representations and the *) (* Wedderburn structure theorem for semisimple group rings, and the *) (* construction of a splitting field of an irreducible representation, and of *) (* reduced, tensored, and factored representations. *) (* mx_representation F G n == the Structure type for representations of G *) (* with n x n matrices with coefficients in F. Note that *) (* rG : mx_representation F G n coerces to a function from *) (* the element type of G to 'M_n, and conversely all such *) (* functions have a Canonical mx_representation. *) (* mx_repr G r <-> r : gT -> 'M_n defines a (matrix) group representation *) (* on G : {set gT} (Prop predicate). *) (* enveloping_algebra_mx rG == a #|G| x (n ^ 2) matrix whose rows are the *) (* mxvec encodings of the image of G under rG, and whose *) (* row space therefore encodes the enveloping algebra of *) (* the representation of G. *) (* rker rG == the kernel of the representation of r on G, i.e., the *) (* subgroup of elements of G mapped to the identity by rG. *) (* mx_faithful rG == the representation rG of G is faithful (its kernel is *) (* trivial). *) (* rfix_mx rG H == an n x n matrix whose row space is the set of vectors *) (* fixed (centralised) by the representation of H by rG. *) (* rcent rG A == the subgroup of G whose representation via rG commutes *) (* with the square matrix A. *) (* rcenter rG == the subgroup of G whose representation via rG consists of *) (* scalar matrices. *) (* centgmx rG f <=> f commutes with every matrix in the representation of G *) (* (i.e., f is a total rG-homomorphism). *) (* rstab rG U == the subgroup of G whose representation via r fixes all *) (* vectors in U, pointwise. *) (* rstabs rG U == the subgroup of G whose representation via r fixes the row *) (* space of U globally. *) (* mxmodule rG U <=> the row-space of the matrix U is a module (globally *) (* invariant) under the representation rG of G. *) (* max_submod rG U V <-> U < V and U is not a proper of any proper *) (* rG-submodule of V (if both U and V are modules, *) (* then U is a maximal proper submodule of V). *) (* mx_subseries rG Us <=> Us : seq 'M_n is a list of rG-modules *) (* mx_composition_series rG Us <-> Us is an increasing composition series *) (* for an rG-module (namely, last 0 Us). *) (* mxsimple rG M <-> M is a simple rG-module (i.e., minimal and nontrivial) *) (* This is a Prop predicate on square matrices. *) (* mxnonsimple rG U <-> U is constructively not a submodule, that is, U *) (* contains a proper nontrivial submodule. *) (* mxnonsimple_sat rG U == U is not a simple as an rG-module. *) (* This is a bool predicate, which requires a decField *) (* structure on the scalar field. *) (* mxsemisimple rG W <-> W is constructively a direct sum of simple modules. *) (* mxsplits rG V U <-> V splits over U in rG, i.e., U has an rG-invariant *) (* complement in V. *) (* mx_completely_reducible rG V <-> V splits over all its submodules; note *) (* that this is only classically equivalent to stating that *) (* V is semisimple. *) (* mx_irreducible rG <-> the representation rG is irreducible, i.e., the full *) (* module 1%:M of rG is simple. *) (* mx_absolutely_irreducible rG == the representation rG of G is absolutely *) (* irreducible: its enveloping algebra is the full matrix *) (* ring. This is only classically equivalent to the more *) (* standard ``rG does not reduce in any field extension''. *) (* group_splitting_field F G <-> F is a splitting field for the group G: *) (* every irreducible representation of G is absolutely *) (* irreducible. Any field can be embedded classically into a *) (* splitting field. *) (* group_closure_field F gT <-> F is a splitting field for every group *) (* G : {group gT}, and indeed for any section of such a *) (* group. This is a convenient constructive substitute for *) (* algebraic closures, that can be constructed classically. *) (* dom_hom_mx rG f == a square matrix encoding the set of vectors for which *) (* multiplication by the n x n matrix f commutes with the *) (* representation of G, i.e., the largest domain on which *) (* f is an rG homomorphism. *) (* mx_iso rG U V <-> U and V are (constructively) rG-isomorphic; this is *) (* a Prop predicate. *) (* mx_simple_iso rG U V == U and V are rG-isomorphic if one of them is *) (* simple; this is a bool predicate. *) (* cyclic_mx rG u == the cyclic rG-module generated by the row vector u *) (* annihilator_mx rG u == the annihilator of the row vector u in the *) (* enveloping algebra the representation rG. *) (* row_hom_mx rG u == the image of u by the set of all rG-homomorphisms on *) (* its cyclic module, or, equivalently, the null-space of the *) (* annihilator of u. *) (* component_mx rG M == when M is a simple rG-module, the component of M in *) (* the representation rG, i.e. the module generated by all *) (* the (simple) modules rG-isomorphic to M. *) (* socleType rG == a Structure that represents the type of all components *) (* of rG (more precisely, it coerces to such a type via *) (* socle_sort). For sG : socleType, values of type sG (to be *) (* exact, socle_sort sG) coerce to square matrices. For any *) (* representation rG we can construct sG : socleType rG *) (* classically; the socleType structure encapsulates this *) (* use of classical logic. *) (* DecSocleType rG == a socleType rG structure, for a representation over a *) (* decidable field type. DecSocleType rG is opaque. *) (* socle_base W == for W : (sG : socleType), a simple module whose *) (* component is W; socle_simple W and socle_module W are *) (* proofs that socle_base W is a simple module. *) (* socle_mult W == the multiplicity of socle_base W in W : sG. *) (* := \rank W %/ \rank (socle_base W) *) (* Socle sG == the Socle of rG, given sG : socleType rG, i.e., the *) (* (direct) sum of all the components of rG. *) (* mx_rsim rG rG' <-> rG and rG' are similar representations of the same *) (* group G. Note that rG and rG' must then have equal, but *) (* not necessarily convertible, degree. *) (* submod_repr modU == a representation of G on 'rV_(\rank U) equivalent to *) (* the restriction of rG to U (here modU : mxmodule rG U). *) (* socle_repr W := submod_repr (socle_module W) *) (* val/in_submod rG U == the projections resp. from/onto 'rV_(\rank U), *) (* that correspond to submod_repr r G U (these work both on *) (* vectors and row spaces). *) (* factmod_repr modV == a representation of G on 'rV_(\rank (cokermx V)) that *) (* is equivalent to the factor module 'rV_n / V induced by V *) (* and rG (here modV : mxmodule rG V). *) (* val/in_factmod rG U == the projections for factmod_repr r G U. *) (* section_repr modU modV == the restriction to in_factmod V U of the factor *) (* representation factmod_repr modV (for modU : mxmodule rG U *) (* and modV : mxmodule rG V); section_repr modU modV is *) (* irreducible iff max_submod rG U V. *) (* subseries_repr modUs i == the representation for the section module *) (* in_factmod (0 :: Us)`_i Us`_i, where *) (* modUs : mx_subseries rG Us. *) (* series_repr compUs i == the representation for the section module *) (* in_factmod (0 :: Us)`_i Us`_i, where *) (* compUs : mx_composition_series rG Us. The Jordan-Holder *) (* theorem asserts the uniqueness of the set of such *) (* representations, up to similarity and permutation. *) (* regular_repr F G == the regular F-representation of the group G. *) (* group_ring F G == a #|G| x #|G|^2 matrix that encodes the free group *) (* ring of G -- that is, the enveloping algebra of the *) (* regular F-representation of G. *) (* gring_index x == the index corresponding to x \in G in the matrix *) (* encoding of regular_repr and group_ring. *) (* gring_row A == the row vector corresponding to A \in group_ring F G in *) (* the regular FG-module. *) (* gring_proj x A == the 1 x 1 matrix holding the coefficient of x \in G in *) (* (A \in group_ring F G)%MS. *) (* gring_mx rG u == the image of a row vector u of the regular FG-module, *) (* in the enveloping algebra of another representation rG. *) (* gring_op rG A == the image of a matrix of the free group ring of G, *) (* in the enveloping algebra of rG. *) (* gset_mx F G C == the group sum of C in the free group ring of G -- the *) (* sum of the images of all the x \in C in group_ring F G. *) (* classg_base F G == a #|classes G| x #|G|^2 matrix whose rows encode the *) (* group sums of the conjugacy classes of G -- this is a *) (* basis of 'Z(group_ring F G)%MS. *) (* irrType F G == a type indexing irreducible representations of G over a *) (* field F, provided its characteristic does not divide the *) (* order of G; it also indexes Wedderburn subrings. *) (* := socleType (regular_repr F G) *) (* irr_repr i == the irreducible representation corresponding to the *) (* index i : irrType sG *) (* := socle_repr i as i coerces to a component matrix. *) (* 'n_i, irr_degree i == the degree of irr_repr i; the notation is only *) (* active after Open Scope group_ring_scope. *) (* linear_irr sG == the set of sG-indices of linear irreducible *) (* representations of G. *) (* irr_comp sG rG == the sG-index of the unique irreducible representation *) (* similar to rG, at least when rG is irreducible and the *) (* characteristic is coprime. *) (* irr_mode i z == the unique eigenvalue of irr_repr i z, at least when *) (* irr_repr i z is scalar (e.g., when z \in 'Z(G)). *) (* [1 sG]%irr == the index of the principal representation of G, in *) (* sG : irrType F G. The i argument of irr_repr, irr_degree *) (* and irr_mode is in the %irr scope. This notation may be *) (* replaced locally by an interpretation of 1%irr as [1 sG] *) (* for some specific irrType sG. *) (* 'R_i, Wedderburn_subring i == the subring (indeed, the component) of the *) (* free group ring of G corresponding to the component i : sG *) (* of the regular FG-module, where sG : irrType F g. In *) (* coprime characteristic the Wedderburn structure theorem *) (* asserts that the free group ring is the direct sum of *) (* these subrings; as with 'n_i above, the notation is only *) (* active in group_ring_scope. *) (* 'e_i, Wedderburn_id i == the projection of the identity matrix 1%:M on the *) (* Wedderburn subring of i : sG (with sG a socleType). In *) (* coprime characteristic this is the identity element of *) (* the subring, and the basis of its center if the field F is *) (* a splitting field. As 'R_i, 'e_i is in group_ring_scope. *) (* subg_repr rG sHG == the restriction to H of the representation rG of G; *) (* here sHG : H \subset G. *) (* eqg_repr rG eqHG == the representation rG of G viewed a a representation *) (* of H; here eqHG : G == H. *) (* morphpre_repr f rG == the representation of f @*^-1 G obtained by *) (* composing the group morphism f with rG. *) (* morphim_repr rGf sGD == the representation of G induced by a *) (* representation rGf of f @* G; here sGD : G \subset D where *) (* D is the domain of the group morphism f. *) (* rconj_repr rG uB == the conjugate representation x |-> B * rG x * B^-1; *) (* here uB : B \in unitmx. *) (* quo_repr sHK nHG == the representation of G / H induced by rG, given *) (* sHK : H \subset rker rG, and nHG : G \subset 'N(H). *) (* kquo_repr rG == the representation induced on G / rker rG by rG. *) (* map_repr f rG == the representation f \o rG, whose module is the tensor *) (* product of the module of rG with the extension field into *) (* which f : {rmorphism F -> Fstar} embeds F. *) (* 'Cl%act == the transitive action of G on the Wedderburn components of *) (* H, with nsGH : H <| G, given by Clifford's theorem. More *) (* precisely this is a total action of G on socle_sort sH, *) (* where sH : socleType (subg_repr rG (normal_sub sGH)). *) (* We build on the MatrixFormula toolkit to define decision procedures for *) (* the reducibility property: *) (* mxmodule_form rG U == a formula asserting that the interpretation of U is *) (* a module of the representation rG. *) (* mxnonsimple_form rG U == a formula asserting that the interpretation of U *) (* contains a proper nontrivial rG-module. *) (* mxnonsimple_sat rG U <=> mxnonsimple_form rG U is satisfied. *) (* More involved constructions are encapsulated in two Coq submodules: *) (* MatrixGenField == a module that encapsulates the lengthy details of the *) (* construction of appropriate extension fields. We assume we *) (* have an irreducible representation rG of a group G, and a *) (* non-scalar matrix A that centralises rG(G), as this data *) (* is readily extracted from the Jacobson density theorem. It *) (* then follows from Schur's lemma that the ring generated by *) (* A is a field on which the extension of the representation *) (* rG of G is reducible. Note that this is equivalent to the *) (* more traditional quotient of the polynomial ring by an *) (* irreducible polynomial (the minimal polynomial of A), but *) (* much better suited to our needs. *) (* Here are the main definitions of MatrixGenField; they all have three *) (* proofs as arguments: (implicit) rG : mx_repr n G, irrG : mx_irreducible rG *) (* and cGA : centgmx rG A. These ensure the validity of the construction and *) (* allow us to define Canonical instances; we assume degree_mxminpoly A > 1 *) (* (which is equivalent to ~~ is_scalar_mx A) only to prove reducibility. *) (* + gen_of irrG cGA == the carrier type of the field generated by A. It is *) (* at least equipped with a fieldType structure; we also *) (* propagate any decFieldType/finFieldType structures on the *) (* original field. *) (* + gen irrG cGA == the morphism injecting into gen_of irrG cGA. *) (* + groot irrG cGA == the root of mxminpoly A in the gen_of irrG cGA field. *) (* + pval x, rVval x, mxval x == the interpretation of x : gen_of irrG cGA *) (* as a polynomial, a row vector, and a matrix, respectively. *) (* Both irrG and cGA are implicit arguments here. *) (* + gen_repr irrG cGA == an alternative to the field extension *) (* representation, which consists in reconsidering the *) (* original module as a module over the new gen_of field, *) (* thereby DIVIDING the original dimension n by the degree of *) (* the minimal polynomial of A. This can be simpler than the *) (* extension method, is actually required by the proof that *) (* odd groups are p-stable (B & G 6.1-2, and Appendix A), but *) (* is only applicable if G is the LARGEST group represented *) (* by rG (e.g., NOT for B & G 2.6). *) (* + gen_dim A == the dimension of gen_repr irrG cGA (only depends on A). *) (* + in_gen irrG cGA W == the ROWWISE image of a matrix W : 'M[F]_(m, n), *) (* i.e., interpreting W as a sequence of m tow vectors, *) (* under the bijection from rG to gen_repr irrG cGA. *) (* The sequence length m is a maximal implicit argument *) (* passed between the explicit argument cGA and W. *) (* + val_gen W == the ROWWISE image of an 'M[gen_of irrG cGA]_(m, gen_dim A) *) (* matrix W under the bijection from gen_repr irrG cGA to rG. *) (* + rowval_gen W == the ROWSPACE image of W under the bijection from *) (* gen_repr irrG cGA to rG, i.e., a 'M[F]_n matrix whose row *) (* space is the image of the row space of W. *) (* This is the A-ideal generated by val_gen W. *) (* + gen_sat e f <=> f : GRing.formula (gen_of irrG cGA) is satisfied in *) (* environment e : seq (gen_of irrG cGA), provided F has a *) (* decFieldType structure. *) (* + gen_env e, gen_term t, gen_form f == interpretations of environments, *) (* terms, and RING formulas over gen_of irrG cGA as row *) (* vector formulae, used to construct gen_sat. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope irrType_scope. Declare Scope group_ring_scope. Import GroupScope GRing.Theory. Local Open Scope ring_scope. Reserved Notation "''n_' i" (at level 8, i at level 2, format "''n_' i"). Reserved Notation "''R_' i" (at level 8, i at level 2, format "''R_' i"). Reserved Notation "''e_' i" (at level 8, i at level 2, format "''e_' i"). Delimit Scope irrType_scope with irr. Section RingRepr. Variable R : comUnitRingType. Section OneRepresentation. Variable gT : finGroupType. Definition mx_repr (G : {set gT}) n (r : gT -> 'M[R]_n) := r 1%g = 1%:M /\ {in G &, {morph r : x y / (x * y)%g >-> x *m y}}. Structure mx_representation G n := MxRepresentation { repr_mx :> gT -> 'M_n; _ : mx_repr G repr_mx }. Variables (G : {group gT}) (n : nat) (rG : mx_representation G n). Arguments rG _%_group_scope : extra scopes. Lemma repr_mx1 : rG 1 = 1%:M. Proof. by case: rG => r []. Qed. Lemma repr_mxM : {in G &, {morph rG : x y / (x * y)%g >-> x *m y}}. Proof. by case: rG => r []. Qed. Lemma repr_mxK m x : x \in G -> cancel ((@mulmx R m n n)^~ (rG x)) (mulmx^~ (rG x^-1)). Proof. by move=> Gx U; rewrite -mulmxA -repr_mxM ?groupV // mulgV repr_mx1 mulmx1. Qed. Lemma repr_mxKV m x : x \in G -> cancel ((@mulmx R m n n)^~ (rG x^-1)) (mulmx^~ (rG x)). Proof. by rewrite -groupV -{3}[x]invgK; apply: repr_mxK. Qed. Lemma repr_mx_unit x : x \in G -> rG x \in unitmx. Proof. by move=> Gx; case/mulmx1_unit: (repr_mxKV Gx 1%:M). Qed. Lemma repr_mxV : {in G, {morph rG : x / x^-1%g >-> invmx x}}. Proof. by move=> x Gx /=; rewrite -[rG x^-1](mulKmx (repr_mx_unit Gx)) mulmxA repr_mxK. Qed. (* This is only used in the group ring construction below, as we only have *) (* developped the theory of matrix subalgebras for F-algebras. *) Definition enveloping_algebra_mx := \matrix_(i < #|G|) mxvec (rG (enum_val i)). Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Definition rstab := [set x in G | U *m rG x == U]. Lemma rstab_sub : rstab \subset G. Proof. by apply/subsetP=> x; case/setIdP. Qed. Lemma rstab_group_set : group_set rstab. Proof. apply/group_setP; rewrite inE group1 repr_mx1 mulmx1; split=> //= x y. case/setIdP=> Gx cUx; case/setIdP=> Gy cUy; rewrite inE repr_mxM ?groupM //. by rewrite mulmxA (eqP cUx). Qed. Canonical rstab_group := Group rstab_group_set. End Stabiliser. (* Centralizer subgroup and central homomorphisms. *) Section CentHom. Variable f : 'M[R]_n. Definition rcent := [set x in G | f *m rG x == rG x *m f]. Lemma rcent_sub : rcent \subset G. Proof. by apply/subsetP=> x; case/setIdP. Qed. Lemma rcent_group_set : group_set rcent. Proof. apply/group_setP; rewrite inE group1 repr_mx1 mulmx1 mul1mx; split=> //= x y. case/setIdP=> Gx; move/eqP=> cfx; case/setIdP=> Gy; move/eqP=> cfy. by rewrite inE repr_mxM ?groupM //= -mulmxA -cfy !mulmxA cfx. Qed. Canonical rcent_group := Group rcent_group_set. Definition centgmx := G \subset rcent. Lemma centgmxP : reflect (forall x, x \in G -> f *m rG x = rG x *m f) centgmx. Proof. by apply: (iffP subsetP) => cGf x Gx; have /[!(inE, Gx)] /eqP := cGf x Gx. Qed. End CentHom. (* Representation kernel, and faithful representations. *) Definition rker := rstab 1%:M. Canonical rker_group := Eval hnf in [group of rker]. Lemma rkerP x : reflect (x \in G /\ rG x = 1%:M) (x \in rker). Proof. by apply: (iffP setIdP) => [] [->]; move/eqP; rewrite mul1mx. Qed. Lemma rker_norm : G \subset 'N(rker). Proof. apply/subsetP=> x Gx; rewrite inE sub_conjg; apply/subsetP=> y. case/rkerP=> Gy ry1; rewrite mem_conjgV !inE groupJ //=. by rewrite !repr_mxM ?groupM ?groupV // ry1 !mulmxA mulmx1 repr_mxKV. Qed. Lemma rker_normal : rker <| G. Proof. by rewrite /normal rstab_sub rker_norm. Qed. Definition mx_faithful := rker \subset [1]. Lemma mx_faithful_inj : mx_faithful -> {in G &, injective rG}. Proof. move=> ffulG x y Gx Gy eq_rGxy; apply/eqP; rewrite eq_mulgV1 -in_set1. rewrite (subsetP ffulG) // inE groupM ?repr_mxM ?groupV //= eq_rGxy. by rewrite mulmxA repr_mxK. Qed. Lemma rker_linear : n = 1 -> G^`(1)%g \subset rker. Proof. move=> n1; rewrite gen_subG; apply/subsetP=> xy; case/imset2P=> x y Gx Gy ->. rewrite !inE groupR //= /commg mulgA -invMg repr_mxM ?groupV ?groupM //. rewrite mulmxA (can2_eq (repr_mxK _) (repr_mxKV _)) ?groupM //. rewrite !repr_mxV ?repr_mxM ?groupM //; move: (rG x) (rG y). by rewrite n1 => rx ry; rewrite (mx11_scalar rx) scalar_mxC. Qed. (* Representation center. *) Definition rcenter := [set g in G | is_scalar_mx (rG g)]. Fact rcenter_group_set : group_set rcenter. Proof. apply/group_setP; split=> [|x y]. by rewrite inE group1 repr_mx1 scalar_mx_is_scalar. move=> /setIdP[Gx /is_scalar_mxP[a defx]] /setIdP[Gy /is_scalar_mxP[b defy]]. by rewrite !inE groupM ?repr_mxM // defx defy -scalar_mxM ?scalar_mx_is_scalar. Qed. Canonical rcenter_group := Group rcenter_group_set. Lemma rcenter_normal : rcenter <| G. Proof. rewrite /normal /rcenter {1}setIdE subsetIl; apply/subsetP=> x Gx /[1!inE]. apply/subsetP=> _ /imsetP[y /setIdP[Gy /is_scalar_mxP[c rGy]] ->]. rewrite inE !repr_mxM ?groupM ?groupV //= mulmxA rGy scalar_mxC repr_mxKV //. exact: scalar_mx_is_scalar. Qed. End OneRepresentation. Arguments rkerP {gT G n rG x}. Section Proper. Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variable rG : mx_representation G n. Lemma repr_mxMr : {in G &, {morph rG : x y / (x * y)%g >-> x * y}}. Proof. exact: repr_mxM. Qed. Lemma repr_mxVr : {in G, {morph rG : x / (x^-1)%g >-> x^-1}}. Proof. exact: repr_mxV. Qed. Lemma repr_mx_unitr x : x \in G -> rG x \is a GRing.unit. Proof. exact: repr_mx_unit. Qed. Lemma repr_mxX m : {in G, {morph rG : x / (x ^+ m)%g >-> x ^+ m}}. Proof. elim: m => [|m IHm] x Gx; rewrite /= ?repr_mx1 // expgS exprS -IHm //. by rewrite repr_mxM ?groupX. Qed. End Proper. Section ChangeGroup. Variables (gT : finGroupType) (G H : {group gT}) (n : nat). Variables (rG : mx_representation G n). Section SubGroup. Hypothesis sHG : H \subset G. Lemma subg_mx_repr : mx_repr H rG. Proof. by split=> [|x y Hx Hy]; rewrite (repr_mx1, repr_mxM) ?(subsetP sHG). Qed. Definition subg_repr := MxRepresentation subg_mx_repr. Local Notation rH := subg_repr. Lemma rcent_subg U : rcent rH U = H :&: rcent rG U. Proof. by apply/setP=> x; rewrite !inE andbA -in_setI (setIidPl sHG). Qed. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_subg : rstab rH U = H :&: rstab rG U. Proof. by apply/setP=> x; rewrite !inE andbA -in_setI (setIidPl sHG). Qed. End Stabiliser. Lemma rker_subg : rker rH = H :&: rker rG. Proof. exact: rstab_subg. Qed. Lemma subg_mx_faithful : mx_faithful rG -> mx_faithful rH. Proof. by apply: subset_trans; rewrite rker_subg subsetIr. Qed. End SubGroup. Section SameGroup. Hypothesis eqGH : G :==: H. Lemma eqg_repr_proof : H \subset G. Proof. by rewrite (eqP eqGH). Qed. Definition eqg_repr := subg_repr eqg_repr_proof. Local Notation rH := eqg_repr. Lemma rcent_eqg U : rcent rH U = rcent rG U. Proof. by rewrite rcent_subg -(eqP eqGH) (setIidPr _) ?rcent_sub. Qed. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_eqg : rstab rH U = rstab rG U. Proof. by rewrite rstab_subg -(eqP eqGH) (setIidPr _) ?rstab_sub. Qed. End Stabiliser. Lemma rker_eqg : rker rH = rker rG. Proof. exact: rstab_eqg. Qed. Lemma eqg_mx_faithful : mx_faithful rH = mx_faithful rG. Proof. by rewrite /mx_faithful rker_eqg. Qed. End SameGroup. End ChangeGroup. Section Morphpre. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Variables (G : {group rT}) (n : nat) (rG : mx_representation G n). Lemma morphpre_mx_repr : mx_repr (f @*^-1 G) (rG \o f). Proof. split=> [|x y]; first by rewrite /= morph1 repr_mx1. case/morphpreP=> Dx Gfx; case/morphpreP=> Dy Gfy. by rewrite /= morphM ?repr_mxM. Qed. Canonical morphpre_repr := MxRepresentation morphpre_mx_repr. Local Notation rGf := morphpre_repr. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_morphpre : rstab rGf U = f @*^-1 (rstab rG U). Proof. by apply/setP=> x; rewrite !inE andbA. Qed. End Stabiliser. Lemma rker_morphpre : rker rGf = f @*^-1 (rker rG). Proof. exact: rstab_morphpre. Qed. End Morphpre. Section Morphim. Variables (aT rT : finGroupType) (G D : {group aT}) (f : {morphism D >-> rT}). Variables (n : nat) (rGf : mx_representation (f @* G) n). Definition morphim_mx of G \subset D := fun x => rGf (f x). Hypothesis sGD : G \subset D. Lemma morphim_mxE x : morphim_mx sGD x = rGf (f x). Proof. by []. Qed. Let sG_f'fG : G \subset f @*^-1 (f @* G). Proof. by rewrite -sub_morphim_pre. Qed. Lemma morphim_mx_repr : mx_repr G (morphim_mx sGD). Proof. exact: subg_mx_repr (morphpre_repr f rGf) sG_f'fG. Qed. Canonical morphim_repr := MxRepresentation morphim_mx_repr. Local Notation rG := morphim_repr. Section Stabiliser. Variables (m : nat) (U : 'M[R]_(m, n)). Lemma rstab_morphim : rstab rG U = G :&: f @*^-1 rstab rGf U. Proof. by rewrite -rstab_morphpre -(rstab_subg _ sG_f'fG). Qed. End Stabiliser. Lemma rker_morphim : rker rG = G :&: f @*^-1 (rker rGf). Proof. exact: rstab_morphim. Qed. End Morphim. Section Conjugate. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation G n) (B : 'M[R]_n). Definition rconj_mx of B \in unitmx := fun x => B *m rG x *m invmx B. Hypothesis uB : B \in unitmx. Lemma rconj_mx_repr : mx_repr G (rconj_mx uB). Proof. split=> [|x y Gx Gy]; rewrite /rconj_mx ?repr_mx1 ?mulmx1 ?mulmxV ?repr_mxM //. by rewrite !mulmxA mulmxKV. Qed. Canonical rconj_repr := MxRepresentation rconj_mx_repr. Local Notation rGB := rconj_repr. Lemma rconj_mxE x : rGB x = B *m rG x *m invmx B. Proof. by []. Qed. Lemma rconj_mxJ m (W : 'M_(m, n)) x : W *m rGB x *m B = W *m B *m rG x. Proof. by rewrite !mulmxA mulmxKV. Qed. Lemma rcent_conj A : rcent rGB A = rcent rG (invmx B *m A *m B). Proof. apply/setP=> x; rewrite !inE /= rconj_mxE !mulmxA. rewrite (can2_eq (mulmxKV uB) (mulmxK uB)) -!mulmxA. by rewrite -(can2_eq (mulKVmx uB) (mulKmx uB)). Qed. Lemma rstab_conj m (U : 'M_(m, n)) : rstab rGB U = rstab rG (U *m B). Proof. apply/setP=> x; rewrite !inE /= rconj_mxE !mulmxA. by rewrite (can2_eq (mulmxKV uB) (mulmxK uB)). Qed. Lemma rker_conj : rker rGB = rker rG. Proof. apply/setP=> x; rewrite !inE /= mulmxA (can2_eq (mulmxKV uB) (mulmxK uB)). by rewrite mul1mx -scalar_mxC (inj_eq (can_inj (mulKmx uB))) mul1mx. Qed. Lemma conj_mx_faithful : mx_faithful rGB = mx_faithful rG. Proof. by rewrite /mx_faithful rker_conj. Qed. End Conjugate. Section Quotient. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation G n. Definition quo_mx (H : {set gT}) of H \subset rker rG & G \subset 'N(H) := fun Hx : coset_of H => rG (repr Hx). Section SubQuotient. Variable H : {group gT}. Hypotheses (krH : H \subset rker rG) (nHG : G \subset 'N(H)). Let nHGs := subsetP nHG. Lemma quo_mx_coset x : x \in G -> quo_mx krH nHG (coset H x) = rG x. Proof. move=> Gx; rewrite /quo_mx val_coset ?nHGs //; case: repr_rcosetP => z Hz. by case/rkerP: (subsetP krH z Hz) => Gz rz1; rewrite repr_mxM // rz1 mul1mx. Qed. Lemma quo_mx_repr : mx_repr (G / H)%g (quo_mx krH nHG). Proof. split=> [|Hx Hy]; first by rewrite /quo_mx repr_coset1 repr_mx1. case/morphimP=> x Nx Gx ->{Hx}; case/morphimP=> y Ny Gy ->{Hy}. by rewrite -morphM // !quo_mx_coset ?groupM ?repr_mxM. Qed. Canonical quo_repr := MxRepresentation quo_mx_repr. Local Notation rGH := quo_repr. Lemma quo_repr_coset x : x \in G -> rGH (coset H x) = rG x. Proof. exact: quo_mx_coset. Qed. Lemma rcent_quo A : rcent rGH A = (rcent rG A / H)%g. Proof. apply/setP=> Hx /[!inE]; apply/andP/idP=> [[]|]; case/morphimP=> x Nx Gx ->{Hx}. by rewrite quo_repr_coset // => cAx; rewrite mem_morphim // inE Gx. by case/setIdP: Gx => Gx cAx; rewrite quo_repr_coset ?mem_morphim. Qed. Lemma rstab_quo m (U : 'M_(m, n)) : rstab rGH U = (rstab rG U / H)%g. Proof. apply/setP=> Hx /[!inE]; apply/andP/idP=> [[]|]; case/morphimP=> x Nx Gx ->{Hx}. by rewrite quo_repr_coset // => nUx; rewrite mem_morphim // inE Gx. by case/setIdP: Gx => Gx nUx; rewrite quo_repr_coset ?mem_morphim. Qed. Lemma rker_quo : rker rGH = (rker rG / H)%g. Proof. exact: rstab_quo. Qed. End SubQuotient. Definition kquo_mx := quo_mx (subxx (rker rG)) (rker_norm rG). Lemma kquo_mxE : kquo_mx = quo_mx (subxx (rker rG)) (rker_norm rG). Proof. by []. Qed. Canonical kquo_repr := @MxRepresentation _ _ _ kquo_mx (quo_mx_repr _ _). Lemma kquo_repr_coset x : x \in G -> kquo_repr (coset (rker rG) x) = rG x. Proof. exact: quo_repr_coset. Qed. Lemma kquo_mx_faithful : mx_faithful kquo_repr. Proof. by rewrite /mx_faithful rker_quo trivg_quotient. Qed. End Quotient. Section Regular. Variables (gT : finGroupType) (G : {group gT}). Definition gcard := #|G|. (* hides the projections to set *) Local Notation nG := gcard. Definition gring_index (x : gT) := enum_rank_in (group1 G) x. Lemma gring_valK : cancel enum_val gring_index. Proof. exact: enum_valK_in. Qed. Lemma gring_indexK : {in G, cancel gring_index enum_val}. Proof. exact: enum_rankK_in. Qed. Definition regular_mx x : 'M[R]_nG := \matrix_i delta_mx 0 (gring_index (enum_val i * x)). Lemma regular_mx_repr : mx_repr G regular_mx. Proof. split=> [|x y Gx Gy]; apply/row_matrixP=> i; rewrite !rowK. by rewrite mulg1 row1 gring_valK. by rewrite row_mul rowK -rowE rowK mulgA gring_indexK // groupM ?enum_valP. Qed. Canonical regular_repr := MxRepresentation regular_mx_repr. Local Notation aG := regular_repr. Definition group_ring := enveloping_algebra_mx aG. Local Notation R_G := group_ring. Definition gring_row : 'M[R]_nG -> 'rV_nG := row (gring_index 1). HB.instance Definition _ := GRing.Linear.on gring_row. Lemma gring_row_mul A B : gring_row (A *m B) = gring_row A *m B. Proof. exact: row_mul. Qed. Definition gring_proj x := row (gring_index x) \o trmx \o gring_row. HB.instance Definition _ x := GRing.Linear.on (gring_proj x). Lemma gring_projE : {in G &, forall x y, gring_proj x (aG y) = (x == y)%:R}. Proof. move=> x y Gx Gy; rewrite /gring_proj /= /gring_row rowK gring_indexK //=. rewrite mul1g trmx_delta rowE mul_delta_mx_cond [delta_mx 0 0]mx11_scalar !mxE. by rewrite /= -(inj_eq (can_inj gring_valK)) !gring_indexK. Qed. Lemma regular_mx_faithful : mx_faithful aG. Proof. apply/subsetP=> x /setIdP[Gx]. rewrite mul1mx inE => /eqP/(congr1 (gring_proj 1%g)). rewrite -(repr_mx1 aG) !gring_projE ?group1 // eqxx eq_sym. by case: (x == _) => // /eqP; rewrite eq_sym oner_eq0. Qed. Section GringMx. Variables (n : nat) (rG : mx_representation G n). Definition gring_mx := vec_mx \o mulmxr (enveloping_algebra_mx rG). HB.instance Definition _ := GRing.Linear.on gring_mx. Lemma gring_mxJ a x : x \in G -> gring_mx (a *m aG x) = gring_mx a *m rG x. Proof. move=> Gx; rewrite /gring_mx /= ![a *m _]mulmx_sum_row. rewrite !(mulmx_suml, linear_sum); apply: eq_bigr => i _. rewrite linearZ -!scalemxAl linearZ /=; congr (_ *: _) => {a}. rewrite !rowK /= !mxvecK -rowE rowK mxvecK. by rewrite gring_indexK ?groupM ?repr_mxM ?enum_valP. Qed. End GringMx. Lemma gring_mxK : cancel (gring_mx aG) gring_row. Proof. move=> a; rewrite /gring_mx /= mulmx_sum_row !linear_sum /= [RHS]row_sum_delta. apply: eq_bigr => i _; rewrite 2!linearZ /= /gring_row !(rowK, mxvecK). by rewrite gring_indexK // mul1g gring_valK. Qed. Section GringOp. Variables (n : nat) (rG : mx_representation G n). Definition gring_op := gring_mx rG \o gring_row. HB.instance Definition _ := GRing.Linear.on gring_op. Lemma gring_opE a : gring_op a = gring_mx rG (gring_row a). Proof. by []. Qed. Lemma gring_opG x : x \in G -> gring_op (aG x) = rG x. Proof. move=> Gx; rewrite gring_opE /gring_row rowK gring_indexK // mul1g. by rewrite /gring_mx /= -rowE rowK mxvecK gring_indexK. Qed. Lemma gring_op1 : gring_op 1%:M = 1%:M. Proof. by rewrite -(repr_mx1 aG) gring_opG ?repr_mx1. Qed. Lemma gring_opJ A b : gring_op (A *m gring_mx aG b) = gring_op A *m gring_mx rG b. Proof. rewrite /gring_mx /= ![b *m _]mulmx_sum_row !linear_sum. apply: eq_bigr => i _; rewrite !linearZ /= !rowK !mxvecK. by rewrite gring_opE gring_row_mul gring_mxJ ?enum_valP. Qed. Lemma gring_op_mx b : gring_op (gring_mx aG b) = gring_mx rG b. Proof. by rewrite -[_ b]mul1mx gring_opJ gring_op1 mul1mx. Qed. Lemma gring_mxA a b : gring_mx rG (a *m gring_mx aG b) = gring_mx rG a *m gring_mx rG b. Proof. by rewrite -(gring_op_mx a) -gring_opJ gring_opE gring_row_mul gring_mxK. Qed. End GringOp. End Regular. End RingRepr. Arguments mx_representation R {gT} G%_g n%_N. Arguments mx_repr {R gT} G%_g {n%_N} r. Arguments group_ring R {gT} G%_g. Arguments regular_repr R {gT} G%_g. Arguments centgmxP {R gT G n rG f}. Arguments rkerP {R gT G n rG x}. Arguments repr_mxK {R gT G%_G n%_N} rG {m%_N} [x%_g] Gx. Arguments repr_mxKV {R gT G%_G n%_N} rG {m%_N} [x%_g] Gx. Arguments gring_valK {gT G%_G} i%_R : rename. Arguments gring_indexK {gT G%_G} x%_g. Arguments gring_mxK {R gT G%_G} v%_R : rename. Section ChangeOfRing. Variables (aR rR : comUnitRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx (GRing.RMorphism.sort f) A) : ring_scope. Variables (gT : finGroupType) (G : {group gT}). Lemma map_regular_mx x : (regular_mx aR G x)^f = regular_mx rR G x. Proof. by apply/matrixP=> i j; rewrite !mxE rmorph_nat. Qed. Lemma map_gring_row (A : 'M_#|G|) : (gring_row A)^f = gring_row A^f. Proof. by rewrite map_row. Qed. Lemma map_gring_proj x (A : 'M_#|G|) : (gring_proj x A)^f = gring_proj x A^f. Proof. by rewrite map_row -map_trmx map_gring_row. Qed. Section OneRepresentation. Variables (n : nat) (rG : mx_representation aR G n). Definition map_repr_mx (f0 : aR -> rR) rG0 (g : gT) : 'M_n := map_mx f0 (rG0 g). Lemma map_mx_repr : mx_repr G (map_repr_mx f rG). Proof. split=> [|x y Gx Gy]; first by rewrite /map_repr_mx repr_mx1 map_mx1. by rewrite -map_mxM -repr_mxM. Qed. Canonical map_repr := MxRepresentation map_mx_repr. Local Notation rGf := map_repr. Lemma map_reprE x : rGf x = (rG x)^f. Proof. by []. Qed. Lemma map_reprJ m (A : 'M_(m, n)) x : (A *m rG x)^f = A^f *m rGf x. Proof. exact: map_mxM. Qed. Lemma map_enveloping_algebra_mx : (enveloping_algebra_mx rG)^f = enveloping_algebra_mx rGf. Proof. by apply/row_matrixP=> i; rewrite -map_row !rowK map_mxvec. Qed. Lemma map_gring_mx a : (gring_mx rG a)^f = gring_mx rGf a^f. Proof. by rewrite map_vec_mx map_mxM map_enveloping_algebra_mx. Qed. Lemma map_gring_op A : (gring_op rG A)^f = gring_op rGf A^f. Proof. by rewrite map_gring_mx map_gring_row. Qed. End OneRepresentation. Lemma map_regular_repr : map_repr (regular_repr aR G) =1 regular_repr rR G. Proof. exact: map_regular_mx. Qed. Lemma map_group_ring : (group_ring aR G)^f = group_ring rR G. Proof. rewrite map_enveloping_algebra_mx; apply/row_matrixP=> i. by rewrite !rowK map_regular_repr. Qed. (* Stabilisers, etc, are only mapped properly for fields. *) End ChangeOfRing. Section FieldRepr. Variable F : fieldType. Section OneRepresentation. Variable gT : finGroupType. Variables (G : {group gT}) (n : nat) (rG : mx_representation F G n). Arguments rG _%_group_scope : extra scopes. Local Notation E_G := (enveloping_algebra_mx rG). Lemma repr_mx_free x : x \in G -> row_free (rG x). Proof. by move=> Gx; rewrite row_free_unit repr_mx_unit. Qed. Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Definition rstabs := [set x in G | U *m rG x <= U]%MS. Lemma rstabs_sub : rstabs \subset G. Proof. by apply/subsetP=> x /setIdP[]. Qed. Lemma rstabs_group_set : group_set rstabs. Proof. apply/group_setP; rewrite inE group1 repr_mx1 mulmx1. split=> //= x y /setIdP[Gx nUx] /setIdP[Gy]; rewrite inE repr_mxM ?groupM //. by apply: submx_trans; rewrite mulmxA submxMr. Qed. Canonical rstabs_group := Group rstabs_group_set. Lemma rstab_act x m1 (W : 'M_(m1, n)) : x \in rstab rG U -> (W <= U)%MS -> W *m rG x = W. Proof. by case/setIdP=> _ /eqP cUx /submxP[w ->]; rewrite -mulmxA cUx. Qed. Lemma rstabs_act x m1 (W : 'M_(m1, n)) : x \in rstabs -> (W <= U)%MS -> (W *m rG x <= U)%MS. Proof. by case/setIdP=> [_ nUx] sWU; apply: submx_trans nUx; apply: submxMr. Qed. Definition mxmodule := G \subset rstabs. Lemma mxmoduleP : reflect {in G, forall x, U *m rG x <= U}%MS mxmodule. Proof. by apply: (iffP subsetP) => modU x Gx; have:= modU x Gx; rewrite !inE ?Gx. Qed. End Stabilisers. Arguments mxmoduleP {m U}. Lemma rstabS m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U <= V)%MS -> rstab rG V \subset rstab rG U. Proof. case/submxP=> u ->; apply/subsetP=> x. by rewrite !inE => /andP[-> /= /eqP cVx]; rewrite -mulmxA cVx. Qed. Lemma eqmx_rstab m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U :=: V)%MS -> rstab rG U = rstab rG V. Proof. by move=> eqUV; apply/eqP; rewrite eqEsubset !rstabS ?eqUV. Qed. Lemma eqmx_rstabs m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U :=: V)%MS -> rstabs U = rstabs V. Proof. by move=> eqUV; apply/setP=> x; rewrite !inE eqUV (eqmxMr _ eqUV). Qed. Lemma eqmx_module m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U :=: V)%MS -> mxmodule U = mxmodule V. Proof. by move=> eqUV; rewrite /mxmodule (eqmx_rstabs eqUV). Qed. Lemma mxmodule0 m : mxmodule (0 : 'M_(m, n)). Proof. by apply/mxmoduleP=> x _; rewrite mul0mx. Qed. Lemma mxmodule1 : mxmodule 1%:M. Proof. by apply/mxmoduleP=> x _; rewrite submx1. Qed. Lemma mxmodule_trans m1 m2 (U : 'M_(m1, n)) (W : 'M_(m2, n)) x : mxmodule U -> x \in G -> (W <= U -> W *m rG x <= U)%MS. Proof. by move=> modU Gx sWU; apply: submx_trans (mxmoduleP modU x Gx); apply: submxMr. Qed. Lemma mxmodule_eigenvector m (U : 'M_(m, n)) : mxmodule U -> \rank U = 1 -> {u : 'rV_n & {a | (U :=: u)%MS & {in G, forall x, u *m rG x = a x *: u}}}. Proof. move=> modU linU; set u := nz_row U; exists u. have defU: (U :=: u)%MS. apply/eqmxP; rewrite andbC -(geq_leqif (mxrank_leqif_eq _)) ?nz_row_sub //. by rewrite linU lt0n mxrank_eq0 nz_row_eq0 -mxrank_eq0 linU. pose a x := (u *m rG x *m pinvmx u) 0 0; exists a => // x Gx. by rewrite -mul_scalar_mx -mx11_scalar mulmxKpV // -defU mxmodule_trans ?defU. Qed. Lemma addsmx_module m1 m2 U V : @mxmodule m1 U -> @mxmodule m2 V -> mxmodule (U + V)%MS. Proof. move=> modU modV; apply/mxmoduleP=> x Gx. by rewrite addsmxMr addsmxS ?(mxmoduleP _ x Gx). Qed. Lemma sumsmx_module I r (P : pred I) U : (forall i, P i -> mxmodule (U i)) -> mxmodule (\sum_(i <- r | P i) U i)%MS. Proof. by move=> modU; elim/big_ind: _; [apply: mxmodule0 | apply: addsmx_module | ]. Qed. Lemma capmx_module m1 m2 U V : @mxmodule m1 U -> @mxmodule m2 V -> mxmodule (U :&: V)%MS. Proof. move=> modU modV; apply/mxmoduleP=> x Gx. by rewrite sub_capmx !mxmodule_trans ?capmxSl ?capmxSr. Qed. Lemma bigcapmx_module I r (P : pred I) U : (forall i, P i -> mxmodule (U i)) -> mxmodule (\bigcap_(i <- r | P i) U i)%MS. Proof. by move=> modU; elim/big_ind: _; [apply: mxmodule1 | apply: capmx_module | ]. Qed. (* Sub- and factor representations induced by a (sub)module. *) Section Submodule. Variable U : 'M[F]_n. Definition val_submod m : 'M_(m, \rank U) -> 'M_(m, n) := mulmxr (row_base U). Definition in_submod m : 'M_(m, n) -> 'M_(m, \rank U) := mulmxr (invmx (row_ebase U) *m pid_mx (\rank U)). HB.instance Definition _ m := GRing.Linear.on (@val_submod m). HB.instance Definition _ m := GRing.Linear.on (@in_submod m). Lemma val_submodE m W : @val_submod m W = W *m val_submod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma in_submodE m W : @in_submod m W = W *m in_submod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma val_submod1 : (val_submod 1%:M :=: U)%MS. Proof. by rewrite /val_submod /= mul1mx; apply: eq_row_base. Qed. Lemma val_submodP m W : (@val_submod m W <= U)%MS. Proof. by rewrite mulmx_sub ?eq_row_base. Qed. Lemma val_submodK m : cancel (@val_submod m) (@in_submod m). Proof. move=> W; rewrite /in_submod /= -!mulmxA mulKVmx ?row_ebase_unit //. by rewrite pid_mx_id ?rank_leq_row // pid_mx_1 mulmx1. Qed. Lemma val_submod_inj m : injective (@val_submod m). Proof. exact: can_inj (@val_submodK m). Qed. Lemma val_submodS m1 m2 (V : 'M_(m1, \rank U)) (W : 'M_(m2, \rank U)) : (val_submod V <= val_submod W)%MS = (V <= W)%MS. Proof. apply/idP/idP=> sVW; last exact: submxMr. by rewrite -[V]val_submodK -[W]val_submodK submxMr. Qed. Lemma in_submodK m W : (W <= U)%MS -> val_submod (@in_submod m W) = W. Proof. case/submxP=> w ->; rewrite /val_submod /= -!mulmxA. congr (_ *m _); rewrite -{1}[U]mulmx_ebase !mulmxA mulmxK ?row_ebase_unit //. by rewrite -2!(mulmxA (col_ebase U)) !pid_mx_id ?rank_leq_row // mulmx_ebase. Qed. Lemma val_submod_eq0 m W : (@val_submod m W == 0) = (W == 0). Proof. by rewrite -!submx0 -val_submodS linear0 !(submx0, eqmx0). Qed. Lemma in_submod_eq0 m W : (@in_submod m W == 0) = (W <= U^C)%MS. Proof. apply/eqP/submxP=> [W_U0 | [w ->{W}]]. exists (W *m invmx (row_ebase U)). rewrite mulmxA mulmxBr mulmx1 -(pid_mx_id _ _ _ (leqnn _)). rewrite mulmxA -(mulmxA W) [W *m (_ *m _)]W_U0 mul0mx subr0. by rewrite mulmxKV ?row_ebase_unit. rewrite /in_submod /= -!mulmxA mulKVmx ?row_ebase_unit //. by rewrite mul_copid_mx_pid ?rank_leq_row ?mulmx0. Qed. Lemma mxrank_in_submod m (W : 'M_(m, n)) : (W <= U)%MS -> \rank (in_submod W) = \rank W. Proof. by move=> sWU; apply/eqP; rewrite eqn_leq -{3}(in_submodK sWU) !mxrankM_maxl. Qed. Definition val_factmod m : _ -> 'M_(m, n) := mulmxr (row_base (cokermx U) *m row_ebase U). Definition in_factmod m : 'M_(m, n) -> _ := mulmxr (col_base (cokermx U)). HB.instance Definition _ m := GRing.Linear.on (@val_factmod m). HB.instance Definition _ m := GRing.Linear.on (@in_factmod m). Lemma val_factmodE m W : @val_factmod m W = W *m val_factmod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma in_factmodE m W : @in_factmod m W = W *m in_factmod 1%:M. Proof. by rewrite mulmxA mulmx1. Qed. Lemma val_factmodP m W : (@val_factmod m W <= U^C)%MS. Proof. by rewrite mulmx_sub {m W}// (eqmxMr _ (eq_row_base _)) -mulmxA submxMl. Qed. Lemma val_factmodK m : cancel (@val_factmod m) (@in_factmod m). Proof. move=> W /=; rewrite /in_factmod /=; set Uc := cokermx U. apply: (row_free_inj (row_base_free Uc)); rewrite -mulmxA mulmx_base. rewrite /val_factmod /= 2!mulmxA -/Uc mulmxK ?row_ebase_unit //. have /submxP[u ->]: (row_base Uc <= Uc)%MS by rewrite eq_row_base. by rewrite -!mulmxA copid_mx_id ?rank_leq_row. Qed. Lemma val_factmod_inj m : injective (@val_factmod m). Proof. exact: can_inj (@val_factmodK m). Qed. Lemma val_factmodS m1 m2 (V : 'M_(m1, _)) (W : 'M_(m2, _)) : (val_factmod V <= val_factmod W)%MS = (V <= W)%MS. Proof. apply/idP/idP=> sVW; last exact: submxMr. by rewrite -[V]val_factmodK -[W]val_factmodK submxMr. Qed. Lemma val_factmod_eq0 m W : (@val_factmod m W == 0) = (W == 0). Proof. by rewrite -!submx0 -val_factmodS linear0 !(submx0, eqmx0). Qed. Lemma in_factmod_eq0 m (W : 'M_(m, n)) : (in_factmod W == 0) = (W <= U)%MS. Proof. rewrite submxE -!mxrank_eq0 -{2}[_ U]mulmx_base mulmxA. by rewrite (mxrankMfree _ (row_base_free _)). Qed. Lemma in_factmodK m (W : 'M_(m, n)) : (W <= U^C)%MS -> val_factmod (in_factmod W) = W. Proof. case/submxP=> w ->{W}; rewrite /val_factmod /= -2!mulmxA. congr (_ *m _); rewrite (mulmxA (col_base _)) mulmx_base -2!mulmxA. by rewrite mulKVmx ?row_ebase_unit // mulmxA copid_mx_id ?rank_leq_row. Qed. Lemma in_factmod_addsK m (W : 'M_(m, n)) : (in_factmod (U + W)%MS :=: in_factmod W)%MS. Proof. apply: eqmx_trans (addsmxMr _ _ _) _. by rewrite ((_ *m _ =P 0) _) ?in_factmod_eq0 //; apply: adds0mx. Qed. Lemma add_sub_fact_mod m (W : 'M_(m, n)) : val_submod (in_submod W) + val_factmod (in_factmod W) = W. Proof. rewrite /val_submod /val_factmod /= -!mulmxA -mulmxDr. rewrite addrC ![in X in X + _](mulmxA (pid_mx _)) pid_mx_id //. rewrite (mulmxA (col_ebase _)) (mulmxA _ _ (row_ebase _)) mulmx_ebase. rewrite (mulmxA (pid_mx _)) pid_mx_id // mulmxA -mulmxDl -mulmxDr. by rewrite subrK mulmx1 mulmxA mulmxKV ?row_ebase_unit. Qed. Lemma proj_factmodS m (W : 'M_(m, n)) : (val_factmod (in_factmod W) <= U + W)%MS. Proof. by rewrite -{2}[W]add_sub_fact_mod addsmx_addKl ?val_submodP ?addsmxSr. Qed. Lemma in_factmodsK m (W : 'M_(m, n)) : (U <= W)%MS -> (U + val_factmod (in_factmod W) :=: W)%MS. Proof. move/addsmx_idPr; apply: eqmx_trans (eqmx_sym _). by rewrite -{1}[W]add_sub_fact_mod; apply: addsmx_addKl; apply: val_submodP. Qed. Lemma mxrank_in_factmod m (W : 'M_(m, n)) : (\rank (in_factmod W) + \rank U)%N = \rank (U + W). Proof. rewrite -in_factmod_addsK in_factmodE; set fU := in_factmod 1%:M. suffices <-: ((U + W) :&: kermx fU :=: U)%MS by rewrite mxrank_mul_ker. apply: eqmx_trans (capmx_idPr (addsmxSl U W)). apply: cap_eqmx => //; apply/eqmxP/rV_eqP => u. by rewrite (sameP sub_kermxP eqP) -in_factmodE in_factmod_eq0. Qed. Definition submod_mx of mxmodule U := fun x => in_submod (val_submod 1%:M *m rG x). Definition factmod_mx of mxmodule U := fun x => in_factmod (val_factmod 1%:M *m rG x). Hypothesis Umod : mxmodule U. Lemma in_submodJ m (W : 'M_(m, n)) x : (W <= U)%MS -> in_submod (W *m rG x) = in_submod W *m submod_mx Umod x. Proof. move=> sWU; rewrite mulmxA; congr (in_submod _). by rewrite mulmxA -val_submodE in_submodK. Qed. Lemma val_submodJ m (W : 'M_(m, \rank U)) x : x \in G -> val_submod (W *m submod_mx Umod x) = val_submod W *m rG x. Proof. move=> Gx; rewrite 2!(mulmxA W) -val_submodE in_submodK //. by rewrite mxmodule_trans ?val_submodP. Qed. Lemma submod_mx_repr : mx_repr G (submod_mx Umod). Proof. rewrite /submod_mx; split=> [|x y Gx Gy /=]. by rewrite repr_mx1 mulmx1 val_submodK. rewrite -in_submodJ; first by rewrite repr_mxM ?mulmxA. by rewrite mxmodule_trans ?val_submodP. Qed. Canonical submod_repr := MxRepresentation submod_mx_repr. Lemma in_factmodJ m (W : 'M_(m, n)) x : x \in G -> in_factmod (W *m rG x) = in_factmod W *m factmod_mx Umod x. Proof. move=> Gx; rewrite -{1}[W]add_sub_fact_mod mulmxDl linearD /=. apply: (canLR (subrK _)); apply: etrans (_ : 0 = _). apply/eqP; rewrite in_factmod_eq0 (submx_trans _ (mxmoduleP Umod x Gx)) //. by rewrite submxMr ?val_submodP. by rewrite /in_factmod /val_factmod /= !mulmxA mulmx1 ?subrr. Qed. Lemma val_factmodJ m (W : 'M_(m, \rank (cokermx U))) x : x \in G -> val_factmod (W *m factmod_mx Umod x) = val_factmod (in_factmod (val_factmod W *m rG x)). Proof. by move=> Gx; rewrite -{1}[W]val_factmodK -in_factmodJ. Qed. Lemma factmod_mx_repr : mx_repr G (factmod_mx Umod). Proof. split=> [|x y Gx Gy /=]. by rewrite /factmod_mx repr_mx1 mulmx1 val_factmodK. by rewrite -in_factmodJ // -mulmxA -repr_mxM. Qed. Canonical factmod_repr := MxRepresentation factmod_mx_repr. (* For character theory. *) Lemma mxtrace_sub_fact_mod x : \tr (submod_repr x) + \tr (factmod_repr x) = \tr (rG x). Proof. rewrite -[submod_repr x]mulmxA mxtrace_mulC -val_submodE addrC. rewrite -[factmod_repr x]mulmxA mxtrace_mulC -val_factmodE addrC. by rewrite -mxtraceD add_sub_fact_mod. Qed. End Submodule. (* Properties of enveloping algebra as a subspace of 'rV_(n ^ 2). *) Lemma envelop_mx_id x : x \in G -> (rG x \in E_G)%MS. Proof. by move=> Gx; rewrite (eq_row_sub (enum_rank_in Gx x)) // rowK enum_rankK_in. Qed. Lemma envelop_mx1 : (1%:M \in E_G)%MS. Proof. by rewrite -(repr_mx1 rG) envelop_mx_id. Qed. Lemma envelop_mxP A : reflect (exists a, A = \sum_(x in G) a x *: rG x) (A \in E_G)%MS. Proof. have G_1 := group1 G; have bijG := enum_val_bij_in G_1. set h := enum_val in bijG; have Gh: h _ \in G by apply: enum_valP. apply: (iffP submxP) => [[u defA] | [a ->]]. exists (fun x => u 0 (enum_rank_in G_1 x)); apply: (can_inj mxvecK). rewrite defA mulmx_sum_row linear_sum (reindex h) //=. by apply: eq_big => [i | i _]; rewrite ?Gh // rowK linearZ enum_valK_in. exists (\row_i a (h i)); rewrite mulmx_sum_row linear_sum (reindex h) //=. by apply: eq_big => [i | i _]; rewrite ?Gh // mxE rowK linearZ. Qed. Lemma envelop_mxM A B : (A \in E_G -> B \in E_G -> A *m B \in E_G)%MS. Proof. move=> {A B} /envelop_mxP[a ->] /envelop_mxP[b ->]. rewrite mulmx_suml !linear_sum summx_sub //= => x Gx. rewrite !linear_sum summx_sub //= => y Gy. rewrite -scalemxAl 3!linearZ !scalemx_sub//= -repr_mxM //. by rewrite envelop_mx_id ?groupM. Qed. Lemma mxmodule_envelop m1 m2 (U : 'M_(m1, n)) (W : 'M_(m2, n)) A : (mxmodule U -> mxvec A <= E_G -> W <= U -> W *m A <= U)%MS. Proof. move=> modU /envelop_mxP[a ->] sWU; rewrite linear_sum summx_sub //= => x Gx. by rewrite -scalemxAr scalemx_sub ?mxmodule_trans. Qed. (* Module homomorphisms; any square matrix f defines a module homomorphism *) (* over some domain, namely, dom_hom_mx f. *) Definition dom_hom_mx f : 'M_n := kermx (lin1_mx (mxvec \o mulmx (cent_mx_fun E_G f) \o lin_mul_row)). Lemma hom_mxP m f (W : 'M_(m, n)) : reflect (forall x, x \in G -> W *m rG x *m f = W *m f *m rG x) (W <= dom_hom_mx f)%MS. Proof. apply: (iffP row_subP) => [cGf x Gx | cGf i]. apply/row_matrixP=> i; apply/eqP; rewrite -subr_eq0 -!mulmxA -!linearB /=. have:= sub_kermxP (cGf i); rewrite mul_rV_lin1 /=. move/(canRL mxvecK)/row_matrixP/(_ (enum_rank_in Gx x))/eqP; rewrite !linear0. by rewrite !row_mul rowK mul_vec_lin /= mul_vec_lin_row enum_rankK_in. apply/sub_kermxP; rewrite mul_rV_lin1 /=; apply: (canLR vec_mxK). apply/row_matrixP=> j; rewrite !row_mul rowK mul_vec_lin /= mul_vec_lin_row. by rewrite -!row_mul mulmxBr !mulmxA cGf ?enum_valP // subrr !linear0. Qed. Arguments hom_mxP {m f W}. Lemma hom_envelop_mxC m f (W : 'M_(m, n)) A : (W <= dom_hom_mx f -> A \in E_G -> W *m A *m f = W *m f *m A)%MS. Proof. move/hom_mxP=> cWfG /envelop_mxP[a ->]; rewrite !linear_sum mulmx_suml. by apply: eq_bigr => x Gx /=; rewrite -2!scalemxAr -scalemxAl cWfG. Qed. Lemma dom_hom_invmx f : f \in unitmx -> (dom_hom_mx (invmx f) :=: dom_hom_mx f *m f)%MS. Proof. move=> injf; set U := dom_hom_mx _; apply/eqmxP. rewrite -{1}[U](mulmxKV injf) submxMr; apply/hom_mxP=> x Gx. by rewrite -[_ *m rG x](hom_mxP _) ?mulmxK. by rewrite -[_ *m rG x](hom_mxP _) ?mulmxKV. Qed. Lemma dom_hom_mx_module f : mxmodule (dom_hom_mx f). Proof. apply/mxmoduleP=> x Gx; apply/hom_mxP=> y Gy. rewrite -[_ *m rG y]mulmxA -repr_mxM // 2?(hom_mxP _) ?groupM //. by rewrite repr_mxM ?mulmxA. Qed. Lemma hom_mxmodule m (U : 'M_(m, n)) f : (U <= dom_hom_mx f)%MS -> mxmodule U -> mxmodule (U *m f). Proof. move/hom_mxP=> cGfU modU; apply/mxmoduleP=> x Gx. by rewrite -cGfU // submxMr // (mxmoduleP modU). Qed. Lemma kermx_hom_module m (U : 'M_(m, n)) f : (U <= dom_hom_mx f)%MS -> mxmodule U -> mxmodule (U :&: kermx f)%MS. Proof. move=> homUf modU; apply/mxmoduleP=> x Gx. rewrite sub_capmx mxmodule_trans ?capmxSl //=. apply/sub_kermxP; rewrite (hom_mxP _) ?(submx_trans (capmxSl _ _)) //. by rewrite (sub_kermxP (capmxSr _ _)) mul0mx. Qed. Lemma scalar_mx_hom a m (U : 'M_(m, n)) : (U <= dom_hom_mx a%:M)%MS. Proof. by apply/hom_mxP=> x Gx; rewrite -!mulmxA scalar_mxC. Qed. Lemma proj_mx_hom (U V : 'M_n) : (U :&: V = 0)%MS -> mxmodule U -> mxmodule V -> (U + V <= dom_hom_mx (proj_mx U V))%MS. Proof. move=> dxUV modU modV; apply/hom_mxP=> x Gx. rewrite -{1}(add_proj_mx dxUV (submx_refl _)) !mulmxDl addrC. rewrite {1}[_ *m _]proj_mx_0 ?add0r //; last first. by rewrite mxmodule_trans ?proj_mx_sub. by rewrite [_ *m _](proj_mx_id dxUV) // mxmodule_trans ?proj_mx_sub. Qed. (* The subspace fixed by a subgroup H of G; it is a module if H <| G. *) (* The definition below is extensionally equivalent to the straightforward *) (* \bigcap_(x in H) kermx (rG x - 1%:M) *) (* but it avoids the dependency on the choice function; this allows it to *) (* commute with ring morphisms. *) Definition rfix_mx (H : {set gT}) := let commrH := \matrix_(i < #|H|) mxvec (rG (enum_val i) - 1%:M) in kermx (lin1_mx (mxvec \o mulmx commrH \o lin_mul_row)). Lemma rfix_mxP m (W : 'M_(m, n)) (H : {set gT}) : reflect (forall x, x \in H -> W *m rG x = W) (W <= rfix_mx H)%MS. Proof. rewrite /rfix_mx; set C := \matrix_i _. apply: (iffP row_subP) => [cHW x Hx | cHW j]. apply/row_matrixP=> j; apply/eqP; rewrite -subr_eq0 row_mul. move/sub_kermxP: {cHW}(cHW j); rewrite mul_rV_lin1 /=; move/(canRL mxvecK). move/row_matrixP/(_ (enum_rank_in Hx x)); rewrite row_mul rowK !linear0. by rewrite enum_rankK_in // mul_vec_lin_row mulmxBr mulmx1 => ->. apply/sub_kermxP; rewrite mul_rV_lin1 /=; apply: (canLR vec_mxK). apply/row_matrixP=> i; rewrite row_mul rowK mul_vec_lin_row -row_mul. by rewrite mulmxBr mulmx1 cHW ?enum_valP // subrr !linear0. Qed. Arguments rfix_mxP {m W}. Lemma rfix_mx_id (H : {set gT}) x : x \in H -> rfix_mx H *m rG x = rfix_mx H. Proof. exact/rfix_mxP. Qed. Lemma rfix_mxS (H K : {set gT}) : H \subset K -> (rfix_mx K <= rfix_mx H)%MS. Proof. by move=> sHK; apply/rfix_mxP=> x Hx; apply: rfix_mxP (subsetP sHK x Hx). Qed. Lemma rfix_mx_conjsg (H : {set gT}) x : x \in G -> H \subset G -> (rfix_mx (H :^ x) :=: rfix_mx H *m rG x)%MS. Proof. move=> Gx sHG; pose rf y := rfix_mx (H :^ y). suffices{x Gx} IH: {in G &, forall y z, rf y *m rG z <= rf (y * z)%g}%MS. apply/eqmxP; rewrite -/(rf x) -[H]conjsg1 -/(rf 1%g). rewrite -{4}[x] mul1g -{1}[rf x](repr_mxKV rG Gx) -{1}(mulgV x). by rewrite submxMr IH ?groupV. move=> x y Gx Gy; apply/rfix_mxP=> zxy; rewrite actM => /imsetP[zx Hzx ->]. have Gzx: zx \in G by apply: subsetP Hzx; rewrite conj_subG. rewrite -mulmxA -repr_mxM ?groupM ?groupV // -conjgC repr_mxM // mulmxA. by rewrite rfix_mx_id. Qed. Lemma norm_sub_rstabs_rfix_mx (H : {set gT}) : H \subset G -> 'N_G(H) \subset rstabs (rfix_mx H). Proof. move=> sHG; apply/subsetP=> x /setIP[Gx nHx]; rewrite inE Gx. apply/rfix_mxP=> y Hy; have Gy := subsetP sHG y Hy. have Hyx: (y ^ x^-1)%g \in H by rewrite memJ_norm ?groupV. rewrite -mulmxA -repr_mxM // conjgCV repr_mxM ?(subsetP sHG _ Hyx) // mulmxA. by rewrite (rfix_mx_id Hyx). Qed. Lemma normal_rfix_mx_module H : H <| G -> mxmodule (rfix_mx H). Proof. case/andP=> sHG nHG. by rewrite /mxmodule -{1}(setIidPl nHG) norm_sub_rstabs_rfix_mx. Qed. Lemma rfix_mx_module : mxmodule (rfix_mx G). Proof. exact: normal_rfix_mx_module. Qed. Lemma rfix_mx_rstabC (H : {set gT}) m (U : 'M[F]_(m, n)) : H \subset G -> (H \subset rstab rG U) = (U <= rfix_mx H)%MS. Proof. move=> sHG; apply/subsetP/rfix_mxP=> cHU x Hx. by rewrite (rstab_act (cHU x Hx)). by rewrite !inE (subsetP sHG) //= cHU. Qed. (* The cyclic module generated by a single vector. *) Definition cyclic_mx u := <<E_G *m lin_mul_row u>>%MS. Lemma cyclic_mxP u v : reflect (exists2 A, A \in E_G & v = u *m A)%MS (v <= cyclic_mx u)%MS. Proof. rewrite genmxE; apply: (iffP submxP) => [[a] | [A /submxP[a defA]]] -> {v}. exists (vec_mx (a *m E_G)); last by rewrite mulmxA mul_rV_lin1. by rewrite vec_mxK submxMl. by exists a; rewrite mulmxA mul_rV_lin1 /= -defA mxvecK. Qed. Arguments cyclic_mxP {u v}. Lemma cyclic_mx_id u : (u <= cyclic_mx u)%MS. Proof. by apply/cyclic_mxP; exists 1%:M; rewrite ?mulmx1 ?envelop_mx1. Qed. Lemma cyclic_mx_eq0 u : (cyclic_mx u == 0) = (u == 0). Proof. rewrite -!submx0; apply/idP/idP. by apply: submx_trans; apply: cyclic_mx_id. move/submx0null->; rewrite genmxE; apply/row_subP=> i. by rewrite row_mul mul_rV_lin1 /= mul0mx ?sub0mx. Qed. Lemma cyclic_mx_module u : mxmodule (cyclic_mx u). Proof. apply/mxmoduleP=> x Gx; apply/row_subP=> i; rewrite row_mul. have [A E_A ->{i}] := @cyclic_mxP u _ (row_sub i _); rewrite -mulmxA. by apply/cyclic_mxP; exists (A *m rG x); rewrite ?envelop_mxM ?envelop_mx_id. Qed. Lemma cyclic_mx_sub m u (W : 'M_(m, n)) : mxmodule W -> (u <= W)%MS -> (cyclic_mx u <= W)%MS. Proof. move=> modU Wu; rewrite genmxE; apply/row_subP=> i. by rewrite row_mul mul_rV_lin1 /= mxmodule_envelop // vec_mxK row_sub. Qed. Lemma hom_cyclic_mx u f : (u <= dom_hom_mx f)%MS -> (cyclic_mx u *m f :=: cyclic_mx (u *m f))%MS. Proof. move=> domf_u; apply/eqmxP; rewrite !(eqmxMr _ (genmxE _)). apply/genmxP; rewrite genmx_id; congr <<_>>%MS; apply/row_matrixP=> i. by rewrite !row_mul !mul_rV_lin1 /= hom_envelop_mxC // vec_mxK row_sub. Qed. (* The annihilator of a single vector. *) Definition annihilator_mx u := (E_G :&: kermx (lin_mul_row u))%MS. Lemma annihilator_mxP u A : reflect (A \in E_G /\ u *m A = 0)%MS (A \in annihilator_mx u)%MS. Proof. rewrite sub_capmx; apply: (iffP andP) => [[-> /sub_kermxP]|[-> uA0]]. by rewrite mul_rV_lin1 /= mxvecK. by split=> //; apply/sub_kermxP; rewrite mul_rV_lin1 /= mxvecK. Qed. (* The subspace of homomorphic images of a row vector. *) Definition row_hom_mx u := (\bigcap_j kermx (vec_mx (row j (annihilator_mx u))))%MS. Lemma row_hom_mxP u v : reflect (exists2 f, u <= dom_hom_mx f & u *m f = v)%MS (v <= row_hom_mx u)%MS. Proof. apply: (iffP sub_bigcapmxP) => [iso_uv | [f hom_uf <-] i _]. have{iso_uv} uv0 A: (A \in E_G)%MS /\ u *m A = 0 -> v *m A = 0. move/annihilator_mxP=> /submxP[a defA]. rewrite -[A]mxvecK {A}defA [a *m _]mulmx_sum_row !linear_sum big1 // => i _. by rewrite !linearZ /= (sub_kermxP _) ?scaler0 ?iso_uv. pose U := E_G *m lin_mul_row u; pose V := E_G *m lin_mul_row v. pose f := pinvmx U *m V. have hom_uv_f x: x \in G -> u *m rG x *m f = v *m rG x. move=> Gx; apply/eqP; rewrite 2!mulmxA mul_rV_lin1 -subr_eq0 -mulmxBr /=. rewrite uv0 // linearB /= mulmxBr vec_mxK; split. (* FIXME: slow *) by rewrite addmx_sub ?submxMl // eqmx_opp envelop_mx_id. have Uux: (u *m rG x <= U)%MS. by rewrite -(genmxE U) mxmodule_trans ?cyclic_mx_id ?cyclic_mx_module. by rewrite -{2}(mulmxKpV Uux) [_ *m U]mulmxA mul_rV_lin1 subrr. have def_uf: u *m f = v. by rewrite -[u]mulmx1 -[v]mulmx1 -(repr_mx1 rG) hom_uv_f. by exists f => //; apply/hom_mxP=> x Gx; rewrite def_uf hom_uv_f. apply/sub_kermxP; set A := vec_mx _. have: (A \in annihilator_mx u)%MS by rewrite vec_mxK row_sub. by case/annihilator_mxP => E_A uA0; rewrite -hom_envelop_mxC // uA0 mul0mx. Qed. (* Sub-, isomorphic, simple, semisimple and completely reducible modules. *) (* All these predicates are intuitionistic (since, e.g., testing simplicity *) (* requires a splitting algorithm fo r the mas field). They are all *) (* specialized to square matrices, to avoid spurious height parameters. *) (* Module isomorphism is an intentional property in general, but it can be *) (* decided when one of the two modules is known to be simple. *) Variant mx_iso (U V : 'M_n) : Prop := MxIso f of f \in unitmx & (U <= dom_hom_mx f)%MS & (U *m f :=: V)%MS. Lemma eqmx_iso U V : (U :=: V)%MS -> mx_iso U V. Proof. by move=> eqUV; exists 1%:M; rewrite ?unitmx1 ?scalar_mx_hom ?mulmx1. Qed. Lemma mx_iso_refl U : mx_iso U U. Proof. exact: eqmx_iso. Qed. Lemma mx_iso_sym U V : mx_iso U V -> mx_iso V U. Proof. case=> f injf homUf defV; exists (invmx f); first by rewrite unitmx_inv. by rewrite dom_hom_invmx // -defV submxMr. by rewrite -[U](mulmxK injf); apply: eqmxMr (eqmx_sym _). Qed. Lemma mx_iso_trans U V W : mx_iso U V -> mx_iso V W -> mx_iso U W. Proof. case=> f injf homUf defV [g injg homVg defW]. exists (f *m g); first by rewrite unitmx_mul injf. by apply/hom_mxP=> x Gx; rewrite !mulmxA 2?(hom_mxP _) ?defV. by rewrite mulmxA; apply: eqmx_trans (eqmxMr g defV) defW. Qed. Lemma mxrank_iso U V : mx_iso U V -> \rank U = \rank V. Proof. by case=> f injf _ <-; rewrite mxrankMfree ?row_free_unit. Qed. Lemma mx_iso_module U V : mx_iso U V -> mxmodule U -> mxmodule V. Proof. by case=> f _ homUf defV; rewrite -(eqmx_module defV); apply: hom_mxmodule. Qed. (* Simple modules (we reserve the term "irreducible" for representations). *) Definition mxsimple (V : 'M_n) := [/\ mxmodule V, V != 0 & forall U : 'M_n, mxmodule U -> (U <= V)%MS -> U != 0 -> (V <= U)%MS]. Definition mxnonsimple (U : 'M_n) := exists V : 'M_n, [&& mxmodule V, (V <= U)%MS, V != 0 & \rank V < \rank U]. Lemma mxsimpleP U : [/\ mxmodule U, U != 0 & ~ mxnonsimple U] <-> mxsimple U. Proof. do [split => [] [modU nzU simU]; split] => // [V modV sVU nzV | [V]]. apply/idPn; rewrite -(ltn_leqif (mxrank_leqif_sup sVU)) => ltVU. by case: simU; exists V; apply/and4P. by case/and4P=> modV sVU nzV; apply/negP; rewrite -leqNgt mxrankS ?simU. Qed. Lemma mxsimple_module U : mxsimple U -> mxmodule U. Proof. by case. Qed. Lemma mxsimple_exists m (U : 'M_(m, n)) : mxmodule U -> U != 0 -> classically (exists2 V, mxsimple V & V <= U)%MS. Proof. move=> modU nzU [] // simU; move: {2}_.+1 (ltnSn (\rank U)) => r leUr. elim: r => // r IHr in m U leUr modU nzU simU. have genU := genmxE U; apply: (simU); exists <<U>>%MS; last by rewrite genU. apply/mxsimpleP; split; rewrite ?(eqmx_eq0 genU) ?(eqmx_module genU) //. case=> V; rewrite !genU=> /and4P[modV sVU nzV ltVU]; case: notF. apply: IHr nzV _ => // [|[W simW sWV]]; first exact: leq_trans ltVU _. by apply: simU; exists W => //; apply: submx_trans sWV sVU. Qed. Lemma mx_iso_simple U V : mx_iso U V -> mxsimple U -> mxsimple V. Proof. move=> isoUV [modU nzU simU]; have [f injf homUf defV] := isoUV. split=> [||W modW sWV nzW]; first by rewrite (mx_iso_module isoUV). by rewrite -(eqmx_eq0 defV) -(mul0mx n f) (can_eq (mulmxK injf)). rewrite -defV -[W](mulmxKV injf) submxMr //; set W' := W *m _. have sW'U: (W' <= U)%MS by rewrite -[U](mulmxK injf) submxMr ?defV. rewrite (simU W') //; last by rewrite -(can_eq (mulmxK injf)) mul0mx mulmxKV. rewrite hom_mxmodule ?dom_hom_invmx // -[W](mulmxKV injf) submxMr //. exact: submx_trans sW'U homUf. Qed. Lemma mxsimple_cyclic u U : mxsimple U -> u != 0 -> (u <= U)%MS -> (U :=: cyclic_mx u)%MS. Proof. case=> [modU _ simU] nz_u Uu; apply/eqmxP; set uG := cyclic_mx u. have s_uG_U: (uG <= U)%MS by rewrite cyclic_mx_sub. by rewrite simU ?cyclic_mx_eq0 ?submx_refl // cyclic_mx_module. Qed. (* The surjective part of Schur's lemma. *) Lemma mx_Schur_onto m (U : 'M_(m, n)) V f : mxmodule U -> mxsimple V -> (U <= dom_hom_mx f)%MS -> (U *m f <= V)%MS -> U *m f != 0 -> (U *m f :=: V)%MS. Proof. move=> modU [modV _ simV] homUf sUfV nzUf. apply/eqmxP; rewrite sUfV -(genmxE (U *m f)). rewrite simV ?(eqmx_eq0 (genmxE _)) ?genmxE //. by rewrite (eqmx_module (genmxE _)) hom_mxmodule. Qed. (* The injective part of Schur's lemma. *) Lemma mx_Schur_inj U f : mxsimple U -> (U <= dom_hom_mx f)%MS -> U *m f != 0 -> (U :&: kermx f)%MS = 0. Proof. case=> [modU _ simU] homUf nzUf; apply/eqP; apply: contraR nzUf => nz_ker. rewrite (sameP eqP sub_kermxP) (sameP capmx_idPl eqmxP) simU ?capmxSl //. exact: kermx_hom_module. Qed. (* The injectve part of Schur's lemma, stated as isomorphism with the image. *) Lemma mx_Schur_inj_iso U f : mxsimple U -> (U <= dom_hom_mx f)%MS -> U *m f != 0 -> mx_iso U (U *m f). Proof. move=> simU homUf nzUf; have [modU _ _] := simU. have eqUfU: \rank (U *m f) = \rank U by apply/mxrank_injP; rewrite mx_Schur_inj. have{eqUfU} [g invg defUf] := complete_unitmx eqUfU. suffices homUg: (U <= dom_hom_mx g)%MS by exists g; rewrite ?defUf. apply/hom_mxP=> x Gx; have [ux defUx] := submxP (mxmoduleP modU x Gx). by rewrite -defUf -(hom_mxP homUf) // defUx -!(mulmxA ux) defUf. Qed. (* The isomorphism part of Schur's lemma. *) Lemma mx_Schur_iso U V f : mxsimple U -> mxsimple V -> (U <= dom_hom_mx f)%MS -> (U *m f <= V)%MS -> U *m f != 0 -> mx_iso U V. Proof. move=> simU simV homUf sUfV nzUf; have [modU _ _] := simU. have [g invg homUg defUg] := mx_Schur_inj_iso simU homUf nzUf. exists g => //; apply: mx_Schur_onto; rewrite ?defUg //. by rewrite -!submx0 defUg in nzUf *. Qed. (* A boolean test for module isomorphism that is only valid for simple *) (* modules; this is the only case that matters in practice. *) Lemma nz_row_mxsimple U : mxsimple U -> nz_row U != 0. Proof. by case=> _ nzU _; rewrite nz_row_eq0. Qed. Definition mxsimple_iso (U V : 'M_n) := [&& mxmodule V, (V :&: row_hom_mx (nz_row U))%MS != 0 & \rank V <= \rank U]. Lemma mxsimple_isoP U V : mxsimple U -> reflect (mx_iso U V) (mxsimple_iso U V). Proof. move=> simU; pose u := nz_row U. have [Uu nz_u]: (u <= U)%MS /\ u != 0 by rewrite nz_row_sub nz_row_mxsimple. apply: (iffP and3P) => [[modV] | isoUV]; last first. split; last by rewrite (mxrank_iso isoUV). by case: (mx_iso_simple isoUV simU). have [f injf homUf defV] := isoUV; apply/rowV0Pn; exists (u *m f). rewrite sub_capmx -defV submxMr //. by apply/row_hom_mxP; exists f; first apply: (submx_trans Uu). by rewrite -(mul0mx _ f) (can_eq (mulmxK injf)) nz_u. case/rowV0Pn=> v; rewrite sub_capmx => /andP[Vv]. case/row_hom_mxP => f homMf def_v nz_v eqrUV. pose uG := cyclic_mx u; pose vG := cyclic_mx v. have def_vG: (uG *m f :=: vG)%MS by rewrite /vG -def_v; apply: hom_cyclic_mx. have defU: (U :=: uG)%MS by apply: mxsimple_cyclic. have mod_uG: mxmodule uG by rewrite cyclic_mx_module. have homUf: (U <= dom_hom_mx f)%MS. by rewrite defU cyclic_mx_sub ?dom_hom_mx_module. have isoUf: mx_iso U (U *m f). apply: mx_Schur_inj_iso => //; apply: contra nz_v; rewrite -!submx0. by rewrite (eqmxMr f defU) def_vG; apply: submx_trans (cyclic_mx_id v). apply: mx_iso_trans (isoUf) (eqmx_iso _); apply/eqmxP. have sUfV: (U *m f <= V)%MS by rewrite (eqmxMr f defU) def_vG cyclic_mx_sub. by rewrite -mxrank_leqif_eq ?eqn_leq 1?mxrankS // -(mxrank_iso isoUf). Qed. Lemma mxsimple_iso_simple U V : mxsimple_iso U V -> mxsimple U -> mxsimple V. Proof. by move=> isoUV simU; apply: mx_iso_simple (simU); apply/mxsimple_isoP. Qed. (* For us, "semisimple" means "sum of simple modules"; this is classically, *) (* but not intuitionistically, equivalent to the "completely reducible" *) (* alternate characterization. *) Implicit Type I : finType. Variant mxsemisimple (V : 'M_n) := MxSemisimple I U (W := (\sum_(i : I) U i)%MS) of forall i, mxsimple (U i) & (W :=: V)%MS & mxdirect W. (* This is a slight generalization of Aschbacher 12.5 for finite sets. *) Lemma sum_mxsimple_direct_compl m I W (U : 'M_(m, n)) : let V := (\sum_(i : I) W i)%MS in (forall i : I, mxsimple (W i)) -> mxmodule U -> (U <= V)%MS -> {J : {set I} | let S := U + \sum_(i in J) W i in S :=: V /\ mxdirect S}%MS. Proof. move=> V simW modU sUV; pose V_ (J : {set I}) := (\sum_(i in J) W i)%MS. pose dxU (J : {set I}) := mxdirect (U + V_ J). have [J maxJ]: {J | maxset dxU J}; last case/maxsetP: maxJ => dxUVJ maxJ. apply: ex_maxset; exists set0. by rewrite /dxU mxdirectE /V_ /= !big_set0 addn0 addsmx0 /=. have modWJ: mxmodule (V_ J) by apply: sumsmx_module => i _; case: (simW i). exists J; split=> //; apply/eqmxP; rewrite addsmx_sub sUV; apply/andP; split. by apply/sumsmx_subP=> i Ji; rewrite (sumsmx_sup i). rewrite -/(V_ J); apply/sumsmx_subP=> i _. case Ji: (i \in J). by apply: submx_trans (addsmxSr _ _); apply: (sumsmx_sup i). have [modWi nzWi simWi] := simW i. rewrite (sameP capmx_idPl eqmxP) simWi ?capmxSl ?capmx_module ?addsmx_module //. apply: contraFT (Ji); rewrite negbK => dxWiUVJ. rewrite -(maxJ (i |: J)) ?setU11 ?subsetUr // /dxU. rewrite mxdirectE /= !big_setU1 ?Ji //=. rewrite addnCA addsmxA (addsmxC U) -addsmxA -mxdirectE /=. by rewrite mxdirect_addsE /= mxdirect_trivial -/(dxU _) dxUVJ. Qed. Lemma sum_mxsimple_direct_sub I W (V : 'M_n) : (forall i : I, mxsimple (W i)) -> (\sum_i W i :=: V)%MS -> {J : {set I} | let S := \sum_(i in J) W i in S :=: V /\ mxdirect S}%MS. Proof. move=> simW defV. have [|J [defS dxS]] := sum_mxsimple_direct_compl simW (mxmodule0 n). exact: sub0mx. exists J; split; last by rewrite mxdirectE /= adds0mx mxrank0 in dxS. by apply: eqmx_trans defV; rewrite adds0mx_id in defS. Qed. Lemma mxsemisimple0 : mxsemisimple 0. Proof. exists 'I_0 (fun _ => 0); [by case | by rewrite big_ord0 | ]. by rewrite mxdirectE /= !big_ord0 mxrank0. Qed. Lemma intro_mxsemisimple (I : Type) r (P : pred I) W V : (\sum_(i <- r | P i) W i :=: V)%MS -> (forall i, P i -> W i != 0 -> mxsimple (W i)) -> mxsemisimple V. Proof. move=> defV simW; pose W_0 := [pred i | W i == 0]. have [-> | nzV] := eqVneq V 0; first exact: mxsemisimple0. case def_r: r => [| i0 r'] => [|{r' def_r}]. by rewrite -mxrank_eq0 -defV def_r big_nil mxrank0 in nzV. move: defV; rewrite (bigID W_0) /= addsmxC -big_filter !(big_nth i0) !big_mkord. rewrite addsmxC big1 ?adds0mx_id => [|i /andP[_ /eqP] //]. set tI := 'I_(_); set r_ := nth _ _ => defV. have{simW} simWr (i : tI) : mxsimple (W (r_ i)). case: i => m /=; set Pr := fun i => _ => lt_m_r /=. suffices: (Pr (r_ m)) by case/andP; apply: simW. apply: all_nthP m lt_m_r; apply/all_filterP. by rewrite -filter_predI; apply: eq_filter => i; rewrite /= andbb. have [J []] := sum_mxsimple_direct_sub simWr defV. case: (set_0Vmem J) => [-> V0 | [j0 Jj0]]. by rewrite -mxrank_eq0 -V0 big_set0 mxrank0 in nzV. pose K := {j | j \in J}; pose k0 : K := Sub j0 Jj0. have bij_KJ: {on J, bijective (sval : K -> _)}. by exists (insubd k0) => [k _ | j Jj]; rewrite ?valKd ?insubdK. have J_K (k : K) : sval k \in J by apply: valP k. rewrite mxdirectE /= !(reindex _ bij_KJ) !(eq_bigl _ _ J_K) -mxdirectE /= -/tI. exact: MxSemisimple. Qed. Lemma mxsimple_semisimple U : mxsimple U -> mxsemisimple U. Proof. move=> simU; apply: (intro_mxsemisimple (_ : \sum_(i < 1) U :=: U))%MS => //. by rewrite big_ord1. Qed. Lemma addsmx_semisimple U V : mxsemisimple U -> mxsemisimple V -> mxsemisimple (U + V)%MS. Proof. case=> [I W /= simW defU _] [J T /= simT defV _]. have defUV: (\sum_ij sum_rect (fun _ => 'M_n) W T ij :=: U + V)%MS. by rewrite big_sumType /=; apply: adds_eqmx. by apply: intro_mxsemisimple defUV _; case=> /=. Qed. Lemma sumsmx_semisimple (I : finType) (P : pred I) V : (forall i, P i -> mxsemisimple (V i)) -> mxsemisimple (\sum_(i | P i) V i)%MS. Proof. move=> ssimV; elim/big_ind: _ => //; first exact: mxsemisimple0. exact: addsmx_semisimple. Qed. Lemma eqmx_semisimple U V : (U :=: V)%MS -> mxsemisimple U -> mxsemisimple V. Proof. by move=> eqUV [I W S simW defU dxS]; exists I W => //; apply: eqmx_trans eqUV. Qed. Lemma hom_mxsemisimple (V f : 'M_n) : mxsemisimple V -> (V <= dom_hom_mx f)%MS -> mxsemisimple (V *m f). Proof. case=> I W /= simW defV _; rewrite -defV => /sumsmx_subP homWf. have{defV} defVf: (\sum_i W i *m f :=: V *m f)%MS. by apply: eqmx_trans (eqmx_sym _) (eqmxMr f defV); apply: sumsmxMr. apply: (intro_mxsemisimple defVf) => i _ nzWf. by apply: mx_iso_simple (simW i); apply: mx_Schur_inj_iso; rewrite ?homWf. Qed. Lemma mxsemisimple_module U : mxsemisimple U -> mxmodule U. Proof. case=> I W /= simW defU _. by rewrite -(eqmx_module defU) sumsmx_module // => i _; case: (simW i). Qed. (* Completely reducible modules, and Maeschke's Theorem. *) Variant mxsplits (V U : 'M_n) := MxSplits (W : 'M_n) of mxmodule W & (U + W :=: V)%MS & mxdirect (U + W). Definition mx_completely_reducible V := forall U, mxmodule U -> (U <= V)%MS -> mxsplits V U. Lemma mx_reducibleS U V : mxmodule U -> (U <= V)%MS -> mx_completely_reducible V -> mx_completely_reducible U. Proof. move=> modU sUV redV U1 modU1 sU1U. have [W modW defV dxU1W] := redV U1 modU1 (submx_trans sU1U sUV). exists (W :&: U)%MS; first exact: capmx_module. by apply/eqmxP; rewrite !matrix_modl // capmxSr sub_capmx defV sUV /=. by apply/mxdirect_addsP; rewrite capmxA (mxdirect_addsP dxU1W) cap0mx. Qed. Lemma mx_Maschke_pchar : [pchar F]^'.-group G -> mx_completely_reducible 1%:M. Proof. rewrite /pgroup pcharf'_nat; set nG := _%:R => nzG U => /mxmoduleP Umod _. pose phi := nG^-1 *: (\sum_(x in G) rG x^-1 *m pinvmx U *m U *m rG x). have phiG x: x \in G -> phi *m rG x = rG x *m phi. move=> Gx; rewrite -scalemxAl -scalemxAr; congr (_ *: _). rewrite {2}(reindex_acts 'R _ Gx) ?astabsR //= mulmx_suml mulmx_sumr. apply: eq_bigr => y Gy; rewrite !mulmxA -repr_mxM ?groupV ?groupM //. by rewrite invMg mulKVg repr_mxM ?mulmxA. have Uphi: U *m phi = U. rewrite -scalemxAr mulmx_sumr (eq_bigr (fun _ => U)) => [|x Gx]. by rewrite sumr_const -scaler_nat !scalerA mulVf ?scale1r. by rewrite 3!mulmxA mulmxKpV ?repr_mxKV ?Umod ?groupV. have tiUker: (U :&: kermx phi = 0)%MS. apply/eqP/rowV0P=> v; rewrite sub_capmx => /andP[/submxP[u ->] /sub_kermxP]. by rewrite -mulmxA Uphi. exists (kermx phi); last exact/mxdirect_addsP. apply/mxmoduleP=> x Gx; apply/sub_kermxP. by rewrite -mulmxA -phiG // mulmxA mulmx_ker mul0mx. apply/eqmxP; rewrite submx1 sub1mx. rewrite /row_full mxrank_disjoint_sum //= mxrank_ker. suffices ->: (U :=: phi)%MS by rewrite subnKC ?rank_leq_row. apply/eqmxP; rewrite -{1}Uphi submxMl scalemx_sub //. by rewrite summx_sub // => x Gx; rewrite -mulmxA mulmx_sub ?Umod. Qed. Lemma mxsemisimple_reducible V : mxsemisimple V -> mx_completely_reducible V. Proof. case=> [I W /= simW defV _] U modU sUV; rewrite -defV in sUV. have [J [defV' dxV]] := sum_mxsimple_direct_compl simW modU sUV. exists (\sum_(i in J) W i)%MS. - by apply: sumsmx_module => i _; case: (simW i). - exact: eqmx_trans defV' defV. by rewrite mxdirect_addsE (sameP eqP mxdirect_addsP) /= in dxV; case/and3P: dxV. Qed. Lemma mx_reducible_semisimple V : mxmodule V -> mx_completely_reducible V -> classically (mxsemisimple V). Proof. move=> modV redV [] // nssimV; have [r leVr] := ubnP (\rank V). elim: r => // r IHr in V leVr modV redV nssimV. have [V0 | nzV] := eqVneq V 0. by rewrite nssimV ?V0 //; apply: mxsemisimple0. apply: (mxsimple_exists modV nzV) => [[U simU sUV]]; have [modU nzU _] := simU. have [W modW defUW dxUW] := redV U modU sUV. have sWV: (W <= V)%MS by rewrite -defUW addsmxSr. apply: IHr (mx_reducibleS modW sWV redV) _ => // [|ssimW]. rewrite ltnS -defUW (mxdirectP dxUW) /= in leVr; apply: leq_trans leVr. by rewrite -add1n leq_add2r lt0n mxrank_eq0. apply: nssimV (eqmx_semisimple defUW (addsmx_semisimple _ ssimW)). exact: mxsimple_semisimple. Qed. Lemma mxsemisimpleS U V : mxmodule U -> (U <= V)%MS -> mxsemisimple V -> mxsemisimple U. Proof. move=> modU sUV ssimV. have [W modW defUW dxUW]:= mxsemisimple_reducible ssimV modU sUV. move/mxdirect_addsP: dxUW => dxUW. have defU : (V *m proj_mx U W :=: U)%MS. by apply/eqmxP; rewrite proj_mx_sub -{1}[U](proj_mx_id dxUW) ?submxMr. apply: eqmx_semisimple defU _; apply: hom_mxsemisimple ssimV _. by rewrite -defUW proj_mx_hom. Qed. Lemma hom_mxsemisimple_iso I P U W f : let V := (\sum_(i : I | P i) W i)%MS in mxsimple U -> (forall i, P i -> W i != 0 -> mxsimple (W i)) -> (V <= dom_hom_mx f)%MS -> (U <= V *m f)%MS -> {i | P i & mx_iso (W i) U}. Proof. move=> V simU simW homVf sUVf; have [modU nzU _] := simU. have ssimVf: mxsemisimple (V *m f). exact: hom_mxsemisimple (intro_mxsemisimple (eqmx_refl V) simW) homVf. have [U' modU' defVf] := mxsemisimple_reducible ssimVf modU sUVf. move/mxdirect_addsP=> dxUU'; pose p := f *m proj_mx U U'. case: (pickP (fun i => P i && (W i *m p != 0))) => [i /andP[Pi nzWip] | no_i]. have sWiV: (W i <= V)%MS by rewrite (sumsmx_sup i). have sWipU: (W i *m p <= U)%MS by rewrite mulmxA proj_mx_sub. exists i => //; apply: (mx_Schur_iso (simW i Pi _) simU _ sWipU nzWip). by apply: contraNneq nzWip => ->; rewrite mul0mx. apply: (submx_trans sWiV); apply/hom_mxP=> x Gx. by rewrite mulmxA [_ *m p]mulmxA 2?(hom_mxP _) -?defVf ?proj_mx_hom. case/negP: nzU; rewrite -submx0 -[U](proj_mx_id dxUU') //. rewrite (submx_trans (submxMr _ sUVf)) // -mulmxA -/p sumsmxMr. by apply/sumsmx_subP=> i Pi; move/negbT: (no_i i); rewrite Pi negbK submx0. Qed. (* The component associated to a given irreducible module. *) Section Components. Fact component_mx_key : unit. Proof. by []. Qed. Definition component_mx_expr (U : 'M[F]_n) := (\sum_i cyclic_mx (row i (row_hom_mx (nz_row U))))%MS. Definition component_mx := locked_with component_mx_key component_mx_expr. Canonical component_mx_unfoldable := [unlockable fun component_mx]. Variable U : 'M[F]_n. Hypothesis simU : mxsimple U. Let u := nz_row U. Let iso_u := row_hom_mx u. Let nz_u : u != 0 := nz_row_mxsimple simU. Let Uu : (u <= U)%MS := nz_row_sub U. Let defU : (U :=: cyclic_mx u)%MS := mxsimple_cyclic simU nz_u Uu. Local Notation compU := (component_mx U). Lemma component_mx_module : mxmodule compU. Proof. by rewrite unlock sumsmx_module // => i; rewrite cyclic_mx_module. Qed. Lemma genmx_component : <<compU>>%MS = compU. Proof. by rewrite [in compU]unlock genmx_sums; apply: eq_bigr => i; rewrite genmx_id. Qed. Lemma component_mx_def : {I : finType & {W : I -> 'M_n | forall i, mx_iso U (W i) & compU = \sum_i W i}}%MS. Proof. pose r i := row i iso_u; pose r_nz i := r i != 0; pose I := {i | r_nz i}. exists I; exists (fun i => cyclic_mx (r (sval i))) => [i|]. apply/mxsimple_isoP=> //; apply/and3P. split; first by rewrite cyclic_mx_module. apply/rowV0Pn; exists (r (sval i)); last exact: (svalP i). by rewrite sub_capmx cyclic_mx_id row_sub. have [f hom_u_f <-] := @row_hom_mxP u (r (sval i)) (row_sub _ _). by rewrite defU -hom_cyclic_mx ?mxrankM_maxl. rewrite -(eq_bigr _ (fun _ _ => genmx_id _)) -genmx_sums -genmx_component. rewrite [in compU]unlock; apply/genmxP/andP; split; last first. by apply/sumsmx_subP => i _; rewrite (sumsmx_sup (sval i)). apply/sumsmx_subP => i _. case i0: (r_nz i); first by rewrite (sumsmx_sup (Sub i i0)). by move/negbFE: i0; rewrite -cyclic_mx_eq0 => /eqP->; apply: sub0mx. Qed. Lemma component_mx_semisimple : mxsemisimple compU. Proof. have [I [W isoUW ->]] := component_mx_def. apply: intro_mxsemisimple (eqmx_refl _) _ => i _ _. exact: mx_iso_simple (isoUW i) simU. Qed. Lemma mx_iso_component V : mx_iso U V -> (V <= compU)%MS. Proof. move=> isoUV; have [f injf homUf defV] := isoUV. have simV := mx_iso_simple isoUV simU. have hom_u_f := submx_trans Uu homUf. have ->: (V :=: cyclic_mx (u *m f))%MS. apply: eqmx_trans (hom_cyclic_mx hom_u_f). exact: eqmx_trans (eqmx_sym defV) (eqmxMr _ defU). have iso_uf: (u *m f <= iso_u)%MS by apply/row_hom_mxP; exists f. rewrite genmxE; apply/row_subP=> j; rewrite row_mul mul_rV_lin1 /=. set a := vec_mx _; apply: submx_trans (submxMr _ iso_uf) _. apply/row_subP=> i; rewrite row_mul [in compU]unlock (sumsmx_sup i) //. by apply/cyclic_mxP; exists a; rewrite // vec_mxK row_sub. Qed. Lemma component_mx_id : (U <= compU)%MS. Proof. exact: mx_iso_component (mx_iso_refl U). Qed. Lemma hom_component_mx_iso f V : mxsimple V -> (compU <= dom_hom_mx f)%MS -> (V <= compU *m f)%MS -> mx_iso U V. Proof. have [I [W isoUW ->]] := component_mx_def => simV homWf sVWf. have [i _ _|i _ ] := hom_mxsemisimple_iso simV _ homWf sVWf. exact: mx_iso_simple (simU). exact: mx_iso_trans. Qed. Lemma component_mx_iso V : mxsimple V -> (V <= compU)%MS -> mx_iso U V. Proof. move=> simV; rewrite -[compU]mulmx1. exact: hom_component_mx_iso (scalar_mx_hom _ _). Qed. Lemma hom_component_mx f : (compU <= dom_hom_mx f)%MS -> (compU *m f <= compU)%MS. Proof. move=> hom_f. have [I W /= simW defW _] := hom_mxsemisimple component_mx_semisimple hom_f. rewrite -defW; apply/sumsmx_subP=> i _; apply: mx_iso_component. by apply: hom_component_mx_iso hom_f _ => //; rewrite -defW (sumsmx_sup i). Qed. End Components. Lemma component_mx_isoP U V : mxsimple U -> mxsimple V -> reflect (mx_iso U V) (component_mx U == component_mx V). Proof. move=> simU simV; apply: (iffP eqP) => isoUV. by apply: component_mx_iso; rewrite ?isoUV ?component_mx_id. rewrite -(genmx_component U) -(genmx_component V); apply/genmxP. wlog suffices: U V simU simV isoUV / (component_mx U <= component_mx V)%MS. by move=> IH; rewrite !IH //; apply: mx_iso_sym. have [I [W isoWU ->]] := component_mx_def simU. apply/sumsmx_subP => i _; apply: mx_iso_component => //. exact: mx_iso_trans (mx_iso_sym isoUV) (isoWU i). Qed. Lemma component_mx_disjoint U V : mxsimple U -> mxsimple V -> component_mx U != component_mx V -> (component_mx U :&: component_mx V = 0)%MS. Proof. move=> simU simV neUV; apply: contraNeq neUV => ntUV. apply: (mxsimple_exists _ ntUV) => [|[W simW]]. by rewrite capmx_module ?component_mx_module. rewrite sub_capmx => /andP[sWU sWV]; apply/component_mx_isoP=> //. by apply: mx_iso_trans (_ : mx_iso U W) (mx_iso_sym _); apply: component_mx_iso. Qed. Section Socle. Record socleType := EnumSocle { socle_base_enum : seq 'M[F]_n; _ : forall M, M \in socle_base_enum -> mxsimple M; _ : forall M, mxsimple M -> has (mxsimple_iso M) socle_base_enum }. Lemma socle_exists : classically socleType. Proof. pose V : 'M[F]_n := 0; have: mxsemisimple V by apply: mxsemisimple0. have: n - \rank V < n.+1 by rewrite mxrank0 subn0. elim: _.+1 V => // n' IHn' V; rewrite ltnS => le_nV_n' ssimV. case=> // maxV; apply: (maxV); have [I /= U simU defV _] := ssimV. exists (codom U) => [M | M simM]; first by case/mapP=> i _ ->. suffices sMV: (M <= V)%MS. rewrite -defV -(mulmx1 (\sum_i _)%MS) in sMV. have [//| i _] := hom_mxsemisimple_iso simM _ (scalar_mx_hom _ _) sMV. move/mx_iso_sym=> isoM; apply/hasP. by exists (U i); [apply: codom_f | apply/mxsimple_isoP]. have ssimMV := addsmx_semisimple (mxsimple_semisimple simM) ssimV. apply: contraLR isT => nsMV; apply: IHn' ssimMV _ maxV. apply: leq_trans le_nV_n'; rewrite ltn_sub2l //. rewrite ltn_neqAle rank_leq_row andbT -[_ == _]sub1mx. by apply: contra nsMV; apply: submx_trans; apply: submx1. rewrite (ltn_leqif (mxrank_leqif_sup _)) ?addsmxSr //. by rewrite addsmx_sub submx_refl andbT. Qed. Section SocleDef. Variable sG0 : socleType. Definition socle_enum := map component_mx (socle_base_enum sG0). Lemma component_socle M : mxsimple M -> component_mx M \in socle_enum. Proof. rewrite /socle_enum; case: sG0 => e0 /= sim_e mem_e simM. have /hasP[M' e0M' isoMM'] := mem_e M simM; apply/mapP; exists M' => //. by apply/eqP/component_mx_isoP; [|apply: sim_e | apply/mxsimple_isoP]. Qed. Inductive socle_sort : predArgType := PackSocle W of W \in socle_enum. Local Notation sG := socle_sort. Local Notation e0 := (socle_base_enum sG0). Definition socle_base W := let: PackSocle W _ := W in e0`_(index W socle_enum). Coercion socle_val W : 'M[F]_n := component_mx (socle_base W). Definition socle_mult (W : sG) := (\rank W %/ \rank (socle_base W))%N. Lemma socle_simple W : mxsimple (socle_base W). Proof. case: W => M /=; rewrite /= /socle_enum /=; case: sG0 => e sim_e _ /= e_M. by apply: sim_e; rewrite mem_nth // -(size_map component_mx) index_mem. Qed. Definition socle_module (W : sG) := mxsimple_module (socle_simple W). Definition socle_repr W := submod_repr (socle_module W). Lemma nz_socle (W : sG) : W != 0 :> 'M_n. Proof. have simW := socle_simple W; have [_ nzW _] := simW; apply: contra nzW. by rewrite -!submx0; apply: submx_trans (component_mx_id simW). Qed. Lemma socle_mem (W : sG) : (W : 'M_n) \in socle_enum. Proof. exact: component_socle (socle_simple _). Qed. Lemma PackSocleK W e0W : @PackSocle W e0W = W :> 'M_n. Proof. rewrite /socle_val /= in e0W *; rewrite -(nth_map _ 0) ?nth_index //. by rewrite -(size_map component_mx) index_mem. Qed. HB.instance Definition _ := isSub.Build _ _ sG socle_sort_rect PackSocleK. HB.instance Definition _ := [Choice of sG by <:]. Lemma socleP (W W' : sG) : reflect (W = W') (W == W')%MS. Proof. by rewrite (sameP genmxP eqP) !{1}genmx_component; apply: (W =P _). Qed. Fact socle_can_subproof : cancel (fun W => SeqSub (socle_mem W)) (fun s => PackSocle (valP s)). Proof. by move=> W /=; apply: val_inj; rewrite /= PackSocleK. Qed. HB.instance Definition _ := isCountable.Build sG (pcan_pickleK (can_pcan socle_can_subproof)). HB.instance Definition _ := isFinite.Build sG (pcan_enumP (can_pcan socle_can_subproof)). End SocleDef. Coercion socle_sort : socleType >-> predArgType. Variable sG : socleType. Section SubSocle. Variable P : pred sG. Notation S := (\sum_(W : sG | P W) socle_val W)%MS. Lemma subSocle_module : mxmodule S. Proof. by rewrite sumsmx_module // => W _; apply: component_mx_module. Qed. Lemma subSocle_semisimple : mxsemisimple S. Proof. apply: sumsmx_semisimple => W _; apply: component_mx_semisimple. exact: socle_simple. Qed. Local Notation ssimS := subSocle_semisimple. Lemma subSocle_iso M : mxsimple M -> (M <= S)%MS -> {W : sG | P W & mx_iso (socle_base W) M}. Proof. move=> simM sMS; have [modM nzM _] := simM. have [V /= modV defMV] := mxsemisimple_reducible ssimS modM sMS. move/mxdirect_addsP=> dxMV; pose p := proj_mx M V; pose Sp (W : sG) := W *m p. case: (pickP [pred i | P i & Sp i != 0]) => [/= W | Sp0]; last first. case/negP: nzM; rewrite -submx0 -[M](proj_mx_id dxMV) //. rewrite (submx_trans (submxMr _ sMS)) // sumsmxMr big1 // => W P_W. by apply/eqP; move/negbT: (Sp0 W); rewrite /= P_W negbK. rewrite {}/Sp /= => /andP[P_W nzSp]; exists W => //. have homWp: (W <= dom_hom_mx p)%MS. apply: submx_trans (proj_mx_hom dxMV modM modV). by rewrite defMV (sumsmx_sup W). have simWP := socle_simple W; apply: hom_component_mx_iso (homWp) _ => //. by rewrite (mx_Schur_onto _ simM) ?proj_mx_sub ?component_mx_module. Qed. Lemma capmx_subSocle m (M : 'M_(m, n)) : mxmodule M -> (M :&: S :=: \sum_(W : sG | P W) (M :&: W))%MS. Proof. move=> modM; apply/eqmxP/andP; split; last first. by apply/sumsmx_subP=> W P_W; rewrite capmxS // (sumsmx_sup W). have modMS: mxmodule (M :&: S)%MS by rewrite capmx_module ?subSocle_module. have [J /= U simU defMS _] := mxsemisimpleS modMS (capmxSr M S) ssimS. rewrite -defMS; apply/sumsmx_subP=> j _. have [sUjV sUjS]: (U j <= M /\ U j <= S)%MS. by apply/andP; rewrite -sub_capmx -defMS (sumsmx_sup j). have [W P_W isoWU] := subSocle_iso (simU j) sUjS. rewrite (sumsmx_sup W) // sub_capmx sUjV mx_iso_component //. exact: socle_simple. Qed. End SubSocle. Lemma subSocle_direct P : mxdirect (\sum_(W : sG | P W) W). Proof. apply/mxdirect_sumsP=> W _; apply/eqP. rewrite -submx0 capmx_subSocle ?component_mx_module //. apply/sumsmx_subP=> W' /andP[_ neWW']. by rewrite capmxC component_mx_disjoint //; apply: socle_simple. Qed. Definition Socle := (\sum_(W : sG) W)%MS. Lemma simple_Socle M : mxsimple M -> (M <= Socle)%MS. Proof. move=> simM; have socM := component_socle sG simM. by rewrite (sumsmx_sup (PackSocle socM)) // PackSocleK component_mx_id. Qed. Lemma semisimple_Socle U : mxsemisimple U -> (U <= Socle)%MS. Proof. by case=> I M /= simM <- _; apply/sumsmx_subP=> i _; apply: simple_Socle. Qed. Lemma reducible_Socle U : mxmodule U -> mx_completely_reducible U -> (U <= Socle)%MS. Proof. move=> modU redU; apply: (mx_reducible_semisimple modU redU). exact: semisimple_Socle. Qed. Lemma genmx_Socle : <<Socle>>%MS = Socle. Proof. by rewrite genmx_sums; apply: eq_bigr => W; rewrite genmx_component. Qed. Lemma reducible_Socle1 : mx_completely_reducible 1%:M -> Socle = 1%:M. Proof. move=> redG; rewrite -genmx1 -genmx_Socle; apply/genmxP. by rewrite submx1 reducible_Socle ?mxmodule1. Qed. Lemma Socle_module : mxmodule Socle. Proof. exact: subSocle_module. Qed. Lemma Socle_semisimple : mxsemisimple Socle. Proof. exact: subSocle_semisimple. Qed. Lemma Socle_direct : mxdirect Socle. Proof. exact: subSocle_direct. Qed. Lemma Socle_iso M : mxsimple M -> {W : sG | mx_iso (socle_base W) M}. Proof. by move=> simM; case/subSocle_iso: (simple_Socle simM) => // W _; exists W. Qed. End Socle. (* Centralizer subgroup and central homomorphisms. *) Section CentHom. Variable f : 'M[F]_n. Lemma row_full_dom_hom : row_full (dom_hom_mx f) = centgmx rG f. Proof. by rewrite -sub1mx; apply/hom_mxP/centgmxP=> cfG x /cfG; rewrite !mul1mx. Qed. Lemma memmx_cent_envelop : (f \in 'C(E_G))%MS = centgmx rG f. Proof. apply/cent_rowP/centgmxP=> [cfG x Gx | cfG i]. by have:= cfG (enum_rank_in Gx x); rewrite rowK mxvecK enum_rankK_in. by rewrite rowK mxvecK /= cfG ?enum_valP. Qed. Lemma kermx_centg_module : centgmx rG f -> mxmodule (kermx f). Proof. move/centgmxP=> cGf; apply/mxmoduleP=> x Gx; apply/sub_kermxP. by rewrite -mulmxA -cGf // mulmxA mulmx_ker mul0mx. Qed. Lemma centgmx_hom m (U : 'M_(m, n)) : centgmx rG f -> (U <= dom_hom_mx f)%MS. Proof. by rewrite -row_full_dom_hom -sub1mx; apply: submx_trans (submx1 _). Qed. End CentHom. (* (Globally) irreducible, and absolutely irreducible representations. Note *) (* that unlike "reducible", "absolutely irreducible" can easily be decided. *) Definition mx_irreducible := mxsimple 1%:M. Lemma mx_irrP : mx_irreducible <-> n > 0 /\ (forall U, @mxmodule n U -> U != 0 -> row_full U). Proof. rewrite /mx_irreducible /mxsimple mxmodule1 -mxrank_eq0 mxrank1 -lt0n. do [split=> [[_ -> irrG] | [-> irrG]]; split=> // U] => [modU | modU _] nzU. by rewrite -sub1mx (irrG U) ?submx1. by rewrite sub1mx irrG. Qed. (* Schur's lemma for endomorphisms. *) Lemma mx_Schur : mx_irreducible -> forall f, centgmx rG f -> f != 0 -> f \in unitmx. Proof. move/mx_Schur_onto=> irrG f. rewrite -row_full_dom_hom -!row_full_unit -!sub1mx => cGf nz. by rewrite -[f]mul1mx irrG ?submx1 ?mxmodule1 ?mul1mx. Qed. Definition mx_absolutely_irreducible := (n > 0) && row_full E_G. Lemma mx_abs_irrP : reflect (n > 0 /\ exists a_, forall A, A = \sum_(x in G) a_ x A *: rG x) mx_absolutely_irreducible. Proof. have G_1 := group1 G; have bijG := enum_val_bij_in G_1. set h := enum_val in bijG; have Gh : h _ \in G by apply: enum_valP. rewrite /mx_absolutely_irreducible; case: (n > 0); last by right; case. apply: (iffP row_fullP) => [[E' E'G] | [_ [a_ a_G]]]. split=> //; exists (fun x B => (mxvec B *m E') 0 (enum_rank_in G_1 x)) => B. apply: (can_inj mxvecK); rewrite -{1}[mxvec B]mulmx1 -{}E'G mulmxA. move: {B E'}(_ *m E') => u; apply/rowP=> j. rewrite linear_sum (reindex h) //= mxE summxE. by apply: eq_big => [k| k _]; rewrite ?Gh // enum_valK_in linearZ !mxE. exists (\matrix_(j, i) a_ (h i) (vec_mx (row j 1%:M))). apply/row_matrixP=> i; rewrite -[row i 1%:M]vec_mxK {}[vec_mx _]a_G. apply/rowP=> j; rewrite linear_sum (reindex h) //= 2!mxE summxE. by apply: eq_big => [k| k _]; [rewrite Gh | rewrite linearZ !mxE]. Qed. Lemma mx_abs_irr_cent_scalar : mx_absolutely_irreducible -> forall A, centgmx rG A -> is_scalar_mx A. Proof. case/mx_abs_irrP=> n_gt0 [a_ a_G] A /centgmxP cGA. have{cGA a_G} cMA B: A *m B = B *m A. rewrite {}[B]a_G mulmx_suml mulmx_sumr. by apply: eq_bigr => x Gx; rewrite -scalemxAl -scalemxAr cGA. pose i0 := Ordinal n_gt0; apply/is_scalar_mxP; exists (A i0 i0). apply/matrixP=> i j; move/matrixP/(_ i0 j): (esym (cMA (delta_mx i0 i))). rewrite -[A *m _]trmxK trmx_mul trmx_delta -!(@mul_delta_mx _ n 1 n 0) -!mulmxA. by rewrite -!rowE !mxE !big_ord1 !mxE !eqxx !mulr_natl /= andbT eq_sym. Qed. Lemma mx_abs_irrW : mx_absolutely_irreducible -> mx_irreducible. Proof. case/mx_abs_irrP=> n_gt0 [a_ a_G]; apply/mx_irrP; split=> // U Umod. case/rowV0Pn=> u Uu; rewrite -mxrank_eq0 -lt0n row_leq_rank -sub1mx. case/submxP: Uu => v ->{u} /row_freeP[u' vK]; apply/row_subP=> i. rewrite rowE scalar_mxC -{}vK -2![_ *m _]mulmxA; move: {u' i}(u' *m _) => A. rewrite mulmx_sub {v}// [A]a_G linear_sum summx_sub //= => x Gx. by rewrite -scalemxAr scalemx_sub // (mxmoduleP Umod). Qed. Lemma linear_mx_abs_irr : n = 1 -> mx_absolutely_irreducible. Proof. move=> n1; rewrite /mx_absolutely_irreducible /row_full eqn_leq rank_leq_col. rewrite {1 2 3}n1 /= lt0n mxrank_eq0; apply: contraTneq envelop_mx1 => ->. by rewrite eqmx0 submx0 mxvec_eq0 -mxrank_eq0 mxrank1 n1. Qed. Lemma abelian_abs_irr : abelian G -> mx_absolutely_irreducible = (n == 1). Proof. move=> cGG; apply/idP/eqP=> [absG|]; last exact: linear_mx_abs_irr. have [n_gt0 _] := andP absG. pose M := <<delta_mx 0 (Ordinal n_gt0) : 'rV[F]_n>>%MS. have rM: \rank M = 1 by rewrite genmxE mxrank_delta. suffices defM: (M == 1%:M)%MS by rewrite (eqmxP defM) mxrank1 in rM. case: (mx_abs_irrW absG) => _ _ ->; rewrite ?submx1 -?mxrank_eq0 ?rM //. apply/mxmoduleP=> x Gx; suffices: is_scalar_mx (rG x). by case/is_scalar_mxP=> a ->; rewrite mul_mx_scalar scalemx_sub. apply: (mx_abs_irr_cent_scalar absG). by apply/centgmxP=> y Gy; rewrite -!repr_mxM // (centsP cGG). Qed. End OneRepresentation. Arguments mxmoduleP {gT G n rG m U}. Arguments envelop_mxP {gT G n rG A}. Arguments hom_mxP {gT G n rG m f W}. Arguments rfix_mxP {gT G n rG m W}. Arguments cyclic_mxP {gT G n rG u v}. Arguments annihilator_mxP {gT G n rG u A}. Arguments row_hom_mxP {gT G n rG u v}. Arguments mxsimple_isoP {gT G n rG U V}. Arguments socleP {gT G n rG sG0 W W'}. Arguments mx_abs_irrP {gT G n rG}. Arguments val_submod {n U m} W. Arguments in_submod {n} U {m} W. Arguments val_submodK {n U m} W : rename. Arguments in_submodK {n U m} [W] sWU. Arguments val_submod_inj {n U m} [W1 W2] : rename. Arguments val_factmod {n U m} W. Arguments in_factmod {n} U {m} W. Arguments val_factmodK {n U m} W : rename. Arguments in_factmodK {n} U {m} [W] sWU. Arguments val_factmod_inj {n U m} [W1 W2] : rename. Section Proper. Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variable rG : mx_representation F G n. Lemma envelop_mx_ring : mxring (enveloping_algebra_mx rG). Proof. apply/andP; split; first by apply/mulsmx_subP; apply: envelop_mxM. apply/mxring_idP; exists 1%:M; split=> *; rewrite ?mulmx1 ?mul1mx //. by rewrite -mxrank_eq0 mxrank1. exact: envelop_mx1. Qed. End Proper. Section JacobsonDensity. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation F G n. Hypothesis irrG : mx_irreducible rG. Local Notation E_G := (enveloping_algebra_mx rG). Local Notation Hom_G := 'C(E_G)%MS. Lemma mx_Jacobson_density : ('C(Hom_G) <= E_G)%MS. Proof. apply/row_subP=> iB; rewrite -[row iB _]vec_mxK; move defB: (vec_mx _) => B. have{defB} cBcE: (B \in 'C(Hom_G))%MS by rewrite -defB vec_mxK row_sub. have rGnP: mx_repr G (fun x => lin_mx (mulmxr (rG x)) : 'A_n). split=> [|x y Gx Gy]; apply/row_matrixP=> i. by rewrite !rowE mul_rV_lin repr_mx1 /= !mulmx1 vec_mxK. by rewrite !rowE mulmxA !mul_rV_lin repr_mxM //= mxvecK mulmxA. move def_rGn: (MxRepresentation rGnP) => rGn. pose E_Gn := enveloping_algebra_mx rGn. pose e1 : 'rV[F]_(n ^ 2) := mxvec 1%:M; pose U := cyclic_mx rGn e1. have U_e1: (e1 <= U)%MS by rewrite cyclic_mx_id. have modU: mxmodule rGn U by rewrite cyclic_mx_module. pose Bn : 'M_(n ^ 2) := lin_mx (mulmxr B). suffices U_e1Bn: (e1 *m Bn <= U)%MS. rewrite mul_vec_lin /= mul1mx in U_e1Bn; apply: submx_trans U_e1Bn _. rewrite genmxE; apply/row_subP=> i; rewrite row_mul rowK mul_vec_lin_row. by rewrite -def_rGn mul_vec_lin /= mul1mx (eq_row_sub i) ?rowK. have{cBcE} cBncEn A: centgmx rGn A -> A *m Bn = Bn *m A. rewrite -def_rGn => cAG; apply/row_matrixP; case/mxvec_indexP=> j k /=. rewrite !rowE !mulmxA -mxvec_delta -(mul_delta_mx (0 : 'I_1)). rewrite mul_rV_lin mul_vec_lin /= -mulmxA; apply: (canLR vec_mxK). apply/row_matrixP=> i; set dj0 := delta_mx j 0. have /= defAij := mul_rV_lin1 (row i \o vec_mx \o mulmxr A \o mxvec \o mulmx dj0). rewrite -defAij row_mul -defAij -!mulmxA (cent_mxP cBcE) {k}//. rewrite memmx_cent_envelop; apply/centgmxP=> x Gx; apply/row_matrixP=> k. rewrite !row_mul !rowE !{}defAij /= -row_mul mulmxA mul_delta_mx. congr (row i _); rewrite -(mul_vec_lin (mulmxr (rG x))) -mulmxA. by rewrite -(centgmxP cAG) // mulmxA mx_rV_lin. suffices redGn: mx_completely_reducible rGn 1%:M. have [V modV defUV] := redGn _ modU (submx1 _); move/mxdirect_addsP=> dxUV. rewrite -(proj_mx_id dxUV U_e1) -mulmxA {}cBncEn 1?mulmxA ?proj_mx_sub //. by rewrite -row_full_dom_hom -sub1mx -defUV proj_mx_hom. pose W i : 'M[F]_(n ^ 2) := <<lin1_mx (mxvec \o mulmx (delta_mx i 0))>>%MS. have defW: (\sum_i W i :=: 1%:M)%MS. apply/eqmxP; rewrite submx1; apply/row_subP; case/mxvec_indexP=> i j. rewrite row1 -mxvec_delta (sumsmx_sup i) // genmxE; apply/submxP. by exists (delta_mx 0 j); rewrite mul_rV_lin1 /= mul_delta_mx. apply: mxsemisimple_reducible; apply: (intro_mxsemisimple defW) => i _ nzWi. split=> // [|Vi modVi sViWi nzVi]. apply/mxmoduleP=> x Gx; rewrite genmxE (eqmxMr _ (genmxE _)) -def_rGn. apply/row_subP=> j; rewrite rowE mulmxA !mul_rV_lin1 /= mxvecK -mulmxA. by apply/submxP; move: (_ *m rG x) => v; exists v; rewrite mul_rV_lin1. do [rewrite !genmxE; set f := lin1_mx _] in sViWi *. have f_free: row_free f. apply/row_freeP; exists (lin1_mx (row i \o vec_mx)); apply/row_matrixP=> j. by rewrite row1 rowE mulmxA !mul_rV_lin1 /= mxvecK rowE !mul_delta_mx. pose V := <<Vi *m pinvmx f>>%MS; have Vidf := mulmxKpV sViWi. suffices: (1%:M <= V)%MS by rewrite genmxE -(submxMfree _ _ f_free) mul1mx Vidf. case: irrG => _ _ ->; rewrite ?submx1 //; last first. by rewrite -mxrank_eq0 genmxE -(mxrankMfree _ f_free) Vidf mxrank_eq0. apply/mxmoduleP=> x Gx; rewrite genmxE (eqmxMr _ (genmxE _)). rewrite -(submxMfree _ _ f_free) Vidf. apply: submx_trans (mxmoduleP modVi x Gx); rewrite -{2}Vidf. apply/row_subP=> j; apply: (eq_row_sub j); rewrite row_mul -def_rGn. by rewrite !(row_mul _ _ f) !mul_rV_lin1 /= mxvecK !row_mul !mulmxA. Qed. Lemma cent_mx_scalar_abs_irr : \rank Hom_G <= 1 -> mx_absolutely_irreducible rG. Proof. rewrite leqNgt => /(has_non_scalar_mxP (scalar_mx_cent _ _)) scal_cE. apply/andP; split; first by case/mx_irrP: irrG. rewrite -sub1mx; apply: submx_trans mx_Jacobson_density. apply/memmx_subP=> B _; apply/cent_mxP=> A cGA. case scalA: (is_scalar_mx A); last by case: scal_cE; exists A; rewrite ?scalA. by case/is_scalar_mxP: scalA => a ->; rewrite scalar_mxC. Qed. End JacobsonDensity. Section ChangeGroup. Variables (gT : finGroupType) (G H : {group gT}) (n : nat). Variables (rG : mx_representation F G n). Section SubGroup. Hypothesis sHG : H \subset G. Local Notation rH := (subg_repr rG sHG). Lemma rfix_subg : rfix_mx rH = rfix_mx rG. Proof. by []. Qed. Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_subg : rstabs rH U = H :&: rstabs rG U. Proof. by apply/setP=> x; rewrite !inE andbA -in_setI (setIidPl sHG). Qed. Lemma mxmodule_subg : mxmodule rG U -> mxmodule rH U. Proof. by rewrite /mxmodule rstabs_subg subsetI subxx; apply: subset_trans. Qed. End Stabilisers. Lemma mxsimple_subg M : mxmodule rG M -> mxsimple rH M -> mxsimple rG M. Proof. by move=> modM [_ nzM minM]; split=> // U /mxmodule_subg; apply: minM. Qed. Lemma subg_mx_irr : mx_irreducible rH -> mx_irreducible rG. Proof. by apply: mxsimple_subg; apply: mxmodule1. Qed. Lemma subg_mx_abs_irr : mx_absolutely_irreducible rH -> mx_absolutely_irreducible rG. Proof. rewrite /mx_absolutely_irreducible -!sub1mx => /andP[-> /submx_trans-> //]. apply/row_subP=> i; rewrite rowK /= envelop_mx_id //. by rewrite (subsetP sHG) ?enum_valP. Qed. End SubGroup. Section SameGroup. Hypothesis eqGH : G :==: H. Local Notation rH := (eqg_repr rG eqGH). Lemma rfix_eqg : rfix_mx rH = rfix_mx rG. Proof. by []. Qed. Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_eqg : rstabs rH U = rstabs rG U. Proof. by rewrite rstabs_subg -(eqP eqGH) (setIidPr _) ?rstabs_sub. Qed. Lemma mxmodule_eqg : mxmodule rH U = mxmodule rG U. Proof. by rewrite /mxmodule rstabs_eqg -(eqP eqGH). Qed. End Stabilisers. Lemma mxsimple_eqg M : mxsimple rH M <-> mxsimple rG M. Proof. rewrite /mxsimple mxmodule_eqg. split=> [] [-> -> minM]; split=> // U modU; by apply: minM; rewrite mxmodule_eqg in modU *. Qed. Lemma eqg_mx_irr : mx_irreducible rH <-> mx_irreducible rG. Proof. exact: mxsimple_eqg. Qed. Lemma eqg_mx_abs_irr : mx_absolutely_irreducible rH = mx_absolutely_irreducible rG. Proof. by congr (_ && (_ == _)); rewrite /enveloping_algebra_mx /= -(eqP eqGH). Qed. End SameGroup. End ChangeGroup. Section Morphpre. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Variables (G : {group rT}) (n : nat) (rG : mx_representation F G n). Local Notation rGf := (morphpre_repr f rG). Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_morphpre : rstabs rGf U = f @*^-1 (rstabs rG U). Proof. by apply/setP=> x; rewrite !inE andbA. Qed. Lemma mxmodule_morphpre : G \subset f @* D -> mxmodule rGf U = mxmodule rG U. Proof. by move=> sGf; rewrite /mxmodule rstabs_morphpre morphpreSK. Qed. End Stabilisers. Lemma rfix_morphpre (H : {set aT}) : H \subset D -> (rfix_mx rGf H :=: rfix_mx rG (f @* H))%MS. Proof. move=> sHD; apply/eqmxP/andP; split. by apply/rfix_mxP=> _ /morphimP[x _ Hx ->]; rewrite rfix_mx_id. by apply/rfix_mxP=> x Hx; rewrite rfix_mx_id ?mem_morphim ?(subsetP sHD). Qed. Lemma morphpre_mx_irr : G \subset f @* D -> (mx_irreducible rGf <-> mx_irreducible rG). Proof. move/mxmodule_morphpre=> modG; split=> /mx_irrP[n_gt0 irrG]; by apply/mx_irrP; split=> // U modU; apply: irrG; rewrite modG in modU *. Qed. Lemma morphpre_mx_abs_irr : G \subset f @* D -> mx_absolutely_irreducible rGf = mx_absolutely_irreducible rG. Proof. move=> sGfD; congr (_ && (_ == _)); apply/eqP; rewrite mxrank_leqif_sup //. apply/row_subP=> i; rewrite rowK. case/morphimP: (subsetP sGfD _ (enum_valP i)) => x Dx _ def_i. by rewrite def_i (envelop_mx_id rGf) // !inE Dx -def_i enum_valP. apply/row_subP=> i; rewrite rowK (envelop_mx_id rG) //. by case/morphpreP: (enum_valP i). Qed. End Morphpre. Section Morphim. Variables (aT rT : finGroupType) (G D : {group aT}) (f : {morphism D >-> rT}). Variables (n : nat) (rGf : mx_representation F (f @* G) n). Hypothesis sGD : G \subset D. Let sG_f'fG : G \subset f @*^-1 (f @* G). Proof. by rewrite -sub_morphim_pre. Qed. Local Notation rG := (morphim_repr rGf sGD). Section Stabilisers. Variables (m : nat) (U : 'M[F]_(m, n)). Lemma rstabs_morphim : rstabs rG U = G :&: f @*^-1 rstabs rGf U. Proof. by rewrite -rstabs_morphpre -(rstabs_subg _ sG_f'fG). Qed. Lemma mxmodule_morphim : mxmodule rG U = mxmodule rGf U. Proof. by rewrite /mxmodule rstabs_morphim subsetI subxx -sub_morphim_pre. Qed. End Stabilisers. Lemma rfix_morphim (H : {set aT}) : H \subset D -> (rfix_mx rG H :=: rfix_mx rGf (f @* H))%MS. Proof. exact: rfix_morphpre. Qed. Lemma mxsimple_morphim M : mxsimple rG M <-> mxsimple rGf M. Proof. rewrite /mxsimple mxmodule_morphim. split=> [] [-> -> minM]; split=> // U modU; by apply: minM; rewrite mxmodule_morphim in modU *. Qed. Lemma morphim_mx_irr : (mx_irreducible rG <-> mx_irreducible rGf). Proof. exact: mxsimple_morphim. Qed. Lemma morphim_mx_abs_irr : mx_absolutely_irreducible rG = mx_absolutely_irreducible rGf. Proof. have fG_onto: f @* G \subset restrm sGD f @* G. by rewrite (morphim_restrm sGD) setIid. rewrite -(morphpre_mx_abs_irr _ fG_onto); congr (_ && (_ == _)). by rewrite /enveloping_algebra_mx /= morphpre_restrm (setIidPl _). Qed. End Morphim. Section Submodule. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation F G n) (U : 'M[F]_n) (Umod : mxmodule rG U). Local Notation rU := (submod_repr Umod). Local Notation rU' := (factmod_repr Umod). Lemma rfix_submod (H : {set gT}) : H \subset G -> (rfix_mx rU H :=: in_submod U (U :&: rfix_mx rG H))%MS. Proof. move=> sHG; apply/eqmxP/andP; split; last first. apply/rfix_mxP=> x Hx; rewrite -in_submodJ ?capmxSl //. by rewrite (rfix_mxP H _) ?capmxSr. rewrite -val_submodS in_submodK ?capmxSl // sub_capmx val_submodP //=. apply/rfix_mxP=> x Hx. by rewrite -(val_submodJ Umod) ?(subsetP sHG) ?rfix_mx_id. Qed. Lemma rfix_factmod (H : {set gT}) : H \subset G -> (in_factmod U (rfix_mx rG H) <= rfix_mx rU' H)%MS. Proof. move=> sHG; apply/rfix_mxP=> x Hx. by rewrite -(in_factmodJ Umod) ?(subsetP sHG) ?rfix_mx_id. Qed. Lemma rstab_submod m (W : 'M_(m, \rank U)) : rstab rU W = rstab rG (val_submod W). Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. by rewrite -(inj_eq val_submod_inj) val_submodJ. Qed. Lemma rstabs_submod m (W : 'M_(m, \rank U)) : rstabs rU W = rstabs rG (val_submod W). Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. by rewrite -val_submodS val_submodJ. Qed. Lemma val_submod_module m (W : 'M_(m, \rank U)) : mxmodule rG (val_submod W) = mxmodule rU W. Proof. by rewrite /mxmodule rstabs_submod. Qed. Lemma in_submod_module m (V : 'M_(m, n)) : (V <= U)%MS -> mxmodule rU (in_submod U V) = mxmodule rG V. Proof. by move=> sVU; rewrite -val_submod_module in_submodK. Qed. Lemma rstab_factmod m (W : 'M_(m, n)) : rstab rG W \subset rstab rU' (in_factmod U W). Proof. by apply/subsetP=> x /setIdP[Gx /eqP cUW]; rewrite inE Gx -in_factmodJ //= cUW. Qed. Lemma rstabs_factmod m (W : 'M_(m, \rank (cokermx U))) : rstabs rU' W = rstabs rG (U + val_factmod W)%MS. Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. rewrite addsmxMr addsmx_sub (submx_trans (mxmoduleP Umod x Gx)) ?addsmxSl //. rewrite -val_factmodS val_factmodJ //= val_factmodS; apply/idP/idP=> nWx. rewrite (submx_trans (addsmxSr U _)) // -(in_factmodsK (addsmxSl U _)) //. by rewrite addsmxS // val_factmodS in_factmod_addsK. rewrite in_factmodE (submx_trans (submxMr _ nWx)) // -in_factmodE. by rewrite in_factmod_addsK val_factmodK. Qed. Lemma val_factmod_module m (W : 'M_(m, \rank (cokermx U))) : mxmodule rG (U + val_factmod W)%MS = mxmodule rU' W. Proof. by rewrite /mxmodule rstabs_factmod. Qed. Lemma in_factmod_module m (V : 'M_(m, n)) : mxmodule rU' (in_factmod U V) = mxmodule rG (U + V)%MS. Proof. rewrite -(eqmx_module _ (in_factmodsK (addsmxSl U V))). by rewrite val_factmod_module (eqmx_module _ (in_factmod_addsK _ _)). Qed. Lemma rker_submod : rker rU = rstab rG U. Proof. by rewrite /rker rstab_submod; apply: eqmx_rstab (val_submod1 U). Qed. Lemma rstab_norm : G \subset 'N(rstab rG U). Proof. by rewrite -rker_submod rker_norm. Qed. Lemma rstab_normal : rstab rG U <| G. Proof. by rewrite -rker_submod rker_normal. Qed. Lemma submod_mx_faithful : mx_faithful rU -> mx_faithful rG. Proof. by apply: subset_trans; rewrite rker_submod rstabS ?submx1. Qed. Lemma rker_factmod : rker rG \subset rker rU'. Proof. apply/subsetP=> x /rkerP[Gx cVx]. by rewrite inE Gx /= /factmod_mx cVx mul1mx mulmx1 val_factmodK. Qed. Lemma factmod_mx_faithful : mx_faithful rU' -> mx_faithful rG. Proof. exact: subset_trans rker_factmod. Qed. Lemma submod_mx_irr : mx_irreducible rU <-> mxsimple rG U. Proof. split=> [] [_ nzU simU]. rewrite -mxrank_eq0 mxrank1 mxrank_eq0 in nzU; split=> // V modV sVU nzV. rewrite -(in_submodK sVU) -val_submod1 val_submodS. rewrite -(genmxE (in_submod U V)) simU ?genmxE ?submx1 //=. by rewrite (eqmx_module _ (genmxE _)) in_submod_module. by rewrite -submx0 genmxE -val_submodS in_submodK // linear0 eqmx0 submx0. apply/mx_irrP; rewrite lt0n mxrank_eq0; split=> // V modV. rewrite -(inj_eq val_submod_inj) linear0 -(eqmx_eq0 (genmxE _)) => nzV. rewrite -sub1mx -val_submodS val_submod1 -(genmxE (val_submod V)). rewrite simU ?genmxE ?val_submodP //=. by rewrite (eqmx_module _ (genmxE _)) val_submod_module. Qed. End Submodule. Section Conjugate. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation F G n) (B : 'M[F]_n). Hypothesis uB : B \in unitmx. Local Notation rGB := (rconj_repr rG uB). Lemma rfix_conj (H : {set gT}) : (rfix_mx rGB H :=: B *m rfix_mx rG H *m invmx B)%MS. Proof. apply/eqmxP/andP; split. rewrite -mulmxA (eqmxMfull (_ *m _)) ?row_full_unit //. rewrite -[rfix_mx rGB H](mulmxK uB) submxMr //; apply/rfix_mxP=> x Hx. apply: (canRL (mulmxKV uB)); rewrite -(rconj_mxJ _ uB) mulmxK //. by rewrite rfix_mx_id. apply/rfix_mxP=> x Gx; rewrite -3!mulmxA; congr (_ *m _). by rewrite !mulmxA mulmxKV // rfix_mx_id. Qed. Lemma rstabs_conj m (U : 'M_(m, n)) : rstabs rGB U = rstabs rG (U *m B). Proof. apply/setP=> x; rewrite !inE rconj_mxE !mulmxA. by rewrite -{2}[U](mulmxK uB) submxMfree // row_free_unit unitmx_inv. Qed. Lemma mxmodule_conj m (U : 'M_(m, n)) : mxmodule rGB U = mxmodule rG (U *m B). Proof. by rewrite /mxmodule rstabs_conj. Qed. Lemma conj_mx_irr : mx_irreducible rGB <-> mx_irreducible rG. Proof. have Bfree: row_free B by rewrite row_free_unit. split => /mx_irrP[n_gt0 irrG]; apply/mx_irrP; split=> // U. rewrite -[U](mulmxKV uB) -mxmodule_conj -mxrank_eq0 /row_full mxrankMfree //. by rewrite mxrank_eq0; apply: irrG. rewrite -mxrank_eq0 /row_full -(mxrankMfree _ Bfree) mxmodule_conj mxrank_eq0. exact: irrG. Qed. End Conjugate. Section Quotient. Variables (gT : finGroupType) (G : {group gT}) (n : nat). Variables (rG : mx_representation F G n) (H : {group gT}). Hypotheses (krH : H \subset rker rG) (nHG : G \subset 'N(H)). Let nHGs := subsetP nHG. Local Notation rGH := (quo_repr krH nHG). Local Notation E_ r := (enveloping_algebra_mx r). Lemma quo_mx_quotient : (E_ rGH :=: E_ rG)%MS. Proof. apply/eqmxP/andP; split; apply/row_subP=> i. rewrite rowK; case/morphimP: (enum_valP i) => x _ Gx ->{i}. rewrite quo_repr_coset // (eq_row_sub (enum_rank_in Gx x)) // rowK. by rewrite enum_rankK_in. rewrite rowK -(quo_mx_coset krH nHG) ?enum_valP //; set Hx := coset H _. have GHx: Hx \in (G / H)%g by rewrite mem_quotient ?enum_valP. by rewrite (eq_row_sub (enum_rank_in GHx Hx)) // rowK enum_rankK_in. Qed. Lemma rfix_quo (K : {group gT}) : K \subset G -> (rfix_mx rGH (K / H)%g :=: rfix_mx rG K)%MS. Proof. move=> sKG; apply/eqmxP/andP; (split; apply/rfix_mxP) => [x Kx | Hx]. have Gx := subsetP sKG x Kx; rewrite -(quo_mx_coset krH nHG) // rfix_mx_id //. by rewrite mem_morphim ?(subsetP nHG). case/morphimP=> x _ Kx ->; have Gx := subsetP sKG x Kx. by rewrite quo_repr_coset ?rfix_mx_id. Qed. Lemma rstabs_quo m (U : 'M_(m, n)) : rstabs rGH U = (rstabs rG U / H)%g. Proof. apply/setP=> Hx /[!inE]; apply/andP/idP=> [[]|] /morphimP[x Nx Gx ->{Hx}]. by rewrite quo_repr_coset // => nUx; rewrite mem_morphim // inE Gx. by case/setIdP: Gx => Gx nUx; rewrite quo_repr_coset ?mem_morphim. Qed. Lemma mxmodule_quo m (U : 'M_(m, n)) : mxmodule rGH U = mxmodule rG U. Proof. rewrite /mxmodule rstabs_quo quotientSGK // ?(subset_trans krH) //. by apply/subsetP=> x /[!inE]/andP[-> /[1!mul1mx]/eqP->/=]; rewrite mulmx1. Qed. Lemma quo_mx_irr : mx_irreducible rGH <-> mx_irreducible rG. Proof. split; case/mx_irrP=> n_gt0 irrG; apply/mx_irrP; split=> // U modU; by apply: irrG; rewrite mxmodule_quo in modU *. Qed. End Quotient. Section SplittingField. Implicit Type gT : finGroupType. Definition group_splitting_field gT (G : {group gT}) := forall n (rG : mx_representation F G n), mx_irreducible rG -> mx_absolutely_irreducible rG. Definition group_closure_field gT := forall G : {group gT}, group_splitting_field G. Lemma quotient_splitting_field gT (G : {group gT}) (H : {set gT}) : G \subset 'N(H) -> group_splitting_field G -> group_splitting_field (G / H). Proof. move=> nHG splitG n rGH irrGH. by rewrite -(morphim_mx_abs_irr _ nHG) splitG //; apply/morphim_mx_irr. Qed. Lemma coset_splitting_field gT (H : {set gT}) : group_closure_field gT -> group_closure_field (coset_of H). Proof. move=> split_gT Gbar; have ->: Gbar = (coset H @*^-1 Gbar / H)%G. by apply: val_inj; rewrite /= /quotient morphpreK ?sub_im_coset. by apply: quotient_splitting_field; [apply: subsetIl | apply: split_gT]. Qed. End SplittingField. Section Abelian. Variables (gT : finGroupType) (G : {group gT}). Lemma mx_faithful_irr_center_cyclic n (rG : mx_representation F G n) : mx_faithful rG -> mx_irreducible rG -> cyclic 'Z(G). Proof. case: n rG => [|n] rG injG irrG; first by case/mx_irrP: irrG. move/trivgP: injG => KrG1; pose rZ := subg_repr rG (center_sub _). apply: (div_ring_mul_group_cyclic (repr_mx1 rZ)) (repr_mxM rZ) _ _; last first. exact: center_abelian. move=> x; rewrite -[[set _]]KrG1 !inE mul1mx -subr_eq0 andbC; set U := _ - _. do 2![case/andP]=> Gx cGx; rewrite Gx /=; apply: (mx_Schur irrG). apply/centgmxP=> y Gy; rewrite mulmxBl mulmxBr mulmx1 mul1mx. by rewrite -!repr_mxM // (centP cGx). Qed. Lemma mx_faithful_irr_abelian_cyclic n (rG : mx_representation F G n) : mx_faithful rG -> mx_irreducible rG -> abelian G -> cyclic G. Proof. move=> injG irrG cGG; rewrite -(setIidPl cGG). exact: mx_faithful_irr_center_cyclic injG irrG. Qed. Hypothesis splitG : group_splitting_field G. Lemma mx_irr_abelian_linear n (rG : mx_representation F G n) : mx_irreducible rG -> abelian G -> n = 1. Proof. by move=> irrG cGG; apply/eqP; rewrite -(abelian_abs_irr rG) ?splitG. Qed. Lemma mxsimple_abelian_linear n (rG : mx_representation F G n) M : abelian G -> mxsimple rG M -> \rank M = 1. Proof. move=> cGG simM; have [modM _ _] := simM. by move/(submod_mx_irr modM)/mx_irr_abelian_linear: simM => ->. Qed. Lemma linear_mxsimple n (rG : mx_representation F G n) (M : 'M_n) : mxmodule rG M -> \rank M = 1 -> mxsimple rG M. Proof. move=> modM rM1; apply/(submod_mx_irr modM). by apply: mx_abs_irrW; rewrite linear_mx_abs_irr. Qed. End Abelian. Section AbelianQuotient. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation F G n). Lemma center_kquo_cyclic : mx_irreducible rG -> cyclic 'Z(G / rker rG)%g. Proof. move=> irrG; apply: mx_faithful_irr_center_cyclic (kquo_mx_faithful rG) _. exact/quo_mx_irr. Qed. Lemma der1_sub_rker : group_splitting_field G -> mx_irreducible rG -> (G^`(1) \subset rker rG)%g = (n == 1)%N. Proof. move=> splitG irrG; apply/idP/idP; last by move/eqP; apply: rker_linear. move/sub_der1_abelian; move/(abelian_abs_irr (kquo_repr rG))=> <-. by apply: (quotient_splitting_field (rker_norm _) splitG); apply/quo_mx_irr. Qed. End AbelianQuotient. Section Similarity. Variables (gT : finGroupType) (G : {group gT}). Local Notation reprG := (mx_representation F G). Variant mx_rsim n1 (rG1 : reprG n1) n2 (rG2 : reprG n2) : Prop := MxReprSim B of n1 = n2 & row_free B & forall x, x \in G -> rG1 x *m B = B *m rG2 x. Lemma mxrank_rsim n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> n1 = n2. Proof. by case. Qed. Lemma mx_rsim_refl n (rG : reprG n) : mx_rsim rG rG. Proof. exists 1%:M => // [|x _]; first by rewrite row_free_unit unitmx1. by rewrite mulmx1 mul1mx. Qed. Lemma mx_rsim_sym n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_rsim rG2 rG1. Proof. case=> B def_n1; rewrite def_n1 in rG1 B *. rewrite row_free_unit => injB homB; exists (invmx B) => // [|x Gx]. by rewrite row_free_unit unitmx_inv. by apply: canRL (mulKmx injB) _; rewrite mulmxA -homB ?mulmxK. Qed. Lemma mx_rsim_trans n1 n2 n3 (rG1 : reprG n1) (rG2 : reprG n2) (rG3 : reprG n3) : mx_rsim rG1 rG2 -> mx_rsim rG2 rG3 -> mx_rsim rG1 rG3. Proof. case=> [B1 defn1 freeB1 homB1] [B2 defn2 freeB2 homB2]. exists (B1 *m B2); rewrite /row_free ?mxrankMfree 1?defn1 // => x Gx. by rewrite mulmxA homB1 // -!mulmxA homB2. Qed. Lemma mx_rsim_def n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> exists B, exists2 B', B' *m B = 1%:M & forall x, x \in G -> rG1 x = B *m rG2 x *m B'. Proof. case=> B def_n1; rewrite def_n1 in rG1 B *; rewrite row_free_unit => injB homB. by exists B, (invmx B) => [|x Gx]; rewrite ?mulVmx // -homB // mulmxK. Qed. Lemma mx_rsim_iso n (rG : reprG n) (U V : 'M_n) (modU : mxmodule rG U) (modV : mxmodule rG V) : mx_rsim (submod_repr modU) (submod_repr modV) <-> mx_iso rG U V. Proof. split=> [[B eqrUV injB homB] | [f injf homf defV]]. have: \rank (U *m val_submod (in_submod U 1%:M *m B)) = \rank U. do 2!rewrite mulmxA mxrankMfree ?row_base_free //. by rewrite -(eqmxMr _ (val_submod1 U)) -in_submodE val_submodK mxrank1. case/complete_unitmx => f injf defUf; exists f => //. apply/hom_mxP=> x Gx; rewrite -defUf -2!mulmxA -(val_submodJ modV) //. rewrite -(mulmxA _ B) -homB // val_submodE 3!(mulmxA U) (mulmxA _ _ B). rewrite -in_submodE -in_submodJ //. have [u ->] := submxP (mxmoduleP modU x Gx). by rewrite in_submodE -mulmxA -defUf !mulmxA !mulmx1. apply/eqmxP; rewrite -mxrank_leqif_eq. by rewrite mxrankMfree ?eqrUV ?row_free_unit. by rewrite -defUf mulmxA val_submodP. have eqrUV: \rank U = \rank V by rewrite -defV mxrankMfree ?row_free_unit. exists (in_submod V (val_submod 1%:M *m f)) => // [|x Gx]. rewrite /row_free {6}eqrUV -[_ == _]sub1mx -val_submodS. rewrite in_submodK; last by rewrite -defV submxMr ?val_submodP. by rewrite val_submod1 -defV submxMr ?val_submod1. rewrite -in_submodJ; last by rewrite -defV submxMr ?val_submodP. rewrite -(hom_mxP (submx_trans (val_submodP _) homf)) // -(val_submodJ modU) //. by rewrite mul1mx 2!(mulmxA ((submod_repr _) x)) -val_submodE. Qed. Lemma mx_rsim_irr n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_irreducible rG1 -> mx_irreducible rG2. Proof. case/mx_rsim_sym=> f def_n2; rewrite {n2}def_n2 in f rG2 * => injf homf. case/mx_irrP=> n1_gt0 minG; apply/mx_irrP; split=> // U modU nzU. rewrite /row_full -(mxrankMfree _ injf) -genmxE. apply: minG; last by rewrite -mxrank_eq0 genmxE mxrankMfree // mxrank_eq0. rewrite (eqmx_module _ (genmxE _)); apply/mxmoduleP=> x Gx. by rewrite -mulmxA -homf // mulmxA submxMr // (mxmoduleP modU). Qed. Lemma mx_rsim_abs_irr n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_absolutely_irreducible rG1 = mx_absolutely_irreducible rG2. Proof. case=> f def_n2; rewrite -{n2}def_n2 in f rG2 *. rewrite row_free_unit => injf homf; congr (_ && (_ == _)). pose Eg (g : 'M[F]_n1) := lin_mx (mulmxr (invmx g) \o mulmx g). have free_Ef: row_free (Eg f). apply/row_freeP; exists (Eg (invmx f)); apply/row_matrixP=> i. rewrite rowE row1 mulmxA mul_rV_lin mx_rV_lin /=. by rewrite invmxK !{1}mulmxA mulmxKV // -mulmxA mulKmx // vec_mxK. symmetry; rewrite -(mxrankMfree _ free_Ef); congr (\rank _). apply/row_matrixP=> i; rewrite row_mul !rowK mul_vec_lin /=. by rewrite -homf ?enum_valP // mulmxK. Qed. Lemma rker_mx_rsim n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> rker rG1 = rker rG2. Proof. case=> f def_n2; rewrite -{n2}def_n2 in f rG2 *. rewrite row_free_unit => injf homf. apply/setP=> x; rewrite !inE !mul1mx; apply: andb_id2l => Gx. by rewrite -(can_eq (mulmxK injf)) homf // -scalar_mxC (can_eq (mulKmx injf)). Qed. Lemma mx_rsim_faithful n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> mx_faithful rG1 = mx_faithful rG2. Proof. by move=> simG12; rewrite /mx_faithful (rker_mx_rsim simG12). Qed. Lemma mx_rsim_factmod n (rG : reprG n) U V (modU : mxmodule rG U) (modV : mxmodule rG V) : (U + V :=: 1%:M)%MS -> mxdirect (U + V) -> mx_rsim (factmod_repr modV) (submod_repr modU). Proof. move=> addUV dxUV. have eqUV: \rank U = \rank (cokermx V). by rewrite mxrank_coker -{3}(mxrank1 F n) -addUV (mxdirectP dxUV) addnK. have{} dxUV: (U :&: V = 0)%MS by apply/mxdirect_addsP. exists (in_submod U (val_factmod 1%:M *m proj_mx U V)) => // [|x Gx]. rewrite /row_free -{6}eqUV -[_ == _]sub1mx -val_submodS val_submod1. rewrite in_submodK ?proj_mx_sub // -{1}[U](proj_mx_id dxUV) //. rewrite -{1}(add_sub_fact_mod V U) mulmxDl proj_mx_0 ?val_submodP // add0r. by rewrite submxMr // val_factmodS submx1. rewrite -in_submodJ ?proj_mx_sub // -(hom_mxP _) //; last first. by apply: submx_trans (submx1 _) _; rewrite -addUV proj_mx_hom. rewrite mulmxA; congr (_ *m _); rewrite mulmxA -val_factmodE; apply/eqP. rewrite eq_sym -subr_eq0 -mulmxBl proj_mx_0 //. by rewrite -[_ *m rG x](add_sub_fact_mod V) addrK val_submodP. Qed. Lemma mxtrace_rsim n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : mx_rsim rG1 rG2 -> {in G, forall x, \tr (rG1 x) = \tr (rG2 x)}. Proof. case/mx_rsim_def=> B [B' B'B def_rG1] x Gx. by rewrite def_rG1 // mxtrace_mulC mulmxA B'B mul1mx. Qed. Lemma mx_rsim_scalar n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) x c : x \in G -> mx_rsim rG1 rG2 -> rG1 x = c%:M -> rG2 x = c%:M. Proof. move=> Gx /mx_rsim_sym[B _ Bfree rG2_B] rG1x. by apply: (row_free_inj Bfree); rewrite rG2_B // rG1x scalar_mxC. Qed. End Similarity. Section Socle. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation F G n) (sG : socleType rG). Lemma socle_irr (W : sG) : mx_irreducible (socle_repr W). Proof. by apply/submod_mx_irr; apply: socle_simple. Qed. Lemma socle_rsimP (W1 W2 : sG) : reflect (mx_rsim (socle_repr W1) (socle_repr W2)) (W1 == W2). Proof. have [simW1 simW2] := (socle_simple W1, socle_simple W2). by apply: (iffP (component_mx_isoP simW1 simW2)); move/mx_rsim_iso; apply. Qed. Local Notation mG U := (mxmodule rG U). Local Notation sr modV := (submod_repr modV). Lemma mx_rsim_in_submod U V (modU : mG U) (modV : mG V) : let U' := <<in_submod V U>>%MS in (U <= V)%MS -> exists modU' : mxmodule (sr modV) U', mx_rsim (sr modU) (sr modU'). Proof. move=> U' sUV; have modU': mxmodule (sr modV) U'. by rewrite (eqmx_module _ (genmxE _)) in_submod_module. have rankU': \rank U = \rank U' by rewrite genmxE mxrank_in_submod. pose v1 := val_submod 1%:M; pose U1 := v1 _ U. have sU1V: (U1 <= V)%MS by rewrite val_submod1. have sU1U': (in_submod V U1 <= U')%MS by rewrite genmxE submxMr ?val_submod1. exists modU', (in_submod U' (in_submod V U1)) => // [|x Gx]. apply/row_freeP; exists (v1 _ _ *m v1 _ _ *m in_submod U 1%:M). rewrite mulmxA [X in X *m _]mulmxA -in_submodE. by rewrite -!val_submodE !in_submodK ?val_submodK. rewrite -!in_submodJ // -(val_submodJ modU) // mul1mx. by rewrite 2!{1}in_submodE mulmxA (mulmxA _ U1) -val_submodE -!in_submodE. Qed. Lemma rsim_submod1 U (modU : mG U) : (U :=: 1%:M)%MS -> mx_rsim (sr modU) rG. Proof. move=> U1; exists (val_submod 1%:M) => [||x Gx]; first by rewrite U1 mxrank1. by rewrite /row_free val_submod1. by rewrite -(val_submodJ modU) // mul1mx -val_submodE. Qed. Lemma mxtrace_submod1 U (modU : mG U) : (U :=: 1%:M)%MS -> {in G, forall x, \tr (sr modU x) = \tr (rG x)}. Proof. by move=> defU; apply: mxtrace_rsim (rsim_submod1 modU defU). Qed. Lemma mxtrace_dadd_mod U V W (modU : mG U) (modV : mG V) (modW : mG W) : (U + V :=: W)%MS -> mxdirect (U + V) -> {in G, forall x, \tr (sr modU x) + \tr (sr modV x) = \tr (sr modW x)}. Proof. move=> defW dxW x Gx; have [sUW sVW]: (U <= W)%MS /\ (V <= W)%MS. by apply/andP; rewrite -addsmx_sub defW. pose U' := <<in_submod W U>>%MS; pose V' := <<in_submod W V>>%MS. have addUV': (U' + V' :=: 1%:M)%MS. apply/eqmxP; rewrite submx1 /= (adds_eqmx (genmxE _) (genmxE _)). by rewrite -addsmxMr -val_submodS val_submod1 in_submodK ?defW. have dxUV': mxdirect (U' + V'). apply/eqnP; rewrite /= addUV' mxrank1 !genmxE !mxrank_in_submod //. by rewrite -(mxdirectP dxW) /= defW. have [modU' simU] := mx_rsim_in_submod modU modW sUW. have [modV' simV] := mx_rsim_in_submod modV modW sVW. rewrite (mxtrace_rsim simU) // (mxtrace_rsim simV) //. rewrite -(mxtrace_sub_fact_mod modV') addrC; congr (_ + _). by rewrite (mxtrace_rsim (mx_rsim_factmod modU' modV' addUV' dxUV')). Qed. Lemma mxtrace_dsum_mod (I : finType) (P : pred I) U W (modU : forall i, mG (U i)) (modW : mG W) : let S := (\sum_(i | P i) U i)%MS in (S :=: W)%MS -> mxdirect S -> {in G, forall x, \sum_(i | P i) \tr (sr (modU i) x) = \tr (sr modW x)}. Proof. move=> /= sumS dxS x Gx; have [m lePm] := ubnP #|P|. elim: m => // m IHm in P lePm W modW sumS dxS *. have [j /= Pj | P0] := pickP P; last first. case: sumS (_ x); rewrite !big_pred0 // mxrank0 => <- _ rWx. by rewrite [rWx]flatmx0 linear0. rewrite ltnS (cardD1x Pj) in lePm. rewrite mxdirectE /= !(bigD1 j Pj) -mxdirectE mxdirect_addsE /= in dxS sumS *. have [_ dxW' dxW] := and3P dxS; rewrite (sameP eqP mxdirect_addsP) in dxW. rewrite (IHm _ _ _ (sumsmx_module _ (fun i _ => modU i)) (eqmx_refl _)) //. exact: mxtrace_dadd_mod. Qed. Lemma mxtrace_component U (simU : mxsimple rG U) : let V := component_mx rG U in let modV := component_mx_module rG U in let modU := mxsimple_module simU in {in G, forall x, \tr (sr modV x) = \tr (sr modU x) *+ (\rank V %/ \rank U)}. Proof. move=> V modV modU x Gx. have [I W S simW defV dxV] := component_mx_semisimple simU. rewrite -(mxtrace_dsum_mod (fun i => mxsimple_module (simW i)) modV defV) //. have rankU_gt0: \rank U > 0 by rewrite lt0n mxrank_eq0; case simU. have isoW i: mx_iso rG U (W i). by apply: component_mx_iso; rewrite ?simU // -defV (sumsmx_sup i). have ->: (\rank V %/ \rank U)%N = #|I|. symmetry; rewrite -(mulnK #|I| rankU_gt0); congr (_ %/ _)%N. rewrite -defV (mxdirectP dxV) /= -sum_nat_const. by apply: eq_bigr => i _; apply: mxrank_iso. rewrite -sumr_const; apply: eq_bigr => i _; symmetry. by apply: mxtrace_rsim Gx; apply/mx_rsim_iso; apply: isoW. Qed. Lemma mxtrace_Socle : let modS := Socle_module sG in {in G, forall x, \tr (sr modS x) = \sum_(W : sG) \tr (socle_repr W x) *+ socle_mult W}. Proof. move=> /= x Gx /=; pose modW (W : sG) := component_mx_module rG (socle_base W). rewrite -(mxtrace_dsum_mod modW _ (eqmx_refl _) (Socle_direct sG)) //. by apply: eq_bigr => W _; rewrite (mxtrace_component (socle_simple W)). Qed. End Socle. Section Clifford. Variables (gT : finGroupType) (G H : {group gT}). Hypothesis nsHG : H <| G. Variables (n : nat) (rG : mx_representation F G n). Let sHG := normal_sub nsHG. Let nHG := normal_norm nsHG. Let rH := subg_repr rG sHG. Lemma Clifford_simple M x : mxsimple rH M -> x \in G -> mxsimple rH (M *m rG x). Proof. have modmG m U y: y \in G -> (mxmodule rH) m U -> mxmodule rH (U *m rG y). move=> Gy modU; apply/mxmoduleP=> h Hh; have Gh := subsetP sHG h Hh. rewrite -mulmxA -repr_mxM // conjgCV repr_mxM ?groupJ ?groupV // mulmxA. by rewrite submxMr ?(mxmoduleP modU) // -mem_conjg (normsP nHG). have nzmG m y (U : 'M_(m, n)): y \in G -> (U *m rG y == 0) = (U == 0). by move=> Gy; rewrite -{1}(mul0mx m (rG y)) (can_eq (repr_mxK rG Gy)). case=> [modM nzM simM] Gx; have Gx' := groupVr Gx. split=> [||U modU sUMx nzU]; rewrite ?modmG ?nzmG //. rewrite -(repr_mxKV rG Gx U) submxMr //. by rewrite (simM (U *m _)) ?modmG ?nzmG // -(repr_mxK rG Gx M) submxMr. Qed. Lemma Clifford_hom x m (U : 'M_(m, n)) : x \in 'C_G(H) -> (U <= dom_hom_mx rH (rG x))%MS. Proof. case/setIP=> Gx cHx; apply/rV_subP=> v _{U}. apply/hom_mxP=> h Hh; have Gh := subsetP sHG h Hh. by rewrite -!mulmxA /= -!repr_mxM // (centP cHx). Qed. Lemma Clifford_iso x U : x \in 'C_G(H) -> mx_iso rH U (U *m rG x). Proof. move=> cHx; have [Gx _] := setIP cHx. by exists (rG x); rewrite ?repr_mx_unit ?Clifford_hom. Qed. Lemma Clifford_iso2 x U V : mx_iso rH U V -> x \in G -> mx_iso rH (U *m rG x) (V *m rG x). Proof. case=> [f injf homUf defV] Gx; have Gx' := groupVr Gx. pose fx := rG (x^-1)%g *m f *m rG x; exists fx; last 1 first. - by rewrite !mulmxA repr_mxK //; apply: eqmxMr. - by rewrite !unitmx_mul andbC !repr_mx_unit. apply/hom_mxP=> h Hh; have Gh := subsetP sHG h Hh. rewrite -(mulmxA U) -repr_mxM // conjgCV repr_mxM ?groupJ // !mulmxA. rewrite !repr_mxK // (hom_mxP homUf) -?mem_conjg ?(normsP nHG) //=. by rewrite !repr_mxM ?invgK ?groupM // !mulmxA repr_mxKV. Qed. Lemma Clifford_componentJ M x : mxsimple rH M -> x \in G -> (component_mx rH (M *m rG x) :=: component_mx rH M *m rG x)%MS. Proof. set simH := mxsimple rH; set cH := component_mx rH. have actG: {in G, forall y M, simH M -> cH M *m rG y <= cH (M *m rG y)}%MS. move=> {M} y Gy /= M simM; have [I [U isoU def_cHM]] := component_mx_def simM. rewrite /cH def_cHM sumsmxMr; apply/sumsmx_subP=> i _. by apply: mx_iso_component; [apply: Clifford_simple | apply: Clifford_iso2]. move=> simM Gx; apply/eqmxP; rewrite actG // -/cH. rewrite -{1}[cH _](repr_mxKV rG Gx) submxMr // -{2}[M](repr_mxK rG Gx). by rewrite actG ?groupV //; apply: Clifford_simple. Qed. Hypothesis irrG : mx_irreducible rG. Lemma Clifford_basis M : mxsimple rH M -> {X : {set gT} | X \subset G & let S := \sum_(x in X) M *m rG x in S :=: 1%:M /\ mxdirect S}%MS. Proof. move=> simM. have simMG (g : [subg G]) : mxsimple rH (M *m rG (val g)). by case: g => x Gx; apply: Clifford_simple. have [|XG [defX1 dxX1]] := sum_mxsimple_direct_sub simMG (_ : _ :=: 1%:M)%MS. apply/eqmxP; case irrG => _ _ ->; rewrite ?submx1 //; last first. rewrite -submx0; apply/sumsmx_subP; move/(_ 1%g (erefl _)); apply: negP. by rewrite submx0 repr_mx1 mulmx1; case simM. apply/mxmoduleP=> x Gx; rewrite sumsmxMr; apply/sumsmx_subP=> [[y Gy]] /= _. by rewrite (sumsmx_sup (subg G (y * x)))// subgK ?groupM// -mulmxA repr_mxM. exists (val @: XG); first by apply/subsetP=> ?; case/imsetP=> [[x Gx]] _ ->. have bij_val: {on val @: XG, bijective (@sgval _ G)}. exists (subg G) => [g _ | x]; first exact: sgvalK. by case/imsetP=> [[x' Gx]] _ ->; rewrite subgK. have defXG g: (val g \in val @: XG) = (g \in XG). by apply/imsetP/idP=> [[h XGh] | XGg]; [move/val_inj-> | exists g]. by rewrite /= mxdirectE /= !(reindex _ bij_val) !(eq_bigl _ _ defXG). Qed. Variable sH : socleType rH. Definition Clifford_act (W : sH) x := let Gx := subgP (subg G x) in PackSocle (component_socle sH (Clifford_simple (socle_simple W) Gx)). Let valWact W x : (Clifford_act W x :=: W *m rG (sgval (subg G x)))%MS. Proof. rewrite PackSocleK; apply: Clifford_componentJ (subgP _). exact: socle_simple. Qed. Fact Clifford_is_action : is_action G Clifford_act. Proof. split=> [x W W' eqWW' | W x y Gx Gy]. pose Gx := subgP (subg G x); apply/socleP; apply/eqmxP. rewrite -(repr_mxK rG Gx W) -(repr_mxK rG Gx W'); apply: eqmxMr. apply: eqmx_trans (eqmx_sym _) (valWact _ _). by rewrite -eqWW'; apply: valWact. apply/socleP; rewrite !{1}valWact 2!{1}(eqmxMr _ (valWact _ _)). by rewrite !subgK ?groupM ?repr_mxM ?mulmxA ?andbb. Qed. Definition Clifford_action := Action Clifford_is_action. Local Notation "'Cl" := Clifford_action : action_scope. Lemma val_Clifford_act W x : x \in G -> ('Cl%act W x :=: W *m rG x)%MS. Proof. by move=> Gx; apply: eqmx_trans (valWact _ _) _; rewrite subgK. Qed. Lemma Clifford_atrans : [transitive G, on [set: sH] | 'Cl]. Proof. have [_ nz1 _] := irrG. apply: mxsimple_exists (mxmodule1 rH) nz1 _ _ => [[M simM _]]. pose W1 := PackSocle (component_socle sH simM). have [X sXG [def1 _]] := Clifford_basis simM; move/subsetP: sXG => sXG. apply/imsetP; exists W1; first by rewrite inE. symmetry; apply/setP=> W /[1!inE]; have simW := socle_simple W. have:= submx1 (socle_base W); rewrite -def1 -[(\sum_(x in X) _)%MS]mulmx1. case/(hom_mxsemisimple_iso simW) => [x Xx _ | | x Xx isoMxW]. - by apply: Clifford_simple; rewrite ?sXG. - exact: scalar_mx_hom. have Gx := sXG x Xx; apply/imsetP; exists x => //; apply/socleP/eqmxP/eqmx_sym. apply: eqmx_trans (val_Clifford_act _ Gx) _; rewrite PackSocleK. apply: eqmx_trans (eqmx_sym (Clifford_componentJ simM Gx)) _. apply/eqmxP; rewrite (sameP genmxP eqP) !{1}genmx_component. by apply/component_mx_isoP=> //; apply: Clifford_simple. Qed. Lemma Clifford_Socle1 : Socle sH = 1%:M. Proof. case/imsetP: Clifford_atrans => W _ _; have simW := socle_simple W. have [X sXG [def1 _]] := Clifford_basis simW. rewrite reducible_Socle1 //; apply: mxsemisimple_reducible. apply: intro_mxsemisimple def1 _ => x /(subsetP sXG) Gx _. exact: Clifford_simple. Qed. Lemma Clifford_rank_components (W : sH) : (#|sH| * \rank W)%N = n. Proof. rewrite -{9}(mxrank1 F n) -Clifford_Socle1. rewrite (mxdirectP (Socle_direct sH)) /= -sum_nat_const. apply: eq_bigr => W1 _; have [W0 _ W0G] := imsetP Clifford_atrans. have{} W0G W': W' \in orbit 'Cl G W0 by rewrite -W0G inE. have [/orbitP[x Gx <-] /orbitP[y Gy <-]] := (W0G W, W0G W1). by rewrite !{1}val_Clifford_act // !mxrankMfree // !repr_mx_free. Qed. Theorem Clifford_component_basis M : mxsimple rH M -> {t : nat & {x_ : sH -> 'I_t -> gT | forall W, let sW := (\sum_j M *m rG (x_ W j))%MS in [/\ forall j, x_ W j \in G, (sW :=: W)%MS & mxdirect sW]}}. Proof. move=> simM; pose t := (n %/ #|sH| %/ \rank M)%N; exists t. have [X /subsetP sXG [defX1 dxX1]] := Clifford_basis simM. pose sMv (W : sH) x := (M *m rG x <= W)%MS; pose Xv := [pred x in X | sMv _ x]. have sXvG W: {subset Xv W <= G} by move=> x /andP[/sXG]. have defW W: (\sum_(x in Xv W) M *m rG x :=: W)%MS. apply/eqmxP; rewrite -(geq_leqif (mxrank_leqif_eq _)); last first. by apply/sumsmx_subP=> x /andP[]. rewrite -(leq_add2r (\sum_(W' | W' != W) \rank W')) -((bigD1 W) predT) //=. rewrite -(mxdirectP (Socle_direct sH)) /= -/(Socle _) Clifford_Socle1 -defX1. apply: leq_trans (mxrankS _) (mxrank_sum_leqif _).1 => /=. rewrite (bigID (sMv W))%MS addsmxS //=. apply/sumsmx_subP=> x /andP[Xx notW_Mx]; have Gx := sXG x Xx. have simMx := Clifford_simple simM Gx. pose Wx := PackSocle (component_socle sH simMx). have sMxWx: (M *m rG x <= Wx)%MS by rewrite PackSocleK component_mx_id. by rewrite (sumsmx_sup Wx) //; apply: contra notW_Mx => /eqP <-. have dxXv W: mxdirect (\sum_(x in Xv W) M *m rG x). move: dxX1; rewrite !mxdirectE /= !(bigID (sMv W) [in X]) /=. by rewrite -mxdirectE mxdirect_addsE /= => /andP[]. have def_t W: #|Xv W| = t. rewrite /t -{1}(Clifford_rank_components W) mulKn 1?(cardD1 W) //. rewrite -defW (mxdirectP (dxXv W)) /= (eq_bigr (fun _ => \rank M)) => [|x]. rewrite sum_nat_const mulnK //; last by rewrite lt0n mxrank_eq0; case simM. by move/sXvG=> Gx; rewrite mxrankMfree // row_free_unit repr_mx_unit. exists (fun W i => enum_val (cast_ord (esym (def_t W)) i)) => W. case: {def_t}t / (def_t W) => sW. case: (pickP (Xv W)) => [x0 XvWx0 | XvW0]; last first. by case/negP: (nz_socle W); rewrite -submx0 -defW big_pred0. have{x0 XvWx0} reXv := reindex _ (enum_val_bij_in XvWx0). have def_sW: (sW :=: W)%MS. apply: eqmx_trans (defW W); apply/eqmxP; apply/genmxP; congr <<_>>%MS. rewrite reXv /=; apply: eq_big => [j | j _]; first by have:= enum_valP j. by rewrite cast_ord_id. split=> // [j|]; first by rewrite (sXvG W) ?enum_valP. apply/mxdirectP; rewrite def_sW -(defW W) /= (mxdirectP (dxXv W)) /= reXv /=. by apply: eq_big => [j | j _]; [move: (enum_valP j) | rewrite cast_ord_id]. Qed. Lemma Clifford_astab : H <*> 'C_G(H) \subset 'C([set: sH] | 'Cl). Proof. rewrite join_subG !subsetI sHG subsetIl /=; apply/andP; split. apply/subsetP=> h Hh /[1!inE]; have Gh := subsetP sHG h Hh. apply/subsetP=> W _; have simW := socle_simple W; have [modW _ _] := simW. have simWh: mxsimple rH (socle_base W *m rG h) by apply: Clifford_simple. rewrite inE -val_eqE /= PackSocleK eq_sym. apply/component_mx_isoP; rewrite ?subgK //; apply: component_mx_iso => //. by apply: submx_trans (component_mx_id simW); move/mxmoduleP: modW => ->. apply/subsetP=> z cHz /[1!inE]; have [Gz _] := setIP cHz. apply/subsetP=> W _; have simW := socle_simple W; have [modW _ _] := simW. have simWz: mxsimple rH (socle_base W *m rG z) by apply: Clifford_simple. rewrite inE -val_eqE /= PackSocleK eq_sym. by apply/component_mx_isoP; rewrite ?subgK //; apply: Clifford_iso. Qed. Lemma Clifford_astab1 (W : sH) : 'C[W | 'Cl] = rstabs rG W. Proof. apply/setP=> x /[!inE]; apply: andb_id2l => Gx. rewrite sub1set inE (sameP eqP socleP) !val_Clifford_act //. rewrite andb_idr // => sWxW; rewrite -mxrank_leqif_sup //. by rewrite mxrankMfree ?repr_mx_free. Qed. Lemma Clifford_rstabs_simple (W : sH) : mxsimple (subg_repr rG (rstabs_sub rG W)) W. Proof. split => [||U modU sUW nzU]; last 2 [exact: nz_socle]. by rewrite /mxmodule rstabs_subg setIid. have modUH: mxmodule rH U. apply/mxmoduleP=> h Hh; rewrite (mxmoduleP modU) //. rewrite /= -Clifford_astab1 !(inE, sub1set) (subsetP sHG) //. rewrite (astab_act (subsetP Clifford_astab h _)) ?inE //=. by rewrite mem_gen // inE Hh. apply: (mxsimple_exists modUH nzU) => [[M simM sMU]]. have [t [x_ /(_ W)[Gx_ defW _]]] := Clifford_component_basis simM. rewrite -defW; apply/sumsmx_subP=> j _; set x := x_ W j. have{Gx_} Gx: x \in G by rewrite Gx_. apply: submx_trans (submxMr _ sMU) _; apply: (mxmoduleP modU). rewrite inE -val_Clifford_act Gx //; set Wx := 'Cl%act W x. case: (eqVneq Wx W) (simM) => [-> //=|] neWxW [_ /negP[]]; rewrite -submx0. rewrite (canF_eq (actKin 'Cl Gx)) in neWxW. rewrite -(component_mx_disjoint _ _ neWxW); try exact: socle_simple. rewrite sub_capmx {1}(submx_trans sMU sUW) val_Clifford_act ?groupV //. by rewrite -(eqmxMr _ defW) sumsmxMr (sumsmx_sup j) ?repr_mxK. Qed. End Clifford. Section JordanHolder. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation F G n). Local Notation modG := ((mxmodule rG) n). Lemma section_module (U V : 'M_n) (modU : modG U) (modV : modG V) : mxmodule (factmod_repr modU) <<in_factmod U V>>%MS. Proof. by rewrite (eqmx_module _ (genmxE _)) in_factmod_module addsmx_module. Qed. Definition section_repr U V (modU : modG U) (modV : modG V) := submod_repr (section_module modU modV). Lemma mx_factmod_sub U modU : mx_rsim (@section_repr U _ modU (mxmodule1 rG)) (factmod_repr modU). Proof. exists (val_submod 1%:M) => [||x Gx]. - apply: (@addIn (\rank U)); rewrite genmxE mxrank_in_factmod mxrank_coker. by rewrite (addsmx_idPr (submx1 U)) mxrank1 subnK ?rank_leq_row. - by rewrite /row_free val_submod1. by rewrite -[_ x]mul1mx -val_submodE val_submodJ. Qed. Definition max_submod (U V : 'M_n) := (U < V)%MS /\ (forall W, ~ [/\ modG W, U < W & W < V])%MS. Lemma max_submodP U V (modU : modG U) (modV : modG V) : (U <= V)%MS -> (max_submod U V <-> mx_irreducible (section_repr modU modV)). Proof. move=> sUV; split=> [[ltUV maxU] | ]. apply/mx_irrP; split=> [|WU modWU nzWU]. by rewrite genmxE lt0n mxrank_eq0 in_factmod_eq0; case/andP: ltUV. rewrite -sub1mx -val_submodS val_submod1 genmxE. pose W := (U + val_factmod (val_submod WU))%MS. suffices sVW: (V <= W)%MS. rewrite {2}in_factmodE (submx_trans (submxMr _ sVW)) //. rewrite addsmxMr -!in_factmodE val_factmodK. by rewrite ((in_factmod U U =P 0) _) ?adds0mx ?in_factmod_eq0. move/and3P: {maxU}(maxU W); apply: contraR; rewrite /ltmx addsmxSl => -> /=. move: modWU; rewrite /mxmodule rstabs_submod rstabs_factmod => -> /=. rewrite addsmx_sub submx_refl -in_factmod_eq0 val_factmodK. move: nzWU; rewrite -[_ == 0](inj_eq val_submod_inj) linear0 => ->. rewrite -(in_factmodsK sUV) addsmxS // val_factmodS. by rewrite -(genmxE (in_factmod U V)) val_submodP. case/mx_irrP; rewrite lt0n {1}genmxE mxrank_eq0 in_factmod_eq0 => ltUV maxV. split=> // [|W [modW /andP[sUW ltUW] /andP[sWV /negP[]]]]; first exact/andP. rewrite -(in_factmodsK sUV) -(in_factmodsK sUW) addsmxS // val_factmodS. rewrite -genmxE -val_submod1; set VU := <<_>>%MS. have sW_VU: (in_factmod U W <= VU)%MS. by rewrite genmxE -val_factmodS !submxMr. rewrite -(in_submodK sW_VU) val_submodS -(genmxE (in_submod _ _)). rewrite sub1mx maxV //. rewrite (eqmx_module _ (genmxE _)) in_submod_module ?genmxE ?submxMr //. by rewrite in_factmod_module addsmx_module. rewrite -submx0 [(_ <= 0)%MS]genmxE -val_submodS linear0 in_submodK //. by rewrite eqmx0 submx0 in_factmod_eq0. Qed. Lemma max_submod_eqmx U1 U2 V1 V2 : (U1 :=: U2)%MS -> (V1 :=: V2)%MS -> max_submod U1 V1 -> max_submod U2 V2. Proof. move=> eqU12 eqV12 [ltUV1 maxU1]. by split=> [|W]; rewrite -(lt_eqmx eqU12) -(lt_eqmx eqV12). Qed. Definition mx_subseries := all modG. Definition mx_composition_series V := mx_subseries V /\ (forall i, i < size V -> max_submod (0 :: V)`_i V`_i). Local Notation mx_series := mx_composition_series. Fact mx_subseries_module V i : mx_subseries V -> mxmodule rG V`_i. Proof. move=> modV; have [|leVi] := ltnP i (size V); first exact: all_nthP. by rewrite nth_default ?mxmodule0. Qed. Fact mx_subseries_module' V i : mx_subseries V -> mxmodule rG (0 :: V)`_i. Proof. by move=> modV; rewrite mx_subseries_module //= mxmodule0. Qed. Definition subseries_repr V i (modV : all modG V) := section_repr (mx_subseries_module' i modV) (mx_subseries_module i modV). Definition series_repr V i (compV : mx_composition_series V) := subseries_repr i (proj1 compV). Lemma mx_series_lt V : mx_composition_series V -> path ltmx 0 V. Proof. by case=> _ compV; apply/(pathP 0)=> i /compV[]. Qed. Lemma max_size_mx_series (V : seq 'M[F]_n) : path ltmx 0 V -> size V <= \rank (last 0 V). Proof. rewrite -[size V]addn0 -(mxrank0 F n n); elim: V 0 => //= V1 V IHV V0. rewrite ltmxErank -andbA => /and3P[_ ltV01 ltV]. by apply: leq_trans (IHV _ ltV); rewrite addSnnS leq_add2l. Qed. Lemma mx_series_repr_irr V i (compV : mx_composition_series V) : i < size V -> mx_irreducible (series_repr i compV). Proof. case: compV => modV compV /compV maxVi; apply/max_submodP => //. by apply: ltmxW; case: maxVi. Qed. Lemma mx_series_rcons U V : mx_series (rcons U V) <-> [/\ mx_series U, modG V & max_submod (last 0 U) V]. Proof. rewrite /mx_series /mx_subseries all_rcons size_rcons -rcons_cons. split=> [ [/andP[modU modV] maxU] | [[modU maxU] modV maxV]]. split=> //; last first. by have:= maxU _ (leqnn _); rewrite !nth_rcons leqnn ltnn eqxx -last_nth. by split=> // i ltiU; have:= maxU i (ltnW ltiU); rewrite !nth_rcons leqW ltiU. rewrite modV; split=> // i; rewrite !nth_rcons ltnS leq_eqVlt. case: eqP => [-> _ | /= _ ltiU]; first by rewrite ltnn ?eqxx -last_nth. by rewrite ltiU; apply: maxU. Qed. Theorem mx_Schreier U : mx_subseries U -> path ltmx 0 U -> classically (exists V, [/\ mx_series V, last 0 V :=: 1%:M & subseq U V])%MS. Proof. move: U => U0; set U := {1 2}U0; have: subseq U0 U := subseq_refl U. pose n' := n.+1; have: n < size U + n' by rewrite leq_addl. elim: n' U => [|n' IH_U] U ltUn' sU0U modU incU [] // noV. rewrite addn0 ltnNge in ltUn'; case/negP: ltUn'. by rewrite (leq_trans (max_size_mx_series incU)) ?rank_leq_row. apply: (noV); exists U; split => //; first split=> // i lt_iU; last first. apply/eqmxP; apply: contraT => neU1. apply: {IH_U}(IH_U (rcons U 1%:M)) noV. - by rewrite size_rcons addSnnS. - by rewrite (subseq_trans sU0U) ?subseq_rcons. - by rewrite /mx_subseries all_rcons mxmodule1. by rewrite rcons_path ltmxEneq neU1 submx1 !andbT. set U'i := _`_i; set Ui := _`_i; have defU := cat_take_drop i U. have defU'i: U'i = last 0 (take i U). rewrite (last_nth 0) /U'i -{1}defU -cat_cons nth_cat /=. by rewrite size_take lt_iU leqnn. move: incU; rewrite -defU cat_path (drop_nth 0) //= -/Ui -defU'i. set U' := take i U; set U'' := drop _ U; case/and3P=> incU' ltUi incU''. split=> // W [modW ltUW ltWV]; case: notF. apply: {IH_U}(IH_U (U' ++ W :: Ui :: U'')) noV; last 2 first. - by rewrite /mx_subseries -drop_nth // all_cat /= modW -all_cat defU. - by rewrite cat_path /= -defU'i; apply/and4P. - by rewrite -drop_nth // size_cat /= addnS -size_cat defU addSnnS. by rewrite (subseq_trans sU0U) // -defU cat_subseq // -drop_nth ?subseq_cons. Qed. Lemma mx_second_rsim U V (modU : modG U) (modV : modG V) : let modI := capmx_module modU modV in let modA := addsmx_module modU modV in mx_rsim (section_repr modI modU) (section_repr modV modA). Proof. move=> modI modA; set nI := {1}(\rank _). have sIU := capmxSl U V; have sVA := addsmxSr U V. pose valI := val_factmod (val_submod (1%:M : 'M_nI)). have UvalI: (valI <= U)%MS. rewrite -(addsmx_idPr sIU) (submx_trans _ (proj_factmodS _ _)) //. by rewrite submxMr // val_submod1 genmxE. exists (valI *m in_factmod _ 1%:M *m in_submod _ 1%:M) => [||x Gx]. - apply: (@addIn (\rank (U :&: V) + \rank V)%N); rewrite genmxE addnA addnCA. rewrite /nI genmxE !{1}mxrank_in_factmod 2?(addsmx_idPr _) //. by rewrite -mxrank_sum_cap addnC. - rewrite -kermx_eq0; apply/rowV0P=> u; rewrite (sameP sub_kermxP eqP). rewrite mulmxA -in_submodE mulmxA -in_factmodE -(inj_eq val_submod_inj). rewrite linear0 in_submodK ?in_factmod_eq0 => [Vvu|]; last first. by rewrite genmxE addsmxC in_factmod_addsK submxMr // mulmx_sub. apply: val_submod_inj; apply/eqP; rewrite linear0 -[val_submod u]val_factmodK. rewrite val_submodE val_factmodE -mulmxA -val_factmodE -/valI. by rewrite in_factmod_eq0 sub_capmx mulmx_sub. symmetry; rewrite -{1}in_submodE -{1}in_submodJ; last first. by rewrite genmxE addsmxC in_factmod_addsK -in_factmodE submxMr. rewrite -{1}in_factmodE -{1}in_factmodJ // mulmxA in_submodE; congr (_ *m _). apply/eqP; rewrite mulmxA -in_factmodE -subr_eq0 -linearB in_factmod_eq0. apply: submx_trans (capmxSr U V); rewrite -in_factmod_eq0 linearB /=. rewrite subr_eq0 {1}(in_factmodJ modI) // val_factmodK eq_sym. rewrite /valI val_factmodE mulmxA -val_factmodE val_factmodK. by rewrite -[submod_mx _ _]mul1mx -val_submodE val_submodJ. Qed. Lemma section_eqmx_add U1 U2 V1 V2 modU1 modU2 modV1 modV2 : (U1 :=: U2)%MS -> (U1 + V1 :=: U2 + V2)%MS -> mx_rsim (@section_repr U1 V1 modU1 modV1) (@section_repr U2 V2 modU2 modV2). Proof. move=> eqU12 eqV12; set n1 := {1}(\rank _). pose v1 := val_factmod (val_submod (1%:M : 'M_n1)). have sv12: (v1 <= U2 + V2)%MS. rewrite -eqV12 (submx_trans _ (proj_factmodS _ _)) //. by rewrite submxMr // val_submod1 genmxE. exists (v1 *m in_factmod _ 1%:M *m in_submod _ 1%:M) => [||x Gx]. - apply: (@addIn (\rank U1)); rewrite {2}eqU12 /n1 !{1}genmxE. by rewrite !{1}mxrank_in_factmod eqV12. - rewrite -kermx_eq0; apply/rowV0P=> u; rewrite (sameP sub_kermxP eqP) mulmxA. rewrite -in_submodE mulmxA -in_factmodE -(inj_eq val_submod_inj) linear0. rewrite in_submodK ?in_factmod_eq0 -?eqU12 => [U1uv1|]; last first. by rewrite genmxE -(in_factmod_addsK U2 V2) submxMr // mulmx_sub. apply: val_submod_inj; apply/eqP; rewrite linear0 -[val_submod _]val_factmodK. by rewrite in_factmod_eq0 val_factmodE val_submodE -mulmxA -val_factmodE. symmetry; rewrite -{1}in_submodE -{1}in_factmodE -{1}in_submodJ; last first. by rewrite genmxE -(in_factmod_addsK U2 V2) submxMr. rewrite -{1}in_factmodJ // mulmxA in_submodE; congr (_ *m _); apply/eqP. rewrite mulmxA -in_factmodE -subr_eq0 -linearB in_factmod_eq0 -eqU12. rewrite -in_factmod_eq0 linearB /= subr_eq0 {1}(in_factmodJ modU1) //. rewrite val_factmodK /v1 val_factmodE eq_sym mulmxA -val_factmodE val_factmodK. by rewrite -[_ *m _]mul1mx mulmxA -val_submodE val_submodJ. Qed. Lemma section_eqmx U1 U2 V1 V2 modU1 modU2 modV1 modV2 (eqU : (U1 :=: U2)%MS) (eqV : (V1 :=: V2)%MS) : mx_rsim (@section_repr U1 V1 modU1 modV1) (@section_repr U2 V2 modU2 modV2). Proof. by apply: section_eqmx_add => //; apply: adds_eqmx. Qed. Lemma mx_butterfly U V W modU modV modW : ~~ (U == V)%MS -> max_submod U W -> max_submod V W -> let modUV := capmx_module modU modV in max_submod (U :&: V)%MS U /\ mx_rsim (@section_repr V W modV modW) (@section_repr _ U modUV modU). Proof. move=> neUV maxU maxV modUV; have{neUV maxU} defW: (U + V :=: W)%MS. wlog{neUV modUV} ltUV: U V modU modV maxU maxV / ~~ (V <= U)%MS. by case/nandP: neUV => ?; first rewrite addsmxC; apply. apply/eqmxP/idPn=> neUVW; case: maxU => ltUW; case/(_ (U + V)%MS). rewrite addsmx_module // ltmxE ltmxEneq neUVW addsmxSl !addsmx_sub. by have [ltVW _] := maxV; rewrite submx_refl andbT ltUV !ltmxW. have sUV_U := capmxSl U V; have sVW: (V <= W)%MS by rewrite -defW addsmxSr. set goal := mx_rsim _ _; suffices{maxV} simUV: goal. split=> //; apply/(max_submodP modUV modU sUV_U). by apply: mx_rsim_irr simUV _; apply/max_submodP. apply: {goal}mx_rsim_sym. by apply: mx_rsim_trans (mx_second_rsim modU modV) _; apply: section_eqmx. Qed. Lemma mx_JordanHolder_exists U V : mx_composition_series U -> modG V -> max_submod V (last 0 U) -> {W : seq 'M_n | mx_composition_series W & last 0 W = V}. Proof. elim/last_ind: U V => [|U Um IHU] V compU modV; first by case; rewrite ltmx0. rewrite last_rcons => maxV; case/mx_series_rcons: compU => compU modUm maxUm. case eqUV: (last 0 U == V)%MS. case/lastP: U eqUV compU {maxUm IHU} => [|U' Um']. by rewrite andbC; move/eqmx0P->; exists [::]. rewrite last_rcons; move/eqmxP=> eqU'V; case/mx_series_rcons=> compU _ maxUm'. exists (rcons U' V); last by rewrite last_rcons. by apply/mx_series_rcons; split => //; apply: max_submod_eqmx maxUm'. set Um' := last 0 U in maxUm eqUV; have [modU _] := compU. have modUm': modG Um' by rewrite /Um' (last_nth 0) mx_subseries_module'. have [|||W compW lastW] := IHU (V :&: Um')%MS; rewrite ?capmx_module //. by case: (mx_butterfly modUm' modV modUm); rewrite ?eqUV // {1}capmxC. exists (rcons W V); last by rewrite last_rcons. apply/mx_series_rcons; split; rewrite // lastW. by case: (mx_butterfly modV modUm' modUm); rewrite // andbC eqUV. Qed. Let rsim_rcons U V compU compUV i : i < size U -> mx_rsim (@series_repr U i compU) (@series_repr (rcons U V) i compUV). Proof. by move=> ltiU; apply: section_eqmx; rewrite -?rcons_cons nth_rcons ?leqW ?ltiU. Qed. Let last_mod U (compU : mx_series U) : modG (last 0 U). Proof. by case: compU => modU _; rewrite (last_nth 0) (mx_subseries_module' _ modU). Qed. Let rsim_last U V modUm modV compUV : mx_rsim (@section_repr (last 0 U) V modUm modV) (@series_repr (rcons U V) (size U) compUV). Proof. apply: section_eqmx; last by rewrite nth_rcons ltnn eqxx. by rewrite -rcons_cons nth_rcons leqnn -last_nth. Qed. Local Notation rsimT := mx_rsim_trans. Local Notation rsimC := mx_rsim_sym. Lemma mx_JordanHolder U V compU compV : let m := size U in (last 0 U :=: last 0 V)%MS -> m = size V /\ (exists p : 'S_m, forall i : 'I_m, mx_rsim (@series_repr U i compU) (@series_repr V (p i) compV)). Proof. move Dr: {-}(size U) => r; move/eqP in Dr. elim: r U V Dr compU compV => /= [|r IHr] U V. move/nilP->; case/lastP: V => [|V Vm] /= ? compVm; rewrite ?last_rcons => Vm0. by split=> //; exists 1%g; case. by case/mx_series_rcons: (compVm) => _ _ []; rewrite -(lt_eqmx Vm0) ltmx0. case/lastP: U => // [U Um]; rewrite size_rcons eqSS => szUr compUm. case/mx_series_rcons: (compUm); set Um' := last 0 U => compU modUm maxUm. case/lastP: V => [|V Vm] compVm; rewrite ?last_rcons ?size_rcons /= => eqUVm. by case/mx_series_rcons: (compUm) => _ _ []; rewrite (lt_eqmx eqUVm) ltmx0. case/mx_series_rcons: (compVm); set Vm' := last 0 V => compV modVm maxVm. have [modUm' modVm']: modG Um' * modG Vm' := (last_mod compU, last_mod compV). pose i_m := @ord_max (size U). have [eqUVm' | neqUVm'] := altP (@eqmxP _ _ _ _ Um' Vm'). have [szV [p sim_p]] := IHr U V szUr compU compV eqUVm'. split; first by rewrite szV. exists (lift_perm i_m i_m p) => i; case: (unliftP i_m i) => [j|] ->{i}. apply: rsimT (rsimC _) (rsimT (sim_p j) _). by rewrite lift_max; apply: rsim_rcons. by rewrite lift_perm_lift lift_max; apply: rsim_rcons; rewrite -szV. have simUVm := section_eqmx modUm' modVm' modUm modVm eqUVm' eqUVm. apply: rsimT (rsimC _) (rsimT simUVm _); first exact: rsim_last. by rewrite lift_perm_id /= szV; apply: rsim_last. have maxVUm: max_submod Vm' Um by apply: max_submod_eqmx (eqmx_sym _) maxVm. have:= mx_butterfly modUm' modVm' modUm neqUVm' maxUm maxVUm. move: (capmx_module _ _); set Wm := (Um' :&: Vm')%MS => modWm [maxWUm simWVm]. have:= mx_butterfly modVm' modUm' modUm _ maxVUm maxUm. move: (capmx_module _ _); rewrite andbC capmxC -/Wm => modWmV [// | maxWVm]. rewrite {modWmV}(bool_irrelevance modWmV modWm) => simWUm. have [W compW lastW] := mx_JordanHolder_exists compU modWm maxWUm. have compWU: mx_series (rcons W Um') by apply/mx_series_rcons; rewrite lastW. have compWV: mx_series (rcons W Vm') by apply/mx_series_rcons; rewrite lastW. have [|szW [pU pUW]] := IHr U _ szUr compU compWU; first by rewrite last_rcons. rewrite size_rcons in szW; have ltWU: size W < size U by rewrite -szW. have{IHr} := IHr _ V _ compWV compV; rewrite last_rcons size_rcons -szW. case=> {r szUr}// szV [pV pWV]; split; first by rewrite szV. pose j_m := Ordinal ltWU; pose i_m' := lift i_m j_m. exists (lift_perm i_m i_m pU * tperm i_m i_m' * lift_perm i_m i_m pV)%g => i. rewrite !permM; case: (unliftP i_m i) => [j {simWUm}|] ->{i}; last first. rewrite lift_perm_id tpermL lift_perm_lift lift_max {simWVm}. apply: rsimT (rsimT (pWV j_m) _); last by apply: rsim_rcons; rewrite -szV. apply: rsimT (rsimC _) {simWUm}(rsimT simWUm _); first exact: rsim_last. by rewrite -lastW in modWm *; apply: rsim_last. apply: rsimT (rsimC _) {pUW}(rsimT (pUW j) _). by rewrite lift_max; apply: rsim_rcons. rewrite lift_perm_lift; case: (unliftP j_m (pU j)) => [k|] ->{j pU}. rewrite tpermD ?(inj_eq lift_inj) ?neq_lift //. rewrite lift_perm_lift !lift_max; set j := lift j_m k. have ltjW: j < size W by have:= ltn_ord k; rewrite -(lift_max k) /= {1 3}szW. apply: rsimT (rsimT (pWV j) _); last by apply: rsim_rcons; rewrite -szV. by apply: rsimT (rsimC _) (rsim_rcons compW _ _); first apply: rsim_rcons. apply: rsimT {simWVm}(rsimC (rsimT simWVm _)) _. by rewrite -lastW in modWm *; apply: rsim_last. rewrite tpermR lift_perm_id /= szV. by apply: rsimT (rsim_last modVm' modVm _); apply: section_eqmx. Qed. Lemma mx_JordanHolder_max U (m := size U) V compU modV : (last 0 U :=: 1%:M)%MS -> mx_irreducible (@factmod_repr _ G n rG V modV) -> exists i : 'I_m, mx_rsim (factmod_repr modV) (@series_repr U i compU). Proof. rewrite {}/m; set Um := last 0 U => Um1 irrV. have modUm: modG Um := last_mod compU; have simV := rsimC (mx_factmod_sub modV). have maxV: max_submod V Um. move/max_submodP: (mx_rsim_irr simV irrV) => /(_ (submx1 _)). by apply: max_submod_eqmx; last apply: eqmx_sym. have [W compW lastW] := mx_JordanHolder_exists compU modV maxV. have compWU: mx_series (rcons W Um) by apply/mx_series_rcons; rewrite lastW. have:= mx_JordanHolder compU compWU; rewrite last_rcons size_rcons. case=> // szW [p pUW]; have ltWU: size W < size U by rewrite szW. pose i := Ordinal ltWU; exists ((p^-1)%g i). apply: rsimT simV (rsimT _ (rsimC (pUW _))); rewrite permKV. apply: rsimT (rsimC _) (rsim_last (last_mod compW) modUm _). by apply: section_eqmx; rewrite ?lastW. Qed. End JordanHolder. Bind Scope irrType_scope with socle_sort. Section Regular. Variables (gT : finGroupType) (G : {group gT}). Local Notation nG := #|pred_of_set (gval G)|. Local Notation aG := (regular_repr F G). Local Notation R_G := (group_ring F G). Lemma gring_free : row_free R_G. Proof. apply/row_freeP; exists (lin1_mx (row (gring_index G 1) \o vec_mx)). apply/row_matrixP=> i; rewrite row_mul rowK mul_rV_lin1 /= mxvecK rowK row1. by rewrite gring_indexK // mul1g gring_valK. Qed. Lemma gring_op_id A : (A \in R_G)%MS -> gring_op aG A = A. Proof. case/envelop_mxP=> a ->{A}; rewrite linear_sum. by apply: eq_bigr => x Gx; rewrite linearZ /= gring_opG. Qed. Lemma gring_rowK A : (A \in R_G)%MS -> gring_mx aG (gring_row A) = A. Proof. exact: gring_op_id. Qed. Lemma mem_gring_mx m a (M : 'M_(m, nG)) : (gring_mx aG a \in M *m R_G)%MS = (a <= M)%MS. Proof. by rewrite vec_mxK submxMfree ?gring_free. Qed. Lemma mem_sub_gring m A (M : 'M_(m, nG)) : (A \in M *m R_G)%MS = (A \in R_G)%MS && (gring_row A <= M)%MS. Proof. rewrite -(andb_idl (memmx_subP (submxMl _ _) A)); apply: andb_id2l => R_A. by rewrite -mem_gring_mx gring_rowK. Qed. Section GringMx. Variables (n : nat) (rG : mx_representation F G n). Lemma gring_mxP a : (gring_mx rG a \in enveloping_algebra_mx rG)%MS. Proof. by rewrite vec_mxK submxMl. Qed. Lemma gring_opM A B : (B \in R_G)%MS -> gring_op rG (A *m B) = gring_op rG A *m gring_op rG B. Proof. by move=> R_B; rewrite -gring_opJ gring_rowK. Qed. Hypothesis irrG : mx_irreducible rG. Lemma rsim_regular_factmod : {U : 'M_nG & {modU : mxmodule aG U & mx_rsim rG (factmod_repr modU)}}. Proof. pose v : 'rV[F]_n := nz_row 1%:M. pose fU := lin1_mx (mulmx v \o gring_mx rG); pose U := kermx fU. have modU: mxmodule aG U. apply/mxmoduleP => x Gx; apply/sub_kermxP/row_matrixP=> i. rewrite 2!row_mul row0; move: (row i U) (sub_kermxP (row_sub i U)) => u. by rewrite !mul_rV_lin1 /= gring_mxJ // mulmxA => ->; rewrite mul0mx. have def_n: \rank (cokermx U) = n. apply/eqP; rewrite mxrank_coker mxrank_ker subKn ?rank_leq_row // -genmxE. rewrite -[_ == _]sub1mx; have [_ _ ->] := irrG; rewrite ?submx1 //. rewrite (eqmx_module _ (genmxE _)); apply/mxmoduleP=> x Gx. apply/row_subP=> i; apply: eq_row_sub (gring_index G (enum_val i * x)) _. rewrite !rowE mulmxA !mul_rV_lin1 /= -mulmxA -gring_mxJ //. by rewrite -rowE rowK. rewrite (eqmx_eq0 (genmxE _)); apply/rowV0Pn. exists v; last exact: (nz_row_mxsimple irrG). apply/submxP; exists (gring_row (aG 1%g)); rewrite mul_rV_lin1 /=. by rewrite -gring_opE gring_opG // repr_mx1 mulmx1. exists U; exists modU; apply: mx_rsim_sym. exists (val_factmod 1%:M *m fU) => // [|x Gx]. rewrite /row_free eqn_leq rank_leq_row /= -subn_eq0 -mxrank_ker mxrank_eq0. apply/rowV0P=> u /sub_kermxP; rewrite mulmxA => /sub_kermxP. by rewrite -/U -in_factmod_eq0 mulmxA mulmx1 val_factmodK => /eqP. rewrite mulmxA -val_factmodE (canRL (addKr _) (add_sub_fact_mod U _)). rewrite mulmxDl mulNmx (sub_kermxP (val_submodP _)) oppr0 add0r. apply/row_matrixP=> i; move: (val_factmod _) => zz. by rewrite !row_mul !mul_rV_lin1 /= gring_mxJ // mulmxA. Qed. Lemma rsim_regular_series U (compU : mx_composition_series aG U) : (last 0 U :=: 1%:M)%MS -> exists i : 'I_(size U), mx_rsim rG (series_repr i compU). Proof. move=> lastU; have [V [modV simGV]] := rsim_regular_factmod. have irrV := mx_rsim_irr simGV irrG. have [i simVU] := mx_JordanHolder_max compU lastU irrV. by exists i; apply: mx_rsim_trans simGV simVU. Qed. Hypothesis F'G : [pchar F]^'.-group G. Lemma rsim_regular_submod_pchar : {U : 'M_nG & {modU : mxmodule aG U & mx_rsim rG (submod_repr modU)}}. Proof. have [V [modV eqG'V]] := rsim_regular_factmod. have [U modU defVU dxVU] := mx_Maschke_pchar F'G modV (submx1 V). exists U; exists modU; apply: mx_rsim_trans eqG'V _. by apply: mx_rsim_factmod; rewrite ?mxdirectE /= addsmxC // addnC. Qed. End GringMx. Definition gset_mx (A : {set gT}) := \sum_(x in A) aG x. Local Notation tG := #|pred_of_set (classes (gval G))|. Definition classg_base := \matrix_(k < tG) mxvec (gset_mx (enum_val k)). Let groupCl : {in G, forall x, {subset x ^: G <= G}}. Proof. by move=> x Gx; apply: subsetP; apply: class_subG. Qed. Lemma classg_base_free : row_free classg_base. Proof. rewrite -kermx_eq0; apply/rowV0P=> v /sub_kermxP; rewrite mulmx_sum_row => v0. apply/rowP=> k /[1!mxE]. have [x Gx def_k] := imsetP (enum_valP k). transitivity (@gring_proj F _ G x (vec_mx 0) 0 0); last first. by rewrite !linear0 !mxE. rewrite -{}v0 !linear_sum (bigD1 k) //= 2!linearZ /= rowK mxvecK def_k. rewrite linear_sum (bigD1 x) ?class_refl //= gring_projE // eqxx. rewrite !big1 ?addr0 ?mxE ?mulr1 // => [k' | y /andP[xGy ne_yx]]; first 1 last. by rewrite gring_projE ?(groupCl Gx xGy) // eq_sym (negPf ne_yx). rewrite rowK 2!linearZ /= mxvecK -(inj_eq enum_val_inj) def_k eq_sym. have [z Gz ->] := imsetP (enum_valP k'). move/eqP=> not_Gxz; rewrite linear_sum big1 ?scaler0 //= => y zGy. rewrite gring_projE ?(groupCl Gz zGy) //. by case: eqP zGy => // <- /class_eqP. Qed. Lemma classg_base_center : (classg_base :=: 'Z(R_G))%MS. Proof. apply/eqmxP/andP; split. apply/row_subP=> k; rewrite rowK /gset_mx sub_capmx {1}linear_sum. have [x Gx ->{k}] := imsetP (enum_valP k); have sxGG := groupCl Gx. rewrite summx_sub => [|y xGy]; last by rewrite envelop_mx_id ?sxGG. rewrite memmx_cent_envelop; apply/centgmxP=> y Gy. rewrite {2}(reindex_acts 'J _ Gy) ?astabsJ ?class_norm //=. rewrite mulmx_suml mulmx_sumr; apply: eq_bigr => z; move/sxGG=> Gz. by rewrite -!repr_mxM ?groupJ -?conjgC. apply/memmx_subP=> A; rewrite sub_capmx memmx_cent_envelop. case/andP=> /envelop_mxP[a ->{A}] cGa. rewrite (partition_big_imset (class^~ G)) -/(classes G) /=. rewrite linear_sum summx_sub //= => xG GxG; have [x Gx def_xG] := imsetP GxG. apply: submx_trans (scalemx_sub (a x) (submx_refl _)). rewrite (eq_row_sub (enum_rank_in GxG xG)) // linearZ /= rowK enum_rankK_in //. rewrite !linear_sum {xG GxG}def_xG; apply: eq_big => [y | xy] /=. apply/idP/andP=> [| [_ xGy]]; last by rewrite -(eqP xGy) class_refl. by case/imsetP=> z Gz ->; rewrite groupJ // classGidl. case/imsetP=> y Gy ->{xy}; rewrite linearZ; congr (_ *: _). move/(canRL (repr_mxK aG Gy)): (centgmxP cGa y Gy); have Gy' := groupVr Gy. move/(congr1 (gring_proj x)); rewrite -mulmxA mulmx_suml !linear_sum. rewrite (bigD1 x Gx) big1 => [|z /andP[Gz]]; rewrite linearZ /=; last first. by rewrite eq_sym gring_projE // => /negPf->; rewrite scaler0. rewrite gring_projE // eqxx scalemx1 (bigD1 (x ^ y)%g) ?groupJ //=. rewrite big1 => [|z /andP[Gz]]; rewrite -scalemxAl 2!linearZ /=. rewrite !addr0 -!repr_mxM ?groupM // mulgA mulKVg mulgK => /rowP/(_ 0). by rewrite gring_projE // eqxx scalemx1 !mxE. rewrite eq_sym -(can_eq (conjgKV y)) conjgK conjgE invgK. by rewrite -!repr_mxM ?gring_projE ?groupM // => /negPf->; rewrite scaler0. Qed. Lemma regular_module_ideal m (M : 'M_(m, nG)) : mxmodule aG M = right_mx_ideal R_G (M *m R_G). Proof. apply/idP/idP=> modM. apply/mulsmx_subP=> A B; rewrite !mem_sub_gring => /andP[R_A M_A] R_B. by rewrite envelop_mxM // gring_row_mul (mxmodule_envelop modM). apply/mxmoduleP=> x Gx; apply/row_subP=> i; rewrite row_mul -mem_gring_mx. rewrite gring_mxJ // (mulsmx_subP modM) ?envelop_mx_id //. by rewrite mem_gring_mx row_sub. Qed. Definition irrType := socleType aG. Identity Coercion type_of_irrType : irrType >-> socleType. Variable sG : irrType. Definition irr_degree (i : sG) := \rank (socle_base i). Local Notation "'n_ i" := (irr_degree i) : group_ring_scope. Local Open Scope group_ring_scope. Lemma irr_degreeE i : 'n_i = \rank (socle_base i). Proof. by []. Qed. Lemma irr_degree_gt0 i : 'n_i > 0. Proof. by rewrite lt0n mxrank_eq0; case: (socle_simple i). Qed. Definition irr_repr i : mx_representation F G 'n_i := socle_repr i. Lemma irr_reprE i x : irr_repr i x = submod_mx (socle_module i) x. Proof. by []. Qed. Lemma rfix_regular : (rfix_mx aG G :=: gring_row (gset_mx G))%MS. Proof. apply/eqmxP/andP; split; last first. apply/rfix_mxP => x Gx; rewrite -gring_row_mul; congr gring_row. rewrite {2}/gset_mx (reindex_astabs 'R x) ?astabsR //= mulmx_suml. by apply: eq_bigr => y Gy; rewrite repr_mxM. apply/rV_subP=> v /rfix_mxP cGv. have /envelop_mxP[a def_v]: (gring_mx aG v \in R_G)%MS. by rewrite vec_mxK submxMl. suffices ->: v = a 1%g *: gring_row (gset_mx G) by rewrite scalemx_sub. rewrite -linearZ scaler_sumr -[v]gring_mxK def_v; congr (gring_row _). apply: eq_bigr => x Gx; congr (_ *: _). move/rowP/(_ 0): (congr1 (gring_proj x \o gring_mx aG) (cGv x Gx)). rewrite /= gring_mxJ // def_v mulmx_suml !linear_sum (bigD1 1%g) //=. rewrite repr_mx1 -scalemxAl mul1mx linearZ /= gring_projE // eqxx scalemx1. rewrite big1 ?addr0 ?mxE /= => [ | y /andP[Gy nt_y]]; last first. rewrite -scalemxAl linearZ -repr_mxM //= gring_projE ?groupM //. by rewrite eq_sym eq_mulgV1 mulgK (negPf nt_y) scaler0. rewrite (bigD1 x) //= linearZ /= gring_projE // eqxx scalemx1. rewrite big1 ?addr0 ?mxE // => y /andP[Gy ne_yx]. by rewrite linearZ /= gring_projE // eq_sym (negPf ne_yx) scaler0. Qed. Lemma principal_comp_subproof : mxsimple aG (rfix_mx aG G). Proof. apply: linear_mxsimple; first exact: rfix_mx_module. apply/eqP; rewrite rfix_regular eqn_leq rank_leq_row lt0n mxrank_eq0. apply/eqP => /(congr1 (gring_proj 1 \o gring_mx aG)); apply/eqP. rewrite /= -[gring_mx _ _]/(gring_op _ _) !linear0 !linear_sum (bigD1 1%g) //=. rewrite gring_opG ?gring_projE // eqxx big1 ?addr0 ?oner_eq0 // => x. by case/andP=> Gx nt_x; rewrite gring_opG // gring_projE // eq_sym (negPf nt_x). Qed. Fact principal_comp_key : unit. Proof. by []. Qed. Definition principal_comp_def := PackSocle (component_socle sG principal_comp_subproof). Definition principal_comp := locked_with principal_comp_key principal_comp_def. Local Notation "1" := principal_comp : irrType_scope. Lemma irr1_rfix : (1%irr :=: rfix_mx aG G)%MS. Proof. rewrite [1%irr]unlock PackSocleK; apply/eqmxP. rewrite (component_mx_id principal_comp_subproof) andbT. have [I [W isoW ->]] := component_mx_def principal_comp_subproof. apply/sumsmx_subP=> i _; have [f _ hom_f <-]:= isoW i. (* FIX ME : this takes time *) by apply/rfix_mxP=> x Gx; rewrite -(hom_mxP hom_f) // (rfix_mxP G _). Qed. Lemma rank_irr1 : \rank 1%irr = 1. Proof. apply/eqP; rewrite eqn_leq lt0n mxrank_eq0 nz_socle andbT. by rewrite irr1_rfix rfix_regular rank_leq_row. Qed. Lemma degree_irr1 : 'n_1 = 1. Proof. apply/eqP; rewrite eqn_leq irr_degree_gt0 -rank_irr1. by rewrite mxrankS ?component_mx_id //; apply: socle_simple. Qed. Definition Wedderburn_subring (i : sG) := <<i *m R_G>>%MS. Local Notation "''R_' i" := (Wedderburn_subring i) : group_ring_scope. Let sums_R : (\sum_i 'R_i :=: Socle sG *m R_G)%MS. Proof. apply/eqmxP; set R_S := (_ <= _)%MS. have sRS: R_S by apply/sumsmx_subP=> i; rewrite genmxE submxMr ?(sumsmx_sup i). rewrite sRS -(mulmxKpV sRS) mulmxA submxMr //; apply/sumsmx_subP=> i _. rewrite -(submxMfree _ _ gring_free) -(mulmxA _ _ R_G) mulmxKpV //. by rewrite (sumsmx_sup i) ?genmxE. Qed. Lemma Wedderburn_ideal i : mx_ideal R_G 'R_i. Proof. apply/andP; split; last first. rewrite /right_mx_ideal genmxE (muls_eqmx (genmxE _) (eqmx_refl _)). by rewrite -[(_ <= _)%MS]regular_module_ideal component_mx_module. apply/mulsmx_subP=> A B R_A; rewrite !genmxE !mem_sub_gring => /andP[R_B SiB]. rewrite envelop_mxM {R_A}// gring_row_mul -{R_B}(gring_rowK R_B). pose f := mulmx (gring_row A) \o gring_mx aG. rewrite -[_ *m _](mul_rV_lin1 f). suffices: (i *m lin1_mx f <= i)%MS by apply: submx_trans; rewrite submxMr. apply: hom_component_mx; first exact: socle_simple. apply/rV_subP=> v _; apply/hom_mxP=> x Gx. by rewrite !mul_rV_lin1 /f /= gring_mxJ ?mulmxA. Qed. Lemma Wedderburn_direct : mxdirect (\sum_i 'R_i)%MS. Proof. apply/mxdirectP; rewrite /= sums_R mxrankMfree ?gring_free //. rewrite (mxdirectP (Socle_direct sG)); apply: eq_bigr=> i _ /=. by rewrite genmxE mxrankMfree ?gring_free. Qed. Lemma Wedderburn_disjoint i j : i != j -> ('R_i :&: 'R_j)%MS = 0. Proof. move=> ne_ij; apply/eqP; rewrite -submx0 capmxC. by rewrite -(mxdirect_sumsP Wedderburn_direct j) // capmxS // (sumsmx_sup i). Qed. Lemma Wedderburn_annihilate i j : i != j -> ('R_i * 'R_j)%MS = 0. Proof. move=> ne_ij; apply/eqP; rewrite -submx0 -(Wedderburn_disjoint ne_ij). rewrite sub_capmx; apply/andP; split. case/andP: (Wedderburn_ideal i) => _; apply: submx_trans. by rewrite mulsmxS // genmxE submxMl. case/andP: (Wedderburn_ideal j) => idlRj _; apply: submx_trans idlRj. by rewrite mulsmxS // genmxE submxMl. Qed. Lemma Wedderburn_mulmx0 i j A B : i != j -> (A \in 'R_i)%MS -> (B \in 'R_j)%MS -> A *m B = 0. Proof. move=> ne_ij RiA RjB; apply: memmx0. by rewrite -(Wedderburn_annihilate ne_ij) mem_mulsmx. Qed. Hypothesis F'G : [pchar F]^'.-group G. Lemma irr_mx_sum_pchar : (\sum_(i : sG) i = 1%:M)%MS. Proof. by apply: reducible_Socle1; apply: mx_Maschke_pchar. Qed. Lemma Wedderburn_sum_pchar : (\sum_i 'R_i :=: R_G)%MS. Proof. by apply: eqmx_trans sums_R _; rewrite /Socle irr_mx_sum_pchar mul1mx. Qed. Definition Wedderburn_id i := vec_mx (mxvec 1%:M *m proj_mx 'R_i (\sum_(j | j != i) 'R_j)%MS). Local Notation "''e_' i" := (Wedderburn_id i) : group_ring_scope. Lemma Wedderburn_sum_id_pchar : \sum_i 'e_i = 1%:M. Proof. rewrite -linear_sum; apply: canLR mxvecK _. have: (1%:M \in R_G)%MS := envelop_mx1 aG. rewrite -Wedderburn_sum_pchar. case/(sub_dsumsmx Wedderburn_direct) => e Re -> _. apply: eq_bigr => i _; have dxR := mxdirect_sumsP Wedderburn_direct i (erefl _). rewrite (bigD1 i) // mulmxDl proj_mx_id ?Re // proj_mx_0 ?addr0 //=. by rewrite summx_sub // => j ne_ji; rewrite (sumsmx_sup j) ?Re. Qed. Lemma Wedderburn_id_mem i : ('e_i \in 'R_i)%MS. Proof. by rewrite vec_mxK proj_mx_sub. Qed. Lemma Wedderburn_is_id_pchar i : mxring_id 'R_i 'e_i. Proof. have ideRi A: (A \in 'R_i)%MS -> 'e_i *m A = A. move=> RiA; rewrite -{2}[A]mul1mx -Wedderburn_sum_id_pchar mulmx_suml. rewrite (bigD1 i) //= big1 ?addr0 // => j ne_ji. by rewrite (Wedderburn_mulmx0 ne_ji) ?Wedderburn_id_mem. split=> // [||A RiA]; first 2 [exact: Wedderburn_id_mem]. apply: contraNneq (nz_socle i) => e0. apply/rowV0P=> v; rewrite -mem_gring_mx -(genmxE (i *m _)) => /ideRi. by rewrite e0 mul0mx => /(canLR gring_mxK); rewrite linear0. rewrite -{2}[A]mulmx1 -Wedderburn_sum_id_pchar mulmx_sumr (bigD1 i) //=. rewrite big1 ?addr0 // => j; rewrite eq_sym => ne_ij. by rewrite (Wedderburn_mulmx0 ne_ij) ?Wedderburn_id_mem. Qed. Lemma Wedderburn_closed_pchar i : ('R_i * 'R_i = 'R_i)%MS. Proof. rewrite -{3}['R_i]genmx_id -/'R_i -genmx_muls; apply/genmxP. have [idlRi idrRi] := andP (Wedderburn_ideal i). apply/andP; split. by apply: submx_trans idrRi; rewrite mulsmxS // genmxE submxMl. have [_ Ri_e ideRi _] := Wedderburn_is_id_pchar i. by apply/memmx_subP=> A RiA; rewrite -[A]ideRi ?mem_mulsmx. Qed. Lemma Wedderburn_is_ring_pchar i : mxring 'R_i. Proof. rewrite /mxring /left_mx_ideal Wedderburn_closed_pchar submx_refl. by apply/mxring_idP; exists 'e_i; apply: Wedderburn_is_id_pchar. Qed. Lemma Wedderburn_min_ideal_pchar m i (E : 'A_(m, nG)) : E != 0 -> (E <= 'R_i)%MS -> mx_ideal R_G E -> (E :=: 'R_i)%MS. Proof. move=> nzE sE_Ri /andP[idlE idrE]; apply/eqmxP; rewrite sE_Ri. pose M := E *m pinvmx R_G; have defE: E = M *m R_G. by rewrite mulmxKpV // (submx_trans sE_Ri) // genmxE submxMl. have modM: mxmodule aG M by rewrite regular_module_ideal -defE. have simSi := socle_simple i; set Si := socle_base i in simSi. have [I [W isoW defW]]:= component_mx_def simSi. rewrite /'R_i /socle_val /= defW genmxE defE submxMr //. apply/sumsmx_subP=> j _. have simW := mx_iso_simple (isoW j) simSi; have [modW _ minW] := simW. have [{minW}dxWE | nzWE] := eqVneq (W j :&: M)%MS 0; last first. by rewrite (sameP capmx_idPl eqmxP) minW ?capmxSl ?capmx_module. have [_ Rei ideRi _] := Wedderburn_is_id_pchar i. have:= nzE; rewrite -submx0 => /memmx_subP[A E_A]. rewrite -(ideRi _ (memmx_subP sE_Ri _ E_A)). have:= E_A; rewrite defE mem_sub_gring => /andP[R_A M_A]. have:= Rei; rewrite genmxE mem_sub_gring => /andP[Re]. rewrite -{2}(gring_rowK Re) /socle_val defW => /sub_sumsmxP[e ->]. rewrite !(linear_sum, mulmx_suml) summx_sub //= => k _. rewrite -(gring_rowK R_A) -gring_mxA -mulmxA gring_rowK //. rewrite ((W k *m _ =P 0) _) ?linear0 ?sub0mx //. have [f _ homWf defWk] := mx_iso_trans (mx_iso_sym (isoW j)) (isoW k). rewrite -submx0 -{k defWk}(eqmxMr _ defWk) -(hom_envelop_mxC homWf) //. rewrite -(mul0mx _ f) submxMr {f homWf}// -dxWE sub_capmx. rewrite (mxmodule_envelop modW) //=; apply/row_subP=> k. rewrite row_mul -mem_gring_mx -(gring_rowK R_A) gring_mxA gring_rowK //. by rewrite -defE (memmx_subP idlE) // mem_mulsmx ?gring_mxP. Qed. Section IrrComponent. (* The component of the socle of the regular module that is associated to an *) (* irreducible representation. *) Variables (n : nat) (rG : mx_representation F G n). Local Notation E_G := (enveloping_algebra_mx rG). Let not_rsim_op0_pchar (iG j : sG) A : mx_rsim rG (socle_repr iG) -> iG != j -> (A \in 'R_j)%MS -> gring_op rG A = 0. Proof. case/mx_rsim_def=> f [f' _ hom_f] ne_iG_j RjA. transitivity (f *m in_submod _ (val_submod 1%:M *m A) *m f'). have{RjA}: (A \in R_G)%MS by rewrite -Wedderburn_sum_pchar (sumsmx_sup j). case/envelop_mxP=> a ->{A}; rewrite !(linear_sum, mulmx_suml). by apply: eq_bigr => x Gx; rewrite 4!linearZ /= -scalemxAl -hom_f ?gring_opG. rewrite (_ : _ *m A = 0) ?(linear0, mul0mx) //. apply/row_matrixP=> i; rewrite row_mul row0 -[row _ _]gring_mxK -gring_row_mul. rewrite (Wedderburn_mulmx0 ne_iG_j) ?linear0 // genmxE mem_gring_mx. by rewrite (row_subP _) // val_submod1 component_mx_id //; apply: socle_simple. Qed. Definition irr_comp := odflt 1%irr [pick i | gring_op rG 'e_i != 0]. Local Notation iG := irr_comp. Hypothesis irrG : mx_irreducible rG. Lemma rsim_irr_comp_pchar : mx_rsim rG (irr_repr iG). Proof. have [M [modM rsimM]] := rsim_regular_submod_pchar irrG F'G. have simM: mxsimple aG M. case/mx_irrP: irrG => n_gt0 minG. have [f def_n injf homf] := mx_rsim_sym rsimM. apply/(submod_mx_irr modM)/mx_irrP. split=> [|U modU nzU]; first by rewrite def_n. rewrite /row_full -(mxrankMfree _ injf) -genmxE {4}def_n. apply: minG; last by rewrite -mxrank_eq0 genmxE mxrankMfree // mxrank_eq0. rewrite (eqmx_module _ (genmxE _)); apply/mxmoduleP=> x Gx. by rewrite -mulmxA -homf // mulmxA submxMr // (mxmoduleP modU). pose i := PackSocle (component_socle sG simM). have{modM} rsimM: mx_rsim rG (socle_repr i). apply: mx_rsim_trans rsimM (mx_rsim_sym _); apply/mx_rsim_iso. apply: (component_mx_iso (socle_simple _)) => //. by rewrite [component_mx _ _]PackSocleK component_mx_id. have [<- // | ne_i_iG] := eqVneq i iG. suffices {i M simM ne_i_iG rsimM}: gring_op rG 'e_iG != 0. by rewrite (not_rsim_op0_pchar rsimM ne_i_iG) ?Wedderburn_id_mem ?eqxx. rewrite /iG; case: pickP => //= G0. suffices: rG 1%g == 0. by case/idPn; rewrite -mxrank_eq0 repr_mx1 mxrank1 -lt0n; case/mx_irrP: irrG. rewrite -gring_opG // repr_mx1 -Wedderburn_sum_id_pchar linear_sum big1 //. by move=> j _; move/eqP: (G0 j). Qed. Lemma irr_comp'_op0_pchar j A : j != iG -> (A \in 'R_j)%MS -> gring_op rG A = 0. Proof. by rewrite eq_sym; apply: not_rsim_op0_pchar rsim_irr_comp_pchar. Qed. Lemma irr_comp_envelop_pchar : ('R_iG *m lin_mx (gring_op rG) :=: E_G)%MS. Proof. apply/eqmxP/andP; split; apply/row_subP=> i. by rewrite row_mul mul_rV_lin gring_mxP. rewrite rowK /= -gring_opG ?enum_valP // -mul_vec_lin -gring_opG ?enum_valP //. rewrite vec_mxK /= -mulmxA mulmx_sub {i}//= -(eqmxMr _ Wedderburn_sum_pchar). rewrite (bigD1 iG) //= addsmxMr addsmxC [_ *m _](sub_kermxP _) ?adds0mx //=. apply/sumsmx_subP => j ne_j_iG; apply/memmx_subP=> A RjA; apply/sub_kermxP. by rewrite mul_vec_lin /= (irr_comp'_op0_pchar ne_j_iG RjA) linear0. Qed. Lemma ker_irr_comp_op_pchar : ('R_iG :&: kermx (lin_mx (gring_op rG)))%MS = 0. Proof. apply/eqP; rewrite -submx0; apply/memmx_subP=> A. rewrite sub_capmx /= submx0 mxvec_eq0 => /andP[R_A]. rewrite (sameP sub_kermxP eqP) mul_vec_lin mxvec_eq0 /= => opA0. have [_ Re ideR _] := Wedderburn_is_id_pchar iG; rewrite -[A]ideR {ideR}//. move: Re; rewrite genmxE mem_sub_gring /socle_val => /andP[Re]. rewrite -{2}(gring_rowK Re) -submx0. pose simMi := socle_simple iG; have [J [M isoM ->]] := component_mx_def simMi. case/sub_sumsmxP=> e ->; rewrite linear_sum mulmx_suml summx_sub // => j _. rewrite -(in_submodK (submxMl _ (M j))); move: (in_submod _ _) => v. have modMj: mxmodule aG (M j) by apply: mx_iso_module (isoM j) _; case: simMi. have rsimMj: mx_rsim rG (submod_repr modMj). by apply: mx_rsim_trans rsim_irr_comp_pchar _; apply/mx_rsim_iso. have [f [f' _ hom_f]] := mx_rsim_def (mx_rsim_sym rsimMj); rewrite submx0. have <-: (gring_mx aG (val_submod (v *m (f *m gring_op rG A *m f')))) = 0. by rewrite (eqP opA0) !(mul0mx, linear0). have: (A \in R_G)%MS by rewrite -Wedderburn_sum_pchar (sumsmx_sup iG). case/envelop_mxP=> a ->; rewrite !(linear_sum, mulmx_suml) /=; apply/eqP. apply: eq_bigr=> x Gx; rewrite 3!linearZ -scalemxAl 3!linearZ /=. by rewrite gring_opG // -hom_f // val_submodJ // gring_mxJ. Qed. Lemma regular_op_inj_pchar : {in [pred A | (A \in 'R_iG)%MS] &, injective (gring_op rG)}. Proof. move=> A B RnA RnB /= eqAB; apply/eqP; rewrite -subr_eq0 -mxvec_eq0 -submx0. rewrite -ker_irr_comp_op_pchar sub_capmx (sameP sub_kermxP eqP) mul_vec_lin. by rewrite 2!raddfB /= eqAB subrr linear0 addmx_sub ?eqmx_opp /=. Qed. Lemma rank_irr_comp_pchar : \rank 'R_iG = \rank E_G. Proof. rewrite -irr_comp_envelop_pchar; apply/esym/mxrank_injP. by rewrite ker_irr_comp_op_pchar. Qed. End IrrComponent. Lemma irr_comp_rsim_pchar n1 n2 rG1 rG2 : @mx_rsim _ G n1 rG1 n2 rG2 -> irr_comp rG1 = irr_comp rG2. Proof. case=> f eq_n12; rewrite -eq_n12 in rG2 f * => inj_f hom_f. rewrite /irr_comp; apply/f_equal/eq_pick => i; rewrite -!mxrank_eq0. (* [congr (odflt 1%irr _)] works but is very slow *) rewrite -(mxrankMfree _ inj_f); symmetry; rewrite -(eqmxMfull _ inj_f). have /envelop_mxP[e ->{i}]: ('e_i \in R_G)%MS. by rewrite -Wedderburn_sum_pchar (sumsmx_sup i) ?Wedderburn_id_mem. congr (\rank _ != _); rewrite !(mulmx_suml, linear_sum); apply: eq_bigr => x Gx. by rewrite 3!linearZ -scalemxAl /= !gring_opG ?hom_f. Qed. Lemma irr_reprK_pchar i : irr_comp (irr_repr i) = i. Proof. apply/eqP; apply/component_mx_isoP; try exact: socle_simple. by move/mx_rsim_iso: (rsim_irr_comp_pchar (socle_irr i)); apply: mx_iso_sym. Qed. Lemma irr_repr'_op0_pchar i j A : j != i -> (A \in 'R_j)%MS -> gring_op (irr_repr i) A = 0. Proof. move=> neq_ij /(irr_comp'_op0_pchar _). by move=> ->; [|apply: socle_irr|rewrite irr_reprK_pchar]. Qed. Lemma op_Wedderburn_id_pchar i : gring_op (irr_repr i) 'e_i = 1%:M. Proof. rewrite -(gring_op1 (irr_repr i)) -Wedderburn_sum_id_pchar. rewrite linear_sum (bigD1 i) //= addrC big1 ?add0r // => j neq_ji. exact: irr_repr'_op0_pchar (Wedderburn_id_mem j). Qed. Lemma irr_comp_id_pchar (M : 'M_nG) (modM : mxmodule aG M) (iM : sG) : mxsimple aG M -> (M <= iM)%MS -> irr_comp (submod_repr modM) = iM. Proof. move=> simM sMiM; rewrite -[iM]irr_reprK_pchar. apply/esym/irr_comp_rsim_pchar/mx_rsim_iso/component_mx_iso => //. exact: socle_simple. Qed. Lemma irr1_repr x : x \in G -> irr_repr 1 x = 1%:M. Proof. move=> Gx; suffices: x \in rker (irr_repr 1) by case/rkerP. apply: subsetP x Gx; rewrite rker_submod rfix_mx_rstabC // -irr1_rfix. by apply: component_mx_id; apply: socle_simple. Qed. Hypothesis splitG : group_splitting_field G. Lemma rank_Wedderburn_subring_pchar i : \rank 'R_i = ('n_i ^ 2)%N. Proof. apply/eqP; rewrite -{1}[i]irr_reprK_pchar; have irrSi := socle_irr i. by case/andP: (splitG irrSi) => _; rewrite rank_irr_comp_pchar. Qed. Lemma sum_irr_degree_pchar : (\sum_i 'n_i ^ 2 = nG)%N. Proof. apply: etrans (eqnP gring_free). rewrite -Wedderburn_sum_pchar (mxdirectP Wedderburn_direct) /=. by apply: eq_bigr => i _; rewrite rank_Wedderburn_subring_pchar. Qed. Lemma irr_mx_mult_pchar i : socle_mult i = 'n_i. Proof. rewrite /socle_mult -(mxrankMfree _ gring_free) -genmxE. by rewrite rank_Wedderburn_subring_pchar mulKn ?irr_degree_gt0. Qed. Lemma mxtrace_regular_pchar : {in G, forall x, \tr (aG x) = \sum_i \tr (socle_repr i x) *+ 'n_i}. Proof. move=> x Gx; have soc1: (Socle sG :=: 1%:M)%MS by rewrite -irr_mx_sum_pchar. rewrite -(mxtrace_submod1 (Socle_module sG) soc1) // mxtrace_Socle //. by apply: eq_bigr => i _; rewrite irr_mx_mult_pchar. Qed. Definition linear_irr := [set i | 'n_i == 1]. Lemma irr_degree_abelian : abelian G -> forall i, 'n_i = 1. Proof. by move=> cGG i; apply: mxsimple_abelian_linear (socle_simple i). Qed. Lemma linear_irr_comp_pchar i : 'n_i = 1 -> (i :=: socle_base i)%MS. Proof. move=> ni1; apply/eqmxP; rewrite andbC -mxrank_leqif_eq -/'n_i. rewrite -(mxrankMfree _ gring_free) -genmxE. by rewrite rank_Wedderburn_subring_pchar ni1. exact: component_mx_id (socle_simple i). Qed. Lemma Wedderburn_subring_center_pchar i : ('Z('R_i) :=: mxvec 'e_i)%MS. Proof. have [nz_e Re ideR idRe] := Wedderburn_is_id_pchar i. have Ze: (mxvec 'e_i <= 'Z('R_i))%MS. rewrite sub_capmx [(_ <= _)%MS]Re. by apply/cent_mxP=> A R_A; rewrite ideR // idRe. pose irrG := socle_irr i; set rG := socle_repr i in irrG. pose E_G := enveloping_algebra_mx rG; have absG := splitG irrG. apply/eqmxP; rewrite andbC -(geq_leqif (mxrank_leqif_eq Ze)). have ->: \rank (mxvec 'e_i) = (0 + 1)%N. by apply/eqP; rewrite eqn_leq rank_leq_row lt0n mxrank_eq0 mxvec_eq0. rewrite -(mxrank_mul_ker _ (lin_mx (gring_op rG))) addnC leq_add //. rewrite leqn0 mxrank_eq0 -submx0 -(ker_irr_comp_op_pchar irrG) capmxS //. by rewrite irr_reprK_pchar capmxSl. apply: leq_trans (mxrankS _) (rank_leq_row (mxvec 1%:M)). apply/memmx_subP=> Ar; case/submxP=> a ->{Ar}. rewrite mulmxA mul_rV_lin /=; set A := vec_mx _. rewrite memmx1 (mx_abs_irr_cent_scalar absG) // -memmx_cent_envelop. apply/cent_mxP=> Br; rewrite -(irr_comp_envelop_pchar irrG) irr_reprK_pchar. case/submxP=> b /(canRL mxvecK) ->{Br}; rewrite mulmxA mx_rV_lin /=. set B := vec_mx _; have RiB: (B \in 'R_i)%MS by rewrite vec_mxK submxMl. have sRiR: ('R_i <= R_G)%MS by rewrite -Wedderburn_sum_pchar (sumsmx_sup i). have: (A \in 'Z('R_i))%MS by rewrite vec_mxK submxMl. rewrite sub_capmx => /andP[RiA /cent_mxP cRiA]. by rewrite -!gring_opM ?(memmx_subP sRiR) 1?cRiA. Qed. Lemma Wedderburn_center_pchar : ('Z(R_G) :=: \matrix_(i < #|sG|) mxvec 'e_(enum_val i))%MS. Proof. have:= mxdirect_sums_center Wedderburn_sum_pchar Wedderburn_direct Wedderburn_ideal. move/eqmx_trans; apply; apply/eqmxP/andP; split. apply/sumsmx_subP=> i _; rewrite Wedderburn_subring_center_pchar. by apply: (eq_row_sub (enum_rank i)); rewrite rowK enum_rankK. apply/row_subP=> i; rewrite rowK -Wedderburn_subring_center_pchar. by rewrite (sumsmx_sup (enum_val i)). Qed. Lemma card_irr_pchar : #|sG| = tG. Proof. rewrite -(eqnP classg_base_free) classg_base_center. have:= mxdirect_sums_center Wedderburn_sum_pchar Wedderburn_direct Wedderburn_ideal. move->; rewrite (mxdirectP _) /=; last first. apply/mxdirect_sumsP=> i _; apply/eqP; rewrite -submx0. rewrite -{2}(mxdirect_sumsP Wedderburn_direct i) // capmxS ?capmxSl //=. by apply/sumsmx_subP=> j neji; rewrite (sumsmx_sup j) ?capmxSl. rewrite -sum1_card; apply: eq_bigr => i _; apply/eqP. rewrite Wedderburn_subring_center_pchar eqn_leq rank_leq_row lt0n mxrank_eq0. by rewrite andbT mxvec_eq0; case: (Wedderburn_is_id_pchar i). Qed. Section CenterMode. Variable i : sG. Let i0 := Ordinal (irr_degree_gt0 i). Definition irr_mode x := irr_repr i x i0 i0. Lemma irr_mode1 : irr_mode 1 = 1. Proof. by rewrite /irr_mode repr_mx1 mxE eqxx. Qed. Lemma irr_center_scalar : {in 'Z(G), forall x, irr_repr i x = (irr_mode x)%:M}. Proof. rewrite /irr_mode => x /setIP[Gx cGx]. suffices [a ->]: exists a, irr_repr i x = a%:M by rewrite mxE eqxx. apply/is_scalar_mxP; apply: (mx_abs_irr_cent_scalar (splitG (socle_irr i))). by apply/centgmxP=> y Gy; rewrite -!{1}repr_mxM 1?(centP cGx). Qed. Lemma irr_modeM : {in 'Z(G) &, {morph irr_mode : x y / (x * y)%g >-> x * y}}. Proof. move=> x y Zx Zy; rewrite {1}/irr_mode repr_mxM ?(subsetP (center_sub G)) //. by rewrite !irr_center_scalar // -scalar_mxM mxE eqxx. Qed. Lemma irr_modeX n : {in 'Z(G), {morph irr_mode : x / (x ^+ n)%g >-> x ^+ n}}. Proof. elim: n => [|n IHn] x Zx; first exact: irr_mode1. by rewrite expgS irr_modeM ?groupX // exprS IHn. Qed. Lemma irr_mode_unit : {in 'Z(G), forall x, irr_mode x \is a GRing.unit}. Proof. move=> x Zx /=; have:= unitr1 F. by rewrite -irr_mode1 -(mulVg x) irr_modeM ?groupV // unitrM; case/andP=> _. Qed. Lemma irr_mode_neq0 : {in 'Z(G), forall x, irr_mode x != 0}. Proof. by move=> x /irr_mode_unit; rewrite unitfE. Qed. Lemma irr_modeV : {in 'Z(G), {morph irr_mode : x / (x^-1)%g >-> x^-1}}. Proof. move=> x Zx /=; rewrite -[_^-1]mul1r; apply: canRL (mulrK (irr_mode_unit Zx)) _. by rewrite -irr_modeM ?groupV // mulVg irr_mode1. Qed. End CenterMode. Lemma irr1_mode x : x \in G -> irr_mode 1 x = 1. Proof. by move=> Gx; rewrite /irr_mode irr1_repr ?mxE. Qed. End Regular. Local Notation "[ 1 sG ]" := (principal_comp sG) : irrType_scope. Section LinearIrr. Variables (gT : finGroupType) (G : {group gT}). Lemma card_linear_irr (sG : irrType G) : [pchar F]^'.-group G -> group_splitting_field G -> #|linear_irr sG| = #|G : G^`(1)|%g. Proof. move=> F'G splitG; apply/eqP. wlog sGq: / irrType (G / G^`(1))%G by apply: socle_exists. have [_ nG'G] := andP (der_normal 1 G); apply/eqP; rewrite -card_quotient //. have cGqGq: abelian (G / G^`(1))%g by apply: sub_der1_abelian. have F'Gq: [pchar F]^'.-group (G / G^`(1))%g by apply: morphim_pgroup. have splitGq: group_splitting_field (G / G^`(1))%G. exact: quotient_splitting_field. rewrite -(sum_irr_degree_pchar sGq) // -sum1_card. pose rG (j : sGq) := morphim_repr (socle_repr j) nG'G. have irrG j: mx_irreducible (rG j) by apply/morphim_mx_irr; apply: socle_irr. rewrite (reindex (fun j => irr_comp sG (rG j))) /=. apply: eq_big => [j | j _]; last by rewrite irr_degree_abelian. have [_ lin_j _ _] := rsim_irr_comp_pchar sG F'G (irrG j). by rewrite inE -lin_j -irr_degreeE irr_degree_abelian. pose sGlin := {i | i \in linear_irr sG}. have sG'k (i : sGlin) : G^`(1)%g \subset rker (irr_repr (val i)). by case: i => i /= /[!inE] lin; rewrite rker_linear //=; apply/eqP. pose h' u := irr_comp sGq (quo_repr (sG'k u) nG'G). have irrGq u: mx_irreducible (quo_repr (sG'k u) nG'G). by apply/quo_mx_irr; apply: socle_irr. exists (fun i => oapp h' [1 sGq]%irr (insub i)) => [j | i] lin_i. rewrite (insubT [in _] lin_i) /=; apply/esym/eqP/socle_rsimP. apply: mx_rsim_trans (rsim_irr_comp_pchar sGq F'Gq (irrGq _)). have [g lin_g inj_g hom_g] := rsim_irr_comp_pchar sG F'G (irrG j). exists g => [||G'x]; last 1 [case/morphimP=> x _ Gx ->] || by []. by rewrite quo_repr_coset ?hom_g. rewrite (insubT (mem _) lin_i) /=; apply/esym/eqP/socle_rsimP. set u := Sub i lin_i. apply: mx_rsim_trans (rsim_irr_comp_pchar sG F'G (irrG _)). have [g lin_g inj_g hom_g] := rsim_irr_comp_pchar sGq F'Gq (irrGq u). exists g => [||x Gx]; last 1 [have:= hom_g (coset _ x)] || by []. by rewrite quo_repr_coset; first by apply; rewrite mem_quotient. Qed. Lemma primitive_root_splitting_abelian (z : F) : #|G|.-primitive_root z -> abelian G -> group_splitting_field G. Proof. move=> ozG cGG [|n] rG irrG; first by case/mx_irrP: irrG. case: (pickP [pred x in G | ~~ is_scalar_mx (rG x)]) => [x | scalG]. case/andP=> Gx nscal_rGx; have: horner_mx (rG x) ('X^#|G| - 1) == 0. rewrite rmorphB rmorphXn /= horner_mx_C horner_mx_X. rewrite -repr_mxX ?inE // ((_ ^+ _ =P 1)%g _) ?repr_mx1 ?subrr //. by rewrite -order_dvdn order_dvdG. case/idPn; rewrite -mxrank_eq0 -(factor_Xn_sub_1 ozG). elim: #|G| => [|i IHi]; first by rewrite big_nil horner_mx_C mxrank1. rewrite big_nat_recr => [|//]; rewrite rmorphM mxrankMfree {IHi}//=. rewrite row_free_unit rmorphB /= horner_mx_X horner_mx_C. rewrite (mx_Schur irrG) ?subr_eq0 //; last first. by apply: contraNneq nscal_rGx => ->; apply: scalar_mx_is_scalar. rewrite -memmx_cent_envelop raddfB. rewrite addmx_sub ?eqmx_opp ?scalar_mx_cent //= memmx_cent_envelop. by apply/centgmxP=> j Zh_j; rewrite -!repr_mxM // (centsP cGG). pose M := <<delta_mx 0 0 : 'rV[F]_n.+1>>%MS. have linM: \rank M = 1 by rewrite genmxE mxrank_delta. have modM: mxmodule rG M. apply/mxmoduleP=> x Gx; move/idPn: (scalG x); rewrite /= Gx negbK. by case/is_scalar_mxP=> ? ->; rewrite scalar_mxC submxMl. apply: linear_mx_abs_irr; apply/eqP; rewrite eq_sym -linM. by case/mx_irrP: irrG => _; apply; rewrite // -mxrank_eq0 linM. Qed. Lemma cycle_repr_structure_pchar x (sG : irrType G) : G :=: <[x]> -> [pchar F]^'.-group G -> group_splitting_field G -> exists2 w : F, #|G|.-primitive_root w & exists iphi : 'I_#|G| -> sG, [/\ bijective iphi, #|sG| = #|G|, forall i, irr_mode (iphi i) x = w ^+ i & forall i, irr_repr (iphi i) x = (w ^+ i)%:M]. Proof. move=> defG; rewrite {defG}(group_inj defG) -/#[x] in sG * => F'X splitF. have Xx := cycle_id x; have cXX := cycle_abelian x. have card_sG: #|sG| = #[x]. by rewrite card_irr_pchar //; apply/eqP; rewrite -card_classes_abelian. have linX := irr_degree_abelian splitF cXX (_ : sG). pose r (W : sG) := irr_mode W x. have scalX W: irr_repr W x = (r W)%:M. by apply: irr_center_scalar; rewrite ?(center_idP _). have inj_r: injective r. move=> V W eqVW; rewrite -(irr_reprK_pchar F'X V) -(irr_reprK_pchar F'X W). move: (irr_repr V) (irr_repr W) (scalX V) (scalX W). rewrite !linX {}eqVW => rV rW <- rWx; apply: irr_comp_rsim_pchar => //. exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => xk; case/cycleP=> k ->{xk}. by rewrite mulmx1 mul1mx !repr_mxX // rWx. have rx1 W: r W ^+ #[x] = 1. by rewrite -irr_modeX ?(center_idP _) // expg_order irr_mode1. have /hasP[w _ prim_w]: has #[x].-primitive_root (map r (enum sG)). rewrite has_prim_root 1?map_inj_uniq ?enum_uniq //; first 1 last. by rewrite size_map -cardE card_sG. by apply/allP=> _ /mapP[W _ ->]; rewrite unity_rootE rx1. have iphi'P := prim_rootP prim_w (rx1 _); pose iphi' := sval (iphi'P _). have def_r W: r W = w ^+ iphi' W by apply: svalP (iphi'P W). have inj_iphi': injective iphi'. by move=> i j eq_ij; apply: inj_r; rewrite !def_r eq_ij. have iphiP: codom iphi' =i 'I_#[x]. by apply/subset_cardP; rewrite ?subset_predT // card_ord card_image. pose iphi i := iinv (iphiP i); exists w => //; exists iphi. have iphiK: cancel iphi iphi' by move=> i; apply: f_iinv. have r_iphi i: r (iphi i) = w ^+ i by rewrite def_r iphiK. split=> // [|i]; last by rewrite scalX r_iphi. by exists iphi' => // W; rewrite /iphi iinv_f. Qed. Lemma splitting_cyclic_primitive_root_pchar : cyclic G -> [pchar F]^'.-group G -> group_splitting_field G -> classically {z : F | #|G|.-primitive_root z}. Proof. case/cyclicP=> x defG F'G splitF; case=> // IH. wlog sG: / irrType G by apply: socle_exists. have [w prim_w _] := cycle_repr_structure_pchar sG defG F'G splitF. by apply: IH; exists w. Qed. End LinearIrr. End FieldRepr. #[deprecated(since="mathcomp 2.4.0", note="Use mx_Maschke_pchar instead.")] Notation mx_Maschke := (mx_Maschke_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rsim_regular_submod_pchar instead.")] Notation rsim_regular_submod := (rsim_regular_submod_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_mx_sum_pchar instead.")] Notation irr_mx_sum := (irr_mx_sum_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_sum_pchar instead.")] Notation Wedderburn_sum := (Wedderburn_sum_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_sum_id_pchar instead.")] Notation Wedderburn_sum_id := (Wedderburn_sum_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_is_id_pchar instead.")] Notation Wedderburn_is_id:= (Wedderburn_is_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_closed_pchar instead.")] Notation Wedderburn_closed := (Wedderburn_closed_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_is_ring_pchar instead.")] Notation Wedderburn_is_ring := (Wedderburn_is_ring_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_min_ideal_pchar instead.")] Notation Wedderburn_min_ideal := (Wedderburn_min_ideal_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rsim_irr_comp_pchar instead.")] Notation rsim_irr_comp := (rsim_irr_comp_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp'_op0_pchar instead.")] Notation irr_comp'_op0 := (irr_comp'_op0_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp_envelop_pchar instead.")] Notation irr_comp_envelop := (irr_comp_envelop_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ker_irr_comp_op_pchar instead.")] Notation ker_irr_comp_op := (ker_irr_comp_op_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use regular_op_inj_pchar instead.")] Notation regular_op_inj := (regular_op_inj_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rank_irr_comp_pchar instead.")] Notation rank_irr_comp := (rank_irr_comp_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp_rsim_pchar instead.")] Notation irr_comp_rsim := (irr_comp_rsim_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_reprK_pchar instead.")] Notation irr_reprK := (irr_reprK_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_repr'_op0_pchar instead.")] Notation irr_repr'_op0 := (irr_repr'_op0_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use op_Wedderburn_id_pchar instead.")] Notation op_Wedderburn_id := (op_Wedderburn_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_comp_id_pchar instead.")] Notation irr_comp_id := (irr_comp_id_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use rank_Wedderburn_subring_pchar instead.")] Notation rank_Wedderburn_subring := (rank_Wedderburn_subring_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use sum_irr_degree_pchar instead.")] Notation sum_irr_degree := (sum_irr_degree_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use irr_mx_mult_pchar instead.")] Notation irr_mx_mult := (irr_mx_mult_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use mxtrace_regular_pchar instead.")] Notation mxtrace_regular := (mxtrace_regular_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use linear_irr_comp_pchar instead.")] Notation linear_irr_comp := (linear_irr_comp_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_subring_center_pchar instead.")] Notation Wedderburn_subring_center := (Wedderburn_subring_center_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use Wedderburn_center_pchar instead.")] Notation Wedderburn_center := (Wedderburn_center_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use card_irr_pchar instead.")] Notation card_irr := (card_irr_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use cycle_repr_structure_pchar instead.")] Notation cycle_repr_structure := (cycle_repr_structure_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use splitting_cyclic_primitive_root_pchar instead.")] Notation splitting_cyclic_primitive_root := (splitting_cyclic_primitive_root_pchar) (only parsing). Arguments rfix_mx {F gT G%_g n%_N} rG H%_g. Arguments gset_mx F {gT} G%_g A%_g. Arguments classg_base F {gT} G%_g _%_g : extra scopes. Arguments irrType F {gT} G%_g. Arguments mxmoduleP {F gT G n rG m U}. Arguments envelop_mxP {F gT G n rG A}. Arguments hom_mxP {F gT G n rG m f W}. Arguments mx_Maschke_pchar [F gT G n] rG _ [U]. Arguments rfix_mxP {F gT G n rG m W}. Arguments cyclic_mxP {F gT G n rG u v}. Arguments annihilator_mxP {F gT G n rG u A}. Arguments row_hom_mxP {F gT G n rG u v}. Arguments mxsimple_isoP {F gT G n rG U V}. Arguments socle_exists [F gT G n]. Arguments socleP {F gT G n rG sG0 W W'}. Arguments mx_abs_irrP {F gT G n rG}. Arguments socle_rsimP {F gT G n rG sG W1 W2}. Arguments val_submod {F n U m} W. Arguments in_submod {F n} U {m} W. Arguments val_submodK {F n U m} W : rename. Arguments in_submodK {F n U m} [W] sWU. Arguments val_submod_inj {F n U m} [W1 W2] : rename. Arguments val_factmod {F n U m} W. Arguments in_factmod {F n} U {m} W. Arguments val_factmodK {F n U m} W : rename. Arguments in_factmodK {F n} U {m} [W] sWU. Arguments val_factmod_inj {F n U m} [W1 W2] : rename. Notation "'Cl" := (Clifford_action _) : action_scope. Arguments gring_row {R gT G} A. Arguments gring_rowK {F gT G} [A] RG_A. Bind Scope irrType_scope with socle_sort. Notation "[ 1 sG ]" := (principal_comp sG) : irrType_scope. Arguments irr_degree {F gT G%_G sG} i%_irr. Arguments irr_repr {F gT G%_G sG} i%_irr _%_g : extra scopes. Arguments irr_mode {F gT G%_G sG} i%_irr z%_g : rename. Notation "''n_' i" := (irr_degree i) : group_ring_scope. Notation "''R_' i" := (Wedderburn_subring i) : group_ring_scope. Notation "''e_' i" := (Wedderburn_id i) : group_ring_scope. Section DecideRed. Import MatrixFormula. Local Notation term := GRing.term. Local Notation True := GRing.True. Local Notation And := GRing.And (only parsing). Local Notation morphAnd f := ((big_morph f) true andb). Local Notation eval := GRing.eval. Local Notation holds := GRing.holds. Local Notation qf_form := GRing.qf_form. Local Notation qf_eval := GRing.qf_eval. Section Definitions. Variables (F : fieldType) (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation F G n. Definition mxmodule_form (U : 'M[term F]_n) := \big[And/True]_(x in G) submx_form (mulmx_term U (mx_term (rG x))) U. Lemma mxmodule_form_qf U : qf_form (mxmodule_form U). Proof. by rewrite (morphAnd (@qf_form _)) ?big1 //= => x _; rewrite submx_form_qf. Qed. Lemma eval_mxmodule U e : qf_eval e (mxmodule_form U) = mxmodule rG (eval_mx e U). Proof. rewrite (morphAnd (qf_eval e)) //= big_andE /=. apply/forallP/mxmoduleP=> Umod x; move/implyP: (Umod x); by rewrite eval_submx eval_mulmx eval_mx_term. Qed. Definition mxnonsimple_form (U : 'M[term F]_n) := let V := vec_mx (row_var F (n * n) 0) in let nzV := (~ mxrank_form 0 V)%T in let properVU := (submx_form V U /\ ~ submx_form U V)%T in (Exists_row_form (n * n) 0 (mxmodule_form V /\ nzV /\ properVU))%T. End Definitions. Variables (F : decFieldType) (gT : finGroupType) (G : {group gT}) (n : nat). Variable rG : mx_representation F G n. Definition mxnonsimple_sat U := GRing.sat (@row_env _ (n * n) [::]) (mxnonsimple_form rG (mx_term U)). Lemma mxnonsimpleP U : U != 0 -> reflect (mxnonsimple rG U) (mxnonsimple_sat U). Proof. rewrite /mxnonsimple_sat {1}/mxnonsimple_form; set Vt := vec_mx _ => /= nzU. pose nsim V := [&& mxmodule rG V, (V <= U)%MS, V != 0 & \rank V < \rank U]. set nsimUt := (_ /\ _)%T; have: qf_form nsimUt. by rewrite /= mxmodule_form_qf !mxrank_form_qf !submx_form_qf. move/GRing.qf_evalP; set qev := @GRing.qf_eval _ => qevP. have qev_nsim u: qev (row_env [:: u]) nsimUt = nsim n (vec_mx u). rewrite /nsim -mxrank_eq0 /qev /= eval_mxmodule eval_mxrank. rewrite !eval_submx eval_mx_term eval_vec_mx eval_row_var /=. do 2!bool_congr; apply: andb_id2l => sUV. by rewrite ltn_neqAle andbC !mxrank_leqif_sup. have n2gt0: n ^ 2 > 0. by move: nzU; rewrite muln_gt0 -mxrank_eq0 unlock; case: posnP (U) => // ->. apply: (iffP satP) => [|[V nsimV]]. by case/Exists_rowP=> // v; move/qevP; rewrite qev_nsim; exists (vec_mx v). apply/Exists_rowP=> //; exists (mxvec V); apply/qevP. by rewrite qev_nsim mxvecK. Qed. Lemma dec_mxsimple_exists (U : 'M_n) : mxmodule rG U -> U != 0 -> {V | mxsimple rG V & V <= U}%MS. Proof. have [m] := ubnP (\rank U); elim: m U => // m IHm U leUm modU nzU. have [nsimU | simU] := mxnonsimpleP nzU; last first. by exists U; first apply/mxsimpleP. move: (xchooseP nsimU); move: (xchoose _) => W /and4P[modW sWU nzW ltWU]. case: (IHm W) => // [|V simV sVW]; first exact: leq_trans ltWU _. by exists V; last apply: submx_trans sVW sWU. Qed. Lemma dec_mx_reducible_semisimple U : mxmodule rG U -> mx_completely_reducible rG U -> mxsemisimple rG U. Proof. have [m] := ubnP (\rank U); elim: m U => // m IHm U leUm modU redU. have [U0 | nzU] := eqVneq U 0. have{} U0: (\sum_(i < 0) 0 :=: U)%MS by rewrite big_ord0 U0. by apply: (intro_mxsemisimple U0); case. have [V simV sVU] := dec_mxsimple_exists modU nzU; have [modV nzV _] := simV. have [W modW defVW dxVW] := redU V modV sVU. have [||I W_ /= simW defW _] := IHm W _ modW. - rewrite ltnS in leUm; apply: leq_trans leUm. by rewrite -defVW (mxdirectP dxVW) /= -add1n leq_add2r lt0n mxrank_eq0. - by apply: mx_reducibleS redU; rewrite // -defVW addsmxSr. suffices defU: (\sum_i oapp W_ V i :=: U)%MS. by apply: (intro_mxsemisimple defU) => [] [|i] //=. apply: eqmx_trans defVW; rewrite (bigD1 None) //=; apply/eqmxP. have [i0 _ | I0] := pickP I. by rewrite (reindex some) ?addsmxS ?defW //; exists (odflt i0) => //; case. rewrite big_pred0 //; last by case=> // /I0. by rewrite !addsmxS ?sub0mx // -defW big_pred0. Qed. Lemma DecSocleType : socleType rG. Proof. have [n0 | n_gt0] := posnP n. by exists [::] => // M [_]; rewrite -mxrank_eq0 -leqn0 -n0 rank_leq_row. have n2_gt0: n ^ 2 > 0 by rewrite muln_gt0 n_gt0. pose span Ms := (\sum_(M <- Ms) component_mx rG M)%MS. have: {in [::], forall M, mxsimple rG M} by []. have [m] := ubnP (n - \rank (span [::])). elim: m [::] => // m IHm Ms /ltnSE-Ms_ge_n simMs. pose V := span Ms; pose Vt := mx_term V. pose Ut i := vec_mx (row_var F (n * n) i); pose Zt := mx_term (0 : 'M[F]_n). pose exU i f := Exists_row_form (n * n) i (~ submx_form (Ut i) Zt /\ f (Ut i)). pose meetUVf U := exU 1 (fun W => submx_form W Vt /\ submx_form W U)%T. pose mx_sat := GRing.sat (@row_env F (n * n) [::]). have ev_sub0 := GRing.qf_evalP _ (submx_form_qf _ Zt). have ev_mod := GRing.qf_evalP _ (mxmodule_form_qf rG _). pose ev := (eval_mxmodule, eval_submx, eval_vec_mx, eval_row_var, eval_mx_term). case haveU: (mx_sat (exU 0 (fun U => mxmodule_form rG U /\ ~ meetUVf _ U)%T)). have [U modU]: {U : 'M_n | mxmodule rG U & (U != 0) && ((U :&: V)%MS == 0)}. apply: sig2W; case/Exists_rowP: (satP haveU) => //= u [nzU [modU tiUV]]. exists (vec_mx u); first by move/ev_mod: modU; rewrite !ev. set W := (_ :&: V)%MS; move/ev_sub0: nzU; rewrite !ev -!submx0 => -> /=. apply/idPn=> nzW; case: tiUV; apply/Exists_rowP=> //; exists (mxvec W). apply/GRing.qf_evalP; rewrite /= ?submx_form_qf // !ev mxvecK nzW /=. by rewrite andbC -sub_capmx. case/andP=> nzU tiUV; have [M simM sMU] := dec_mxsimple_exists modU nzU. apply: (IHm (M :: Ms)) => [|M']; last first. by case/predU1P=> [-> //|]; apply: simMs. have [_ nzM _] := simM. suffices ltVMV: \rank V < \rank (span (M :: Ms)). rewrite (leq_trans _ Ms_ge_n) // ltn_sub2l ?(leq_trans ltVMV) //. exact: rank_leq_row. rewrite /span big_cons (ltn_leqif (mxrank_leqif_sup (addsmxSr _ _))). apply: contra nzM; rewrite addsmx_sub -submx0 -(eqP tiUV) sub_capmx sMU. by case/andP=> sMV _; rewrite (submx_trans _ sMV) ?component_mx_id. exists Ms => // M simM; have [modM nzM minM] := simM. have sMV: (M <= V)%MS. apply: contraFT haveU => not_sMV; apply/satP/Exists_rowP=> //. exists (mxvec M); split; first by apply/ev_sub0; rewrite !ev mxvecK submx0. split; first by apply/ev_mod; rewrite !ev mxvecK. apply/Exists_rowP=> // [[w]]. apply/GRing.qf_evalP; rewrite /= ?submx_form_qf // !ev /= mxvecK submx0. rewrite -nz_row_eq0 -(cyclic_mx_eq0 rG); set W := cyclic_mx _ _. apply: contra not_sMV => /and3P[nzW Vw Mw]. have{Vw Mw} [sWV sWM]: (W <= V /\ W <= M)%MS. rewrite !cyclic_mx_sub ?(submx_trans (nz_row_sub _)) //. by rewrite sumsmx_module // => M' _; apply: component_mx_module. by rewrite (submx_trans _ sWV) // minM ?cyclic_mx_module. wlog sG: / socleType rG by apply: socle_exists. have sVS: (V <= \sum_(W : sG | has (fun Mi => Mi <= W) Ms) W)%MS. rewrite [V](big_nth 0) big_mkord; apply/sumsmx_subP=> i _. set Mi := Ms`_i; have MsMi: Mi \in Ms by apply: mem_nth. have simMi := simMs _ MsMi; have S_Mi := component_socle sG simMi. rewrite (sumsmx_sup (PackSocle S_Mi)) ?PackSocleK //. by apply/hasP; exists Mi; rewrite ?component_mx_id. have [W MsW isoWM] := subSocle_iso simM (submx_trans sMV sVS). have [Mi MsMi sMiW] := hasP MsW; apply/hasP; exists Mi => //. have [simMi simW] := (simMs _ MsMi, socle_simple W); apply/mxsimple_isoP=> //. exact: mx_iso_trans (mx_iso_sym isoWM) (component_mx_iso simW simMi sMiW). Qed. End DecideRed. Prenex Implicits mxmodule_form mxnonsimple_form mxnonsimple_sat. (* Change of representation field (by tensoring) *) Section ChangeOfField. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Local Notation "A ^f" := (map_mx (GRing.RMorphism.sort f) A) : ring_scope. Variables (gT : finGroupType) (G : {group gT}). Section OneRepresentation. Variables (n : nat) (rG : mx_representation aF G n). Local Notation rGf := (map_repr f rG). Lemma map_rfix_mx H : (rfix_mx rG H)^f = rfix_mx rGf H. Proof. rewrite map_kermx //; congr (kermx _); apply: map_lin1_mx => //= v. rewrite map_mxvec map_mxM; congr (mxvec (_ *m _)); last first. by apply: map_lin1_mx => //= u; rewrite map_mxM map_vec_mx. by apply/row_matrixP=> i; rewrite -map_row !rowK map_mxvec map_mxB map_mx1. Qed. Lemma rcent_map A : rcent rGf A^f = rcent rG A. Proof. by apply/setP=> x; rewrite !inE -!map_mxM inj_eq //; apply: map_mx_inj. Qed. Lemma rstab_map m (U : 'M_(m, n)) : rstab rGf U^f = rstab rG U. Proof. by apply/setP=> x; rewrite !inE -!map_mxM inj_eq //; apply: map_mx_inj. Qed. Lemma rstabs_map m (U : 'M_(m, n)) : rstabs rGf U^f = rstabs rG U. Proof. by apply/setP=> x; rewrite !inE -!map_mxM ?map_submx. Qed. Lemma centgmx_map A : centgmx rGf A^f = centgmx rG A. Proof. by rewrite /centgmx rcent_map. Qed. Lemma mxmodule_map m (U : 'M_(m, n)) : mxmodule rGf U^f = mxmodule rG U. Proof. by rewrite /mxmodule rstabs_map. Qed. Lemma mxsimple_map (U : 'M_n) : mxsimple rGf U^f -> mxsimple rG U. Proof. case; rewrite map_mx_eq0 // mxmodule_map // => modU nzU minU. split=> // V modV sVU nzV; rewrite -(map_submx f). by rewrite (minU V^f) //= ?mxmodule_map ?map_mx_eq0 // map_submx. Qed. Lemma mx_irr_map : mx_irreducible rGf -> mx_irreducible rG. Proof. by move=> irrGf; apply: mxsimple_map; rewrite map_mx1. Qed. Lemma rker_map : rker rGf = rker rG. Proof. by rewrite /rker -rstab_map map_mx1. Qed. Lemma map_mx_faithful : mx_faithful rGf = mx_faithful rG. Proof. by rewrite /mx_faithful rker_map. Qed. Lemma map_mx_abs_irr : mx_absolutely_irreducible rGf = mx_absolutely_irreducible rG. Proof. by rewrite /mx_absolutely_irreducible -map_enveloping_algebra_mx row_full_map. Qed. End OneRepresentation. Lemma mx_rsim_map n1 n2 rG1 rG2 : @mx_rsim _ _ G n1 rG1 n2 rG2 -> mx_rsim (map_repr f rG1) (map_repr f rG2). Proof. case=> g eqn12 inj_g hom_g. by exists g^f => // [|x Gx]; rewrite ?row_free_map // -!map_mxM ?hom_g. Qed. Lemma map_section_repr n (rG : mx_representation aF G n) rGf U V (modU : mxmodule rG U) (modV : mxmodule rG V) (modUf : mxmodule rGf U^f) (modVf : mxmodule rGf V^f) : map_repr f rG =1 rGf -> mx_rsim (map_repr f (section_repr modU modV)) (section_repr modUf modVf). Proof. move=> def_rGf; set VU := <<_>>%MS. pose valUV := val_factmod (val_submod (1%:M : 'M[aF]_(\rank VU))). have sUV_Uf: (valUV^f <= U^f + V^f)%MS. rewrite -map_addsmx map_submx; apply: submx_trans (proj_factmodS _ _). by rewrite val_factmodS val_submod1 genmxE. exists (in_submod _ (in_factmod U^f valUV^f)) => [||x Gx]. - rewrite !genmxE -(mxrank_map f) map_mxM map_col_base. by case: (\rank (cokermx U)) / (mxrank_map _ _); rewrite map_cokermx. - rewrite -kermx_eq0 -submx0; apply/rV_subP=> u. rewrite (sameP sub_kermxP eqP) submx0 -val_submod_eq0. rewrite val_submodE -mulmxA -val_submodE in_submodK; last first. by rewrite genmxE -(in_factmod_addsK _ V^f) submxMr. rewrite in_factmodE mulmxA -in_factmodE in_factmod_eq0. move/(submxMr (in_factmod U 1%:M *m in_submod VU 1%:M)^f). rewrite -mulmxA -!map_mxM //; do 2!rewrite mulmxA -in_factmodE -in_submodE. rewrite val_factmodK val_submodK map_mx1 mulmx1. have ->: in_factmod U U = 0 by apply/eqP; rewrite in_factmod_eq0. by rewrite linear0 map_mx0 eqmx0 submx0. rewrite {1}in_submodE mulmxA -in_submodE -in_submodJ; last first. by rewrite genmxE -(in_factmod_addsK _ V^f) submxMr. congr (in_submod _ _); rewrite -in_factmodJ // in_factmodE mulmxA -in_factmodE. apply/eqP; rewrite -subr_eq0 -def_rGf -!map_mxM -linearB in_factmod_eq0. rewrite -map_mxB map_submx -in_factmod_eq0 linearB. rewrite /= (in_factmodJ modU) // val_factmodK. rewrite [valUV]val_factmodE mulmxA -val_factmodE val_factmodK. rewrite -val_submodE in_submodK ?subrr //. by rewrite mxmodule_trans ?section_module // val_submod1. Qed. Lemma map_regular_subseries U i (modU : mx_subseries (regular_repr aF G) U) (modUf : mx_subseries (regular_repr rF G) [seq M^f | M <- U]) : mx_rsim (map_repr f (subseries_repr i modU)) (subseries_repr i modUf). Proof. set mf := map _ in modUf *; rewrite /subseries_repr. do 2!move: (mx_subseries_module' _ _) (mx_subseries_module _ _). have mf_i V: nth 0^f (mf V) i = (V`_i)^f. case: (ltnP i (size V)) => [ltiV | leVi]; first exact: nth_map. by rewrite !nth_default ?size_map. rewrite -(map_mx0 f) mf_i (mf_i (0 :: U)) => modUi'f modUif modUi' modUi. by apply: map_section_repr; apply: map_regular_repr. Qed. Lemma extend_group_splitting_field : group_splitting_field aF G -> group_splitting_field rF G. Proof. move=> splitG n rG irrG. have modU0: all ((mxmodule (regular_repr aF G)) #|G|) [::] by []. apply: (mx_Schreier modU0 _) => // [[U [compU lastU _]]]; have [modU _]:= compU. pose Uf := map (map_mx f) U. have{lastU} lastUf: (last 0 Uf :=: 1%:M)%MS. by rewrite -(map_mx0 f) -(map_mx1 f) last_map; apply/map_eqmx. have modUf: mx_subseries (regular_repr rF G) Uf. rewrite /mx_subseries all_map; apply: etrans modU; apply: eq_all => Ui /=. rewrite -mxmodule_map; apply: eq_subset_r => x. by rewrite !inE map_regular_repr. have absUf i: i < size U -> mx_absolutely_irreducible (subseries_repr i modUf). move=> lt_i_U; rewrite -(mx_rsim_abs_irr (map_regular_subseries i modU _)). rewrite map_mx_abs_irr; apply: splitG. by apply: mx_rsim_irr (mx_series_repr_irr compU lt_i_U); apply: section_eqmx. have compUf: mx_composition_series (regular_repr rF G) Uf. split=> // i; rewrite size_map => ltiU. move/max_submodP: (mx_abs_irrW (absUf i ltiU)); apply. rewrite -{2}(map_mx0 f) -map_cons !(nth_map 0) ?leqW //. by rewrite map_submx // ltmxW // (pathP _ (mx_series_lt compU)). have [[i ltiU] simUi] := rsim_regular_series irrG compUf lastUf. have{} simUi: mx_rsim rG (subseries_repr i modUf). by apply: mx_rsim_trans simUi _; apply: section_eqmx. by rewrite (mx_rsim_abs_irr simUi) absUf; rewrite size_map in ltiU. Qed. End ChangeOfField. (* Construction of a splitting field FA of an irreducible representation, for *) (* a matrix A in the centraliser of the representation. FA is the row-vector *) (* space of the matrix algebra generated by A with basis 1, A, ..., A ^+ d.-1 *) (* or, equivalently, the polynomials in {poly F} taken mod the (irreducible) *) (* minimal polynomial pA of A (of degree d). *) (* The details of the construction of FA are encapsulated in a submodule. *) Module Import MatrixGenField. (* The type definition must come before the main section so that the Bind *) (* Scope directive applies to all lemmas and definition discharged at the *) (* of the section. *) Record gen_of {F : fieldType} {gT : finGroupType} {G : {group gT}} {n' : nat} {rG : mx_representation F G n'.+1} {A : 'M[F]_n'.+1} (irrG : mx_irreducible rG) (cGA : centgmx rG A) := Gen {rVval : 'rV[F]_(degree_mxminpoly A)}. Local Arguments rVval {F gT G%_G n'%_N rG A%_R irrG cGA} x%_R : rename. Bind Scope ring_scope with gen_of. Section GenField. Variables (F : fieldType) (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variables (rG : mx_representation F G n) (A : 'M[F]_n). Local Notation d := (degree_mxminpoly A). Local Notation Ad := (powers_mx A d). Local Notation pA := (mxminpoly A). Let d_gt0 := mxminpoly_nonconstant A. Local Notation irr := mx_irreducible. Hypotheses (irrG : irr rG) (cGA : centgmx rG A). Notation FA := (gen_of irrG cGA). Let inFA := Gen irrG cGA. #[export, hnf] HB.instance Definition _ := [isNew for rVval : FA -> 'rV_d]. #[export] HB.instance Definition _ := [Choice of FA by <:]. Definition gen0 := inFA 0. Definition genN (x : FA) := inFA (- val x). Definition genD (x y : FA) := inFA (val x + val y). Lemma gen_addA : associative genD. Proof. by move=> x y z; apply: val_inj; rewrite /= addrA. Qed. Lemma gen_addC : commutative genD. Proof. by move=> x y; apply: val_inj; rewrite /= addrC. Qed. Lemma gen_add0r : left_id gen0 genD. Proof. by move=> x; apply: val_inj; rewrite /= add0r. Qed. Lemma gen_addNr : left_inverse gen0 genN genD. Proof. by move=> x; apply: val_inj; rewrite /= addNr. Qed. #[export] HB.instance Definition _ := GRing.isZmodule.Build FA gen_addA gen_addC gen_add0r gen_addNr. Definition pval (x : FA) := rVpoly (val x). Definition mxval (x : FA) := horner_mx A (pval x). Definition gen (x : F) := inFA (poly_rV x%:P). Lemma genK x : mxval (gen x) = x%:M. Proof. by rewrite /mxval [pval _]poly_rV_K ?horner_mx_C // size_polyC; case: (x != 0). Qed. Lemma mxval_inj : injective mxval. Proof. exact: inj_comp horner_rVpoly_inj val_inj. Qed. Lemma mxval0 : mxval 0 = 0. Proof. by rewrite /mxval [pval _]raddf0 rmorph0. Qed. Lemma mxvalN : {morph mxval : x / - x}. Proof. by move=> x; rewrite /mxval [pval _](@raddfN 'rV[F]_d) rmorphN. Qed. Lemma mxvalD : {morph mxval : x y / x + y}. Proof. by move=> x y; rewrite /mxval [pval _]raddfD rmorphD. Qed. Definition mxval_sum := big_morph mxval mxvalD mxval0. Definition gen1 := inFA (poly_rV 1). Definition genM x y := inFA (poly_rV (pval x * pval y %% pA)). Definition genV x := inFA (poly_rV (mx_inv_horner A (mxval x)^-1)). Lemma mxval_gen1 : mxval gen1 = 1%:M. Proof. by rewrite /mxval [pval _]poly_rV_K ?size_poly1 // horner_mx_C. Qed. Lemma mxval_genM : {morph mxval : x y / genM x y >-> x *m y}. Proof. move=> x y; rewrite /mxval [pval _]poly_rV_K ?size_mod_mxminpoly //. by rewrite -horner_mxK mx_inv_hornerK ?horner_mx_mem // rmorphM. Qed. Lemma mxval_genV : {morph mxval : x / genV x >-> invmx x}. Proof. move=> x; rewrite /mxval [pval _]poly_rV_K ?size_poly ?mx_inv_hornerK //. pose m B : 'M[F]_(n * n) := lin_mx (mulmxr B); set B := mxval x. case uB: (B \is a GRing.unit); last by rewrite invr_out ?uB ?horner_mx_mem. have defAd: Ad = Ad *m m B *m m B^-1. apply/row_matrixP=> i. by rewrite !row_mul mul_rV_lin /= mx_rV_lin /= mulmxK ?vec_mxK. rewrite -[B^-1]mul1mx -(mul_vec_lin (mulmxr B^-1)) defAd submxMr //. rewrite -mxval_gen1 (submx_trans (horner_mx_mem _ _)) // {1}defAd. rewrite -(geq_leqif (mxrank_leqif_sup _)) ?mxrankM_maxl // -{}defAd. apply/row_subP=> i; rewrite row_mul rowK mul_vec_lin /= -{2}[A]horner_mx_X. by rewrite -rmorphXn mulmxE -rmorphM horner_mx_mem. Qed. Lemma gen_mulA : associative genM. Proof. by move=> x y z; apply: mxval_inj; rewrite !mxval_genM mulmxA. Qed. Lemma gen_mulC : commutative genM. Proof. by move=> x y; rewrite /genM mulrC. Qed. Lemma gen_mul1r : left_id gen1 genM. Proof. by move=> x; apply: mxval_inj; rewrite mxval_genM mxval_gen1 mul1mx. Qed. Lemma gen_mulDr : left_distributive genM +%R. Proof. by move=> x y z; apply: mxval_inj; rewrite !(mxvalD, mxval_genM) mulmxDl. Qed. Lemma gen_ntriv : gen1 != 0. Proof. by rewrite -(inj_eq mxval_inj) mxval_gen1 mxval0 oner_eq0. Qed. #[export] HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build FA gen_mulA gen_mulC gen_mul1r gen_mulDr gen_ntriv. Lemma mxval1 : mxval 1 = 1%:M. Proof. exact: mxval_gen1. Qed. Lemma mxvalM : {morph mxval : x y / x * y >-> x *m y}. Proof. exact: mxval_genM. Qed. Lemma mxval_is_zmod_morphism : zmod_morphism mxval. Proof. by move=> x y; rewrite mxvalD mxvalN. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `mxval_is_zmod_morphism` instead")] Definition mxval_sub := mxval_is_zmod_morphism. #[export] HB.instance Definition _ := GRing.isZmodMorphism.Build FA 'M[F]_n mxval mxval_is_zmod_morphism. Lemma mxval_is_monoid_morphism : monoid_morphism mxval. Proof. by split; [apply: mxval1 | apply: mxvalM]. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `mxval_is_monoid_morphism` instead")] Definition mxval_is_multiplicative := (fun g => (g.2,g.1)) mxval_is_monoid_morphism. #[export] HB.instance Definition _ := GRing.isMonoidMorphism.Build FA 'M[F]_n mxval mxval_is_monoid_morphism. Lemma mxval_centg x : centgmx rG (mxval x). Proof. rewrite [mxval _]horner_rVpoly -memmx_cent_envelop vec_mxK {x}mulmx_sub //. apply/row_subP=> k; rewrite rowK memmx_cent_envelop; apply/centgmxP => g Gg /=. by rewrite !mulmxE commrX // /GRing.comm -mulmxE (centgmxP cGA). Qed. Lemma gen_mulVr x : x != 0 -> genV x * x = 1. Proof. rewrite -(inj_eq mxval_inj) mxval0. move/(mx_Schur irrG (mxval_centg x)) => u_x. by apply: mxval_inj; rewrite mxvalM mxval_genV mxval1 mulVmx. Qed. Lemma gen_invr0 : genV 0 = 0. Proof. by apply: mxval_inj; rewrite mxval_genV !mxval0 -{2}invr0. Qed. #[export] HB.instance Definition _ := GRing.ComNzRing_isField.Build FA gen_mulVr gen_invr0. Lemma mxvalV : {morph mxval : x / x^-1 >-> invmx x}. Proof. exact: mxval_genV. Qed. Lemma gen_is_zmod_morphism : zmod_morphism gen. Proof. by move=> x y; apply: mxval_inj; rewrite genK !rmorphB /= !genK. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `gen_is_zmod_morphism` instead")] Definition gen_is_additive := gen_is_zmod_morphism. Lemma gen_is_monoid_morphism : monoid_morphism gen. Proof. by split=> // x y; apply: mxval_inj; rewrite genK !rmorphM /= !genK. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `gen_is_monoid_morphism` instead")] Definition gen_is_multiplicative := (fun g => (g.2,g.1)) gen_is_monoid_morphism. #[export] HB.instance Definition _ := GRing.isZmodMorphism.Build F FA gen gen_is_zmod_morphism. #[export] HB.instance Definition _ := GRing.isMonoidMorphism.Build F FA gen gen_is_monoid_morphism. (* The generated field contains a root of the minimal polynomial (in some *) (* cases we want to use the construction solely for that purpose). *) Definition groot := inFA (poly_rV ('X %% pA)). Lemma mxval_groot : mxval groot = A. Proof. rewrite /mxval [pval _]poly_rV_K ?size_mod_mxminpoly // -horner_mxK. by rewrite mx_inv_hornerK ?horner_mx_mem // horner_mx_X. Qed. Lemma mxval_grootXn k : mxval (groot ^+ k) = A ^+ k. Proof. by rewrite rmorphXn /= mxval_groot. Qed. Lemma map_mxminpoly_groot : (map_poly gen pA).[groot] = 0. Proof. (* The [_ groot] prevents divergence of simpl. *) apply: mxval_inj; rewrite -horner_map [_ groot]/= mxval_groot mxval0. rewrite -(mx_root_minpoly A); congr ((_ : {poly _}).[A]). by apply/polyP=> i; rewrite 3!coef_map; apply: genK. Qed. (* Plugging the extension morphism gen into the ext_repr construction *) (* yields a (reducible) tensored representation. *) Lemma non_linear_gen_reducible : d > 1 -> mxnonsimple (map_repr gen rG) 1%:M. Proof. rewrite ltnNge mxminpoly_linear_is_scalar => Anscal. pose Af := map_mx gen A; exists (kermx (Af - groot%:M)). rewrite submx1 kermx_centg_module /=; last first. apply/centgmxP=> z Gz; rewrite mulmxBl [RHS]mulmxBr [in RHS]scalar_mxC. by rewrite -!map_mxM 1?(centgmxP cGA). rewrite andbC mxrank_ker -subn_gt0 mxrank1 subKn ?rank_leq_row // lt0n. rewrite mxrank_eq0 subr_eq0; case: eqP => [defAf | _]. rewrite -(map_mx_is_scalar gen) -/Af in Anscal. by case/is_scalar_mxP: Anscal; exists groot. rewrite -mxrank_eq0 mxrank_ker subn_eq0 row_leq_rank. apply/row_freeP=> [[XA' XAK]]. have pAf0: (mxminpoly Af).[groot] == 0. by rewrite mxminpoly_map ?map_mxminpoly_groot. have{pAf0} [q def_pAf]:= factor_theorem _ _ pAf0. have q_nz: q != 0. case: eqP (congr1 (fun p : {poly _} => size p) def_pAf) => // ->. by rewrite size_mxminpoly mul0r size_poly0. have qAf0: horner_mx Af q = 0. rewrite -[_ q]mulr1 -[1]XAK mulrA -{2}(horner_mx_X Af) -(horner_mx_C Af). by rewrite -rmorphB -rmorphM -def_pAf /= mx_root_minpoly mul0r. have{qAf0} := dvdp_leq q_nz (mxminpoly_min qAf0); rewrite def_pAf. by rewrite size_Mmonic ?monicXsubC // polyseqXsubC addn2 ltnn. Qed. (* An alternative to the above, used in the proof of the p-stability of *) (* groups of odd order, is to reconsider the original vector space as a *) (* vector space of dimension n / e over FA. This is applicable only if G is *) (* the largest group represented on the original vector space (i.e., if we *) (* are not studying a representation of G induced by one of a larger group, *) (* as in B & G Theorem 2.6 for instance). We can't fully exploit one of the *) (* benefits of this approach -- that the type domain for the vector space can *) (* remain unchanged -- because we're restricting ourselves to row matrices; *) (* we have to use explicit bijections to convert between the two views. *) Definition subbase nA (B : 'rV_nA) : 'M_(nA * d, n) := \matrix_ik mxvec (\matrix_(i, k) (row (B 0 i) (A ^+ k))) 0 ik. Lemma gen_dim_ex_proof : exists nA, [exists B : 'rV_nA, row_free (subbase B)]. Proof. by exists 0; apply/existsP; exists 0; rewrite /row_free unlock. Qed. Lemma gen_dim_ub_proof nA : [exists B : 'rV_nA, row_free (subbase B)] -> (nA <= n)%N. Proof. case/existsP=> B /eqnP def_nAd. by rewrite (leq_trans _ (rank_leq_col (subbase B))) // def_nAd leq_pmulr. Qed. Definition gen_dim := ex_maxn gen_dim_ex_proof gen_dim_ub_proof. Notation nA := gen_dim. Definition gen_base : 'rV_nA := odflt 0 [pick B | row_free (subbase B)]. Definition base := subbase gen_base. Lemma base_free : row_free base. Proof. rewrite /base /gen_base /nA; case: pickP => //; case: ex_maxnP => nA_max. by case/existsP=> B Bfree _ no_free; rewrite no_free in Bfree. Qed. Lemma base_full : row_full base. Proof. rewrite /row_full (eqnP base_free) /nA; case: ex_maxnP => nA. case/existsP=> /= B /eqnP Bfree nA_max; rewrite -Bfree eqn_leq rank_leq_col. rewrite -{1}(mxrank1 F n) mxrankS //; apply/row_subP=> j; set u := row _ _. move/implyP: {nA_max}(nA_max nA.+1); rewrite ltnn implybF. apply: contraR => nBj; apply/existsP. exists (row_mx (const_mx j : 'M_1) B); rewrite -row_leq_rank. pose Bj := Ad *m lin1_mx (mulmx u \o vec_mx). have rBj: \rank Bj = d. apply/eqP; rewrite eqn_leq rank_leq_row -subn_eq0 -mxrank_ker mxrank_eq0 /=. apply/rowV0P=> v /sub_kermxP; rewrite mulmxA mul_rV_lin1 /=. rewrite -horner_rVpoly; pose x := inFA v; rewrite -/(mxval x). have [[] // | nzx /(congr1 (mulmx^~ (mxval x^-1)))] := eqVneq x 0. rewrite mul0mx /= -mulmxA -mxvalM divff // mxval1 mulmx1. by move/rowP/(_ j)/eqP; rewrite !mxE !eqxx oner_eq0. rewrite {1}mulSn -Bfree -{1}rBj {rBj} -mxrank_disjoint_sum. rewrite mxrankS // addsmx_sub -[nA.+1]/(1 + nA)%N; apply/andP; split. apply/row_subP=> k; rewrite row_mul mul_rV_lin1 /=. apply: eq_row_sub (mxvec_index (lshift _ 0) k) _. by rewrite !rowK mxvecK mxvecE mxE row_mxEl mxE -row_mul mul1mx. apply/row_subP; case/mxvec_indexP=> i k. apply: eq_row_sub (mxvec_index (rshift 1 i) k) _. by rewrite !rowK !mxvecE 2!mxE row_mxEr. apply/eqP/rowV0P=> v; rewrite sub_capmx => /andP[/submxP[w]]. set x := inFA w; rewrite {Bj}mulmxA mul_rV_lin1 /= -horner_rVpoly -/(mxval x). have [-> | nzx ->] := eqVneq x 0; first by rewrite mxval0 mulmx0. move/(submxMr (mxval x^-1)); rewrite -mulmxA -mxvalM divff {nzx}//. rewrite mxval1 mulmx1 => Bx'j; rewrite (submx_trans Bx'j) in nBj => {Bx'j} //. apply/row_subP; case/mxvec_indexP=> i k. rewrite row_mul rowK mxvecE mxE rowE -mulmxA. have ->: A ^+ k *m mxval x^-1 = mxval (groot ^+ k / x). by rewrite mxvalM rmorphXn /= mxval_groot. rewrite [mxval _]horner_rVpoly; move: {k u x}(val _) => u. rewrite (mulmx_sum_row u) !linear_sum summx_sub //= => k _. rewrite 2!linearZ scalemx_sub //= rowK mxvecK -rowE. by apply: eq_row_sub (mxvec_index i k) _; rewrite rowK mxvecE mxE. Qed. Lemma gen_dim_factor : (nA * d)%N = n. Proof. by rewrite -(eqnP base_free) (eqnP base_full). Qed. Lemma gen_dim_gt0 : nA > 0. Proof. by case: posnP gen_dim_factor => // ->. Qed. Section Bijection. Variable m : nat. Definition in_gen (W : 'M[F]_(m, n)) : 'M[FA]_(m, nA) := \matrix_(i, j) inFA (row j (vec_mx (row i W *m pinvmx base))). Definition val_gen (W : 'M[FA]_(m, nA)) : 'M[F]_(m, n) := \matrix_i (mxvec (\matrix_j val (W i j)) *m base). Lemma in_genK : cancel in_gen val_gen. Proof. move=> W; apply/row_matrixP=> i; rewrite rowK; set w := row i W. have b_w: (w <= base)%MS by rewrite submx_full ?base_full. rewrite -{b_w}(mulmxKpV b_w); congr (_ *m _). by apply/rowP; case/mxvec_indexP=> j k; rewrite mxvecE !mxE. Qed. Lemma val_genK : cancel val_gen in_gen. Proof. move=> W; apply/matrixP=> i j; apply: val_inj; rewrite mxE /= rowK. case/row_freeP: base_free => B' BB'; rewrite -[_ *m _]mulmx1 -BB' mulmxA. by rewrite mulmxKpV ?submxMl // -mulmxA BB' mulmx1 mxvecK rowK. Qed. Lemma in_gen0 : in_gen 0 = 0. Proof. by apply/matrixP=> i j; rewrite !mxE !(mul0mx, linear0). Qed. Lemma val_gen0 : val_gen 0 = 0. Proof. by apply: (canLR in_genK); rewrite in_gen0. Qed. Lemma in_genD : {morph in_gen : U V / U + V}. Proof. by move=> U V; apply/matrixP=> i j; rewrite !mxE 4!(mulmxDl, linearD). Qed. Lemma val_genD : {morph val_gen : U V / U + V}. Proof. by move=> U V; apply: (canLR in_genK); rewrite in_genD !val_genK. Qed. Lemma in_genN : {morph in_gen : W / - W}. Proof. by move=> W; apply/esym/addr0_eq; rewrite -in_genD subrr in_gen0. Qed. Lemma val_genN : {morph val_gen : W / - W}. Proof. by move=> W; apply: (canLR in_genK); rewrite in_genN val_genK. Qed. Definition in_gen_sum := big_morph in_gen in_genD in_gen0. Definition val_gen_sum := big_morph val_gen val_genD val_gen0. Lemma in_genZ a : {morph in_gen : W / a *: W >-> gen a *: W}. Proof. move=> W; apply/matrixP=> i j; apply: mxval_inj. rewrite !mxE mxvalM genK ![mxval _]horner_rVpoly /=. by rewrite mul_scalar_mx !(I, scalemxAl, linearZ). Qed. End Bijection. Prenex Implicits val_genK in_genK. Lemma val_gen_rV (w : 'rV_nA) : val_gen w = mxvec (\matrix_j val (w 0 j)) *m base. Proof. by apply/rowP=> j /[1!mxE]. Qed. Section Bijection2. Variable m : nat. Lemma val_gen_row W (i : 'I_m) : val_gen (row i W) = row i (val_gen W). Proof. rewrite val_gen_rV rowK; congr (mxvec _ *m _). by apply/matrixP=> j k /[!mxE]. Qed. Lemma in_gen_row W (i : 'I_m) : in_gen (row i W) = row i (in_gen W). Proof. by apply: (canLR val_genK); rewrite val_gen_row in_genK. Qed. Lemma row_gen_sum_mxval W (i : 'I_m) : row i (val_gen W) = \sum_j row (gen_base 0 j) (mxval (W i j)). Proof. rewrite -val_gen_row [row i W]row_sum_delta val_gen_sum. apply: eq_bigr => /= j _ /[1!mxE]; move: {W i}(W i j) => x. have ->: x = \sum_k gen (val x 0 k) * inFA (delta_mx 0 k). case: x => u; apply: mxval_inj; rewrite {1}[u]row_sum_delta. rewrite mxval_sum [mxval _]horner_rVpoly mulmx_suml linear_sum /=. apply: eq_bigr => k _; rewrite mxvalM genK [mxval _]horner_rVpoly /=. by rewrite mul_scalar_mx -scalemxAl linearZ. rewrite scaler_suml val_gen_sum mxval_sum linear_sum; apply: eq_bigr => k _. rewrite mxvalM genK mul_scalar_mx linearZ [mxval _]horner_rVpoly /=. rewrite -scalerA; apply: (canLR in_genK); rewrite in_genZ; congr (_ *: _). apply: (canRL val_genK); transitivity (row (mxvec_index j k) base); last first. by rewrite -rowE rowK mxvecE mxE rowK mxvecK. rewrite rowE -mxvec_delta -[val_gen _](row_id 0) rowK /=; congr (mxvec _ *m _). apply/row_matrixP=> j'; rewrite rowK !mxE mulr_natr rowE mul_delta_mx_cond. by rewrite !mulrb (fun_if rVval). Qed. Lemma val_genZ x : {morph @val_gen m : W / x *: W >-> W *m mxval x}. Proof. move=> W; apply/row_matrixP=> i; rewrite row_mul !row_gen_sum_mxval. by rewrite mulmx_suml; apply: eq_bigr => j _; rewrite mxE mulrC mxvalM row_mul. Qed. End Bijection2. Lemma submx_in_gen m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (U <= V -> in_gen U <= in_gen V)%MS. Proof. move=> sUV; apply/row_subP=> i; rewrite -in_gen_row. case/submxP: (row_subP sUV i) => u ->{i}. rewrite mulmx_sum_row in_gen_sum summx_sub // => j _. by rewrite in_genZ in_gen_row scalemx_sub ?row_sub. Qed. Lemma submx_in_gen_eq m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, n)) : (V *m A <= V -> (in_gen U <= in_gen V) = (U <= V))%MS. Proof. move=> sVA_V; apply/idP/idP=> siUV; last exact: submx_in_gen. apply/row_subP=> i; rewrite -[row i U]in_genK in_gen_row. case/submxP: (row_subP siUV i) => u ->{i U siUV}. rewrite mulmx_sum_row val_gen_sum summx_sub // => j _. rewrite val_genZ val_gen_row in_genK rowE -mulmxA mulmx_sub //. rewrite [mxval _]horner_poly mulmx_sumr summx_sub // => [[k _]] _ /=. rewrite mulmxA mul_mx_scalar -scalemxAl scalemx_sub {u j}//. elim: k => [|k IHk]; first by rewrite mulmx1. by rewrite exprSr mulmxA (submx_trans (submxMr A IHk)). Qed. Definition gen_mx g := \matrix_i in_gen (row (gen_base 0 i) (rG g)). Let val_genJmx m : {in G, forall g, {morph @val_gen m : W / W *m gen_mx g >-> W *m rG g}}. Proof. move=> g Gg /= W; apply/row_matrixP=> i; rewrite -val_gen_row !row_mul. rewrite mulmx_sum_row val_gen_sum row_gen_sum_mxval mulmx_suml. apply: eq_bigr => /= j _; rewrite val_genZ rowK in_genK mxE -!row_mul. by rewrite (centgmxP (mxval_centg _)). Qed. Lemma gen_mx_repr : mx_repr G gen_mx. Proof. split=> [|g h Gg Gh]; apply: (can_inj val_genK). by rewrite -[gen_mx 1]mul1mx val_genJmx // repr_mx1 mulmx1. rewrite {1}[val_gen]lock -[gen_mx g]mul1mx !val_genJmx // -mulmxA -repr_mxM //. by rewrite -val_genJmx ?groupM ?mul1mx -?lock. Qed. Canonical gen_repr := MxRepresentation gen_mx_repr. Local Notation rGA := gen_repr. Lemma val_genJ m : {in G, forall g, {morph @val_gen m : W / W *m rGA g >-> W *m rG g}}. Proof. exact: val_genJmx. Qed. Lemma in_genJ m : {in G, forall g, {morph @in_gen m : v / v *m rG g >-> v *m rGA g}}. Proof. by move=> g Gg /= v; apply: (canLR val_genK); rewrite val_genJ ?in_genK. Qed. Lemma rfix_gen (H : {set gT}) : H \subset G -> (rfix_mx rGA H :=: in_gen (rfix_mx rG H))%MS. Proof. move/subsetP=> sHG; apply/eqmxP/andP; split; last first. by apply/rfix_mxP=> g Hg; rewrite -in_genJ ?sHG ?rfix_mx_id. rewrite -[rfix_mx rGA H]val_genK; apply: submx_in_gen. by apply/rfix_mxP=> g Hg; rewrite -val_genJ ?rfix_mx_id ?sHG. Qed. Definition rowval_gen m U := <<\matrix_ik mxvec (\matrix_(i < m, k < d) (row i (val_gen U) *m A ^+ k)) 0 ik>>%MS. Lemma submx_rowval_gen m1 m2 (U : 'M_(m1, n)) (V : 'M_(m2, nA)) : (U <= rowval_gen V)%MS = (in_gen U <= V)%MS. Proof. rewrite genmxE; apply/idP/idP=> sUV. apply: submx_trans (submx_in_gen sUV) _. apply/row_subP; case/mxvec_indexP=> i k; rewrite -in_gen_row rowK mxvecE mxE. rewrite -mxval_grootXn -val_gen_row -val_genZ val_genK scalemx_sub //. exact: row_sub. rewrite -[U]in_genK; case/submxP: sUV => u ->{U}. apply/row_subP=> i0; rewrite -val_gen_row row_mul; move: {i0 u}(row _ u) => u. rewrite mulmx_sum_row val_gen_sum summx_sub // => i _. rewrite val_genZ [mxval _]horner_rVpoly [_ *m Ad]mulmx_sum_row. rewrite !linear_sum summx_sub // => k _. rewrite 2!linearZ scalemx_sub {u}//= rowK mxvecK val_gen_row. by apply: (eq_row_sub (mxvec_index i k)); rewrite rowK mxvecE mxE. Qed. Lemma rowval_genK m (U : 'M_(m, nA)) : (in_gen (rowval_gen U) :=: U)%MS. Proof. apply/eqmxP; rewrite -submx_rowval_gen submx_refl /=. by rewrite -{1}[U]val_genK submx_in_gen // submx_rowval_gen val_genK. Qed. Lemma rowval_gen_stable m (U : 'M_(m, nA)) : (rowval_gen U *m A <= rowval_gen U)%MS. Proof. rewrite -[A]mxval_groot -{1}[_ U]in_genK -val_genZ. by rewrite submx_rowval_gen val_genK scalemx_sub // rowval_genK. Qed. Lemma rstab_in_gen m (U : 'M_(m, n)) : rstab rGA (in_gen U) = rstab rG U. Proof. apply/setP=> x /[!inE]; case Gx: (x \in G) => //=. by rewrite -in_genJ // (inj_eq (can_inj in_genK)). Qed. Lemma rstabs_in_gen m (U : 'M_(m, n)) : rstabs rG U \subset rstabs rGA (in_gen U). Proof. by apply/subsetP=> x /[!inE] /andP[Gx nUx]; rewrite -in_genJ Gx // submx_in_gen. Qed. Lemma rstabs_rowval_gen m (U : 'M_(m, nA)) : rstabs rG (rowval_gen U) = rstabs rGA U. Proof. apply/setP=> x /[!inE]; case Gx: (x \in G) => //=. by rewrite submx_rowval_gen in_genJ // (eqmxMr _ (rowval_genK U)). Qed. Lemma mxmodule_rowval_gen m (U : 'M_(m, nA)) : mxmodule rG (rowval_gen U) = mxmodule rGA U. Proof. by rewrite /mxmodule rstabs_rowval_gen. Qed. Lemma gen_mx_irr : mx_irreducible rGA. Proof. apply/mx_irrP; split=> [|U Umod nzU]; first exact: gen_dim_gt0. rewrite -sub1mx -rowval_genK -submx_rowval_gen submx_full //. case/mx_irrP: irrG => _; apply; first by rewrite mxmodule_rowval_gen. rewrite -(inj_eq (can_inj in_genK)) in_gen0. by rewrite -mxrank_eq0 rowval_genK mxrank_eq0. Qed. Lemma rker_gen : rker rGA = rker rG. Proof. apply/setP=> g; rewrite !inE !mul1mx; case Gg: (g \in G) => //=. apply/eqP/eqP=> g1; apply/row_matrixP=> i. by apply: (can_inj in_genK); rewrite rowE in_genJ //= g1 mulmx1 row1. by apply: (can_inj val_genK); rewrite rowE val_genJ //= g1 mulmx1 row1. Qed. Lemma gen_mx_faithful : mx_faithful rGA = mx_faithful rG. Proof. by rewrite /mx_faithful rker_gen. Qed. End GenField. Section DecideGenField. Import MatrixFormula. Variable F : decFieldType. Local Notation False := GRing.False. Local Notation True := GRing.True. Local Notation Bool b := (GRing.Bool b%bool). Local Notation term := (GRing.term F). Local Notation form := (GRing.formula F). Local Notation morphAnd f := ((big_morph f) true andb). Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variables (rG : mx_representation F G n) (A : 'M[F]_n). Hypotheses (irrG : mx_irreducible rG) (cGA : centgmx rG A). Local Notation FA := (gen_of irrG cGA). Local Notation inFA := (Gen irrG cGA). Local Notation d := (degree_mxminpoly A). Let d_gt0 : d > 0 := mxminpoly_nonconstant A. Local Notation Ad := (powers_mx A d). Let mxT (u : 'rV_d) := vec_mx (mulmx_term u (mx_term Ad)). Let eval_mxT e u : eval_mx e (mxT u) = mxval (inFA (eval_mx e u)). Proof. by rewrite eval_vec_mx eval_mulmx eval_mx_term [mxval _]horner_rVpoly. Qed. Let Ad'T := mx_term (pinvmx Ad). Let mulT (u v : 'rV_d) := mulmx_term (mxvec (mulmx_term (mxT u) (mxT v))) Ad'T. Lemma eval_mulT e u v : eval_mx e (mulT u v) = val (inFA (eval_mx e u) * inFA (eval_mx e v)). Proof. rewrite !(eval_mulmx, eval_mxvec) !eval_mxT eval_mx_term. by apply: (can_inj rVpolyK); rewrite -mxvalM [rVpoly _]horner_rVpolyK. Qed. Fixpoint gen_term t := match t with | 'X_k => row_var _ d k | x%:T => mx_term (val (x : FA)) | n1%:R => mx_term (val (n1%:R : FA))%R | t1 + t2 => \row_i (gen_term t1 0%R i + gen_term t2 0%R i) | - t1 => \row_i (- gen_term t1 0%R i) | t1 *+ n1 => mulmx_term (mx_term n1%:R%:M)%R (gen_term t1) | t1 * t2 => mulT (gen_term t1) (gen_term t2) | t1^-1 => gen_term t1 | t1 ^+ n1 => iter n1 (mulT (gen_term t1)) (mx_term (val (1%R : FA))) end%T. Definition gen_env (e : seq FA) := row_env (map val e). Lemma nth_map_rVval (e : seq FA) j : (map val e)`_j = val e`_j. Proof. case: (ltnP j (size e)) => [| leej]; first exact: (nth_map 0 0). by rewrite !nth_default ?size_map. Qed. Lemma set_nth_map_rVval (e : seq FA) j v : set_nth 0 (map val e) j v = map val (set_nth 0 e j (inFA v)). Proof. apply: (@eq_from_nth _ 0) => [|k _]; first by rewrite !(size_set_nth, size_map). by rewrite !(nth_map_rVval, nth_set_nth) /= nth_map_rVval [rVval _]fun_if. Qed. Lemma eval_gen_term e t : GRing.rterm t -> eval_mx (gen_env e) (gen_term t) = val (GRing.eval e t). Proof. elim: t => //=. - by move=> k _; apply/rowP=> i; rewrite !mxE /= nth_row_env nth_map_rVval. - by move=> x _; rewrite eval_mx_term. - by move=> x _; rewrite eval_mx_term. - by move=> t1 + t2 + /andP[rt1 rt2] => <-// <-//; apply/rowP => k /[!mxE]. - by move=> t1 + rt1 => <-//; apply/rowP=> k /[!mxE]. - move=> t1 IH1 n1 rt1; rewrite eval_mulmx eval_mx_term mul_scalar_mx. by rewrite scaler_nat {}IH1 //; elim: n1 => //= n1 IHn1; rewrite !mulrS IHn1. - by move=> t1 IH1 t2 IH2 /andP[rt1 rt2]; rewrite eval_mulT IH1 ?IH2. move=> t1 + n1 => /[apply] IH1. elim: n1 => [|n1 IHn1] /=; first by rewrite eval_mx_term. by rewrite eval_mulT exprS IH1 IHn1. Qed. Fixpoint gen_form f := match f with | Bool b => Bool b | t1 == t2 => mxrank_form 0 (gen_term (t1 - t2)) | GRing.Unit t1 => mxrank_form 1 (gen_term t1) | f1 /\ f2 => gen_form f1 /\ gen_form f2 | f1 \/ f2 => gen_form f1 \/ gen_form f2 | f1 ==> f2 => gen_form f1 ==> gen_form f2 | ~ f1 => ~ gen_form f1 | ('exists 'X_k, f1) => Exists_row_form d k (gen_form f1) | ('forall 'X_k, f1) => ~ Exists_row_form d k (~ (gen_form f1)) end%T. Lemma sat_gen_form e f : GRing.rformula f -> reflect (GRing.holds e f) (GRing.sat (gen_env e) (gen_form f)). Proof. have ExP := Exists_rowP; have set_val := set_nth_map_rVval. elim: f e => //. - by move=> b e _; apply: (iffP satP). - rewrite /gen_form => t1 t2 e rt_t; set t := (_ - _)%T. have:= GRing.qf_evalP (gen_env e) (mxrank_form_qf 0 (gen_term t)). rewrite eval_mxrank mxrank_eq0 eval_gen_term // => tP. by rewrite (sameP satP tP) /= subr_eq0 val_eqE; apply: eqP. - move=> f1 IH1 f2 IH2 s /= /andP[/(IH1 s)f1P /(IH2 s)f2P]. by apply: (iffP satP) => [[/satP/f1P ? /satP/f2P] | [/f1P/satP ? /f2P/satP]]. - move=> f1 IH1 f2 IH2 s /= /andP[/(IH1 s)f1P /(IH2 s)f2P]. by apply: (iffP satP) => /= [] []; try move/satP; do [move/f1P | move/f2P]; try move/satP; auto. - move=> f1 IH1 f2 IH2 s /= /andP[/(IH1 s)f1P /(IH2 s)f2P]. by apply: (iffP satP) => /= implP; try move/satP; move/f1P; try move/satP; move/implP; try move/satP; move/f2P; try move/satP. - move=> f1 IH1 s /= /(IH1 s) f1P. by apply: (iffP satP) => /= notP; try move/satP; move/f1P; try move/satP. - move=> k f1 IHf1 s /IHf1 f1P; apply: (iffP satP) => /= [|[[v f1v]]]. by case/ExP=> // x /satP; rewrite set_val => /f1P; exists (inFA x). by apply/ExP=> //; exists v; rewrite set_val; apply/satP/f1P. move=> i f1 IHf1 s /IHf1 f1P; apply: (iffP satP) => /= allf1 => [[v]|]. apply/f1P; case: satP => // notf1x; case: allf1; apply/ExP=> //. by exists v; rewrite set_val. by case/ExP=> //= v []; apply/satP; rewrite set_val; apply/f1P. Qed. Definition gen_sat e f := GRing.sat (gen_env e) (gen_form (GRing.to_rform f)). (* FIXME : why this MathCompCompatDecidableField *) Lemma gen_satP : GRing.MathCompCompatDecidableField.DecidableField.axiom gen_sat. Proof. move=> e f; have [tor rto] := GRing.to_rformP e f. exact: (iffP (sat_gen_form e (GRing.to_rform_rformula f))). Qed. #[export] HB.instance Definition _ := GRing.Field_isDecField.Build FA gen_satP. End DecideGenField. Section FiniteGenField. Variables (F : finFieldType) (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variables (rG : mx_representation F G n) (A : 'M[F]_n). Hypotheses (irrG : mx_irreducible rG) (cGA : centgmx rG A). Notation FA := (gen_of irrG cGA). #[export] HB.instance Definition _ := [Finite of FA by <:]. #[export] HB.instance Definition _ := [finGroupMixin of FA for +%R]. Lemma card_gen : #|{:FA}| = (#|F| ^ degree_mxminpoly A)%N. Proof. by rewrite card_sub card_mx mul1n. Qed. End FiniteGenField. End MatrixGenField. Module MatrixGenFieldExports. HB.reexport. End MatrixGenFieldExports. Export MatrixGenFieldExports. Bind Scope ring_scope with gen_of. Arguments rVval {F gT G%_G n'%_N rG A%_R irrG cGA} x%_R : rename. Prenex Implicits gen_of Gen rVval pval mxval gen groot. Arguments subbase {F n'} A {nA}. Prenex Implicits gen_dim gen_base base val_gen gen_mx rowval_gen. Arguments in_gen {F gT G n' rG A} irrG cGA {m} W. Arguments in_genK {F gT G n' rG A} irrG cGA {m} W : rename. Arguments val_genK {F gT G n' rG A irrG cGA m} W : rename. Prenex Implicits gen_env gen_term gen_form gen_sat. (* Classical splitting and closure field constructions provide convenient *) (* packaging for the pointwise construction. *) Section BuildSplittingField. Implicit Type gT : finGroupType. Implicit Type F : fieldType. Lemma group_splitting_field_exists gT (G : {group gT}) F : classically {Fs : fieldType & {rmorphism F -> Fs} & group_splitting_field Fs G}. Proof. move: F => F0 [] // nosplit; pose nG := #|G|; pose aG F := regular_repr F G. pose m := nG.+1; pose F := F0; pose U : seq 'M[F]_nG := [::]. suffices: size U + m <= nG by rewrite ltnn. have: mx_subseries (aG F) U /\ path ltmx 0 U by []. pose f : {rmorphism F0 -> F} := idfun. elim: m F U f => [|m IHm] F U f [modU ltU]. by rewrite addn0 (leq_trans (max_size_mx_series ltU)) ?rank_leq_row. rewrite addnS ltnNge -implybF; apply/implyP=> le_nG_Um; apply: nosplit. exists F => //; case=> [|n] rG irrG; first by case/mx_irrP: irrG. apply/idPn=> nabsG; pose cG := ('C(enveloping_algebra_mx rG))%MS. have{nabsG} [A]: exists2 A, (A \in cG)%MS & ~~ is_scalar_mx A. apply/has_non_scalar_mxP; rewrite ?scalar_mx_cent // ltnNge. by apply: contra nabsG; apply: cent_mx_scalar_abs_irr. rewrite {cG}memmx_cent_envelop -mxminpoly_linear_is_scalar -ltnNge => cGA. move/(non_linear_gen_reducible irrG cGA). (* FIXME: _ matches a generated constant *) set F' := _ irrG cGA; set rG' := @map_repr _ F' _ _ _ _ rG. move: F' (gen _ _ : {rmorphism F -> F'}) => F' f' in rG' * => irrG'. pose U' := [seq map_mx f' Ui | Ui <- U]. have modU': mx_subseries (aG F') U'. apply: etrans modU; rewrite /mx_subseries all_map; apply: eq_all => Ui. rewrite -(mxmodule_map f'); apply: eq_subset_r => x. by rewrite !inE map_regular_repr. case: notF; apply: (mx_Schreier modU ltU) => [[V [compV lastV sUV]]]. have{lastV} [] := rsim_regular_series irrG compV lastV. have{sUV} defV: V = U. apply/eqP; rewrite eq_sym -(geq_leqif (size_subseq_leqif sUV)). rewrite -(leq_add2r m); apply: leq_trans le_nG_Um. by apply: IHm f _; rewrite (mx_series_lt compV); case: compV. rewrite {V}defV in compV * => i rsimVi. apply: (mx_Schreier modU') => [|[V' [compV' _ sUV']]]. rewrite {modU' compV modU i le_nG_Um rsimVi}/U' -(map_mx0 f'). by apply: etrans ltU; elim: U 0 => //= Ui U IHU Ui'; rewrite IHU map_ltmx. have{sUV'} defV': V' = U'; last rewrite {V'}defV' in compV'. apply/eqP; rewrite eq_sym -(geq_leqif (size_subseq_leqif sUV')) size_map. rewrite -(leq_add2r m); apply: leq_trans le_nG_Um. apply: IHm (f' \o f) _. by rewrite (mx_series_lt compV'); case: compV'. suffices{irrG'}: mx_irreducible rG' by case/mxsimpleP=> _ _ []. have ltiU': i < size U' by rewrite size_map. apply: mx_rsim_irr (mx_rsim_sym _ ) (mx_series_repr_irr compV' ltiU'). by apply: mx_rsim_trans (mx_rsim_map f' rsimVi) _; apply: map_regular_subseries. Qed. Lemma group_closure_field_exists gT F : classically {Fs : fieldType & {rmorphism F -> Fs} & group_closure_field Fs gT}. Proof. set n := #|{group gT}|. suffices: classically {Fs : fieldType & {rmorphism F -> Fs} & forall G : {group gT}, enum_rank G < n -> group_splitting_field Fs G}. - apply: classic_bind => [[Fs f splitFs]] _ -> //. by exists Fs => // G; apply: splitFs. elim: (n) => [|i IHi]; first by move=> _ -> //; exists F => //; exists id. apply: classic_bind IHi => [[F' f splitF']]. have [le_n_i _ -> // | lt_i_n] := leqP n i. by exists F' => // G _; apply: splitF'; apply: leq_trans le_n_i. have:= @group_splitting_field_exists _ (enum_val (Ordinal lt_i_n)) F'. apply: classic_bind => [[Fs f' splitFs]] _ -> //. exists Fs => [|G]; first exact: (f' \o f). rewrite ltnS leq_eqVlt -{1}[i]/(val (Ordinal lt_i_n)) val_eqE. case/predU1P=> [defG | ltGi]; first by rewrite -[G]enum_rankK defG. by apply: (extend_group_splitting_field f'); apply: splitF'. Qed. Lemma group_closure_closed_field (F : closedFieldType) gT : group_closure_field F gT. Proof. move=> G [|n] rG irrG; first by case/mx_irrP: irrG. apply: cent_mx_scalar_abs_irr => //; rewrite leqNgt. apply/(has_non_scalar_mxP (scalar_mx_cent _ _)) => [[A cGA nscalA]]. have [a]: exists a, eigenvalue A a. pose P := mxminpoly A; pose d := degree_mxminpoly A. have Pd1: P`_d = 1. by rewrite -(eqP (mxminpoly_monic A)) /lead_coef size_mxminpoly. have d_gt0: d > 0 := mxminpoly_nonconstant A. have [a def_ad] := solve_monicpoly (nth 0 (- P)) d_gt0. exists a; rewrite eigenvalue_root_min -/P /root -oppr_eq0 -hornerN. rewrite horner_coef size_polyN size_mxminpoly -/d big_ord_recr -def_ad. by rewrite coefN Pd1 mulN1r /= subrr. case/negP; rewrite kermx_eq0 row_free_unit (mx_Schur irrG) ?subr_eq0 //. by rewrite -memmx_cent_envelop -raddfN linearD addmx_sub ?scalar_mx_cent. by apply: contraNneq nscalA => ->; exact: scalar_mx_is_scalar. Qed. End BuildSplittingField.